Copy link to clipboard
Copied
In indesign , to set the measurements to particular format,for example to inches, I use the script
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
But I now want to get the default measurement units that I have specified in InDesign Preference setting.Is it possible?How can I get this?
Thanks and Regards,
Revathi
The structure could be something like that:
...main()
function main()
{
var myDocument = app.documents[0];
var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;
ImportXML();
myDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;
myDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;
function ImportXML()
{
// Do something reasonable.
// JUST
Copy link to clipboard
Copied
The measurement units properties are read/write, so to get them just read:
mySpecifiedhDefaultMeasurementUnits = myDocument.viewPreferences.horizontalMeasurementUnits
mySpecifiedvDefaultMeasurementUnits = myDocument.viewPreferences.verticalMeasurementUnits
Copy link to clipboard
Copied
Hi Jongware,
Thank you for your quick response.
I set my InDesign measurement setting to mm and tried to import xml using javascript.But after impporting the xml my measurement unit changes to inches.I used the script specified by you.But couldn't retain the setting.Could you help?
Regards,
Revathi V
Copy link to clipboard
Copied
Hi Revathi,
you are doing the import of XML by script.
So get the values before doing the part with the XML and after that restore the values.
Do all that in the same script.
If you want to do your XML import with a separate script and you have access to the source code, then you have at least two options:
1. Run all three scripts with the same #targetengine directive.
A. Script 1: Get the values
B. Script 2: Do the XML thing
C. Script 3: Restore the values
All three scripts share the same variables and their values.
2. Use a label to store information
A. Script 1: Store the values with a label using methods insertLabel( "KeyString" , "ValueString" ) with e.g. the document.
B. Script 2: Do the XML thing
C. Script 3: Retrieve the old values from the label using extractLabel("KeyString"), that will return the contents of the label and eval("ReturnedString") from the document.
If you have no access to the source code of the XML script you still can do option 2.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
I have got the values before importing the xml and have done all the thingsin one script.
Below I have mentioned my script
main();
with (myDocument.viewPreferences)
{
var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;
}//Here tried to get indesign preference values but only getting it always as inches.
//Import xml
function ImportXML(){
if(importOption=="FlOWINTOTEMPLATE")
{
var docPath = app.scriptArgs.get("templateFilePath");
myDocument = app.open(File(docPath),true);
if(myDocument!=null)
{
var rootXMLElement = myDocument.xmlElements.item(0);
ClearProductFamilies(rootXMLElement);
}
}
Copy link to clipboard
Copied
The structure could be something like that:
main()
function main()
{
var myDocument = app.documents[0];
var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;
ImportXML();
myDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;
myDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;
function ImportXML()
{
// Do something reasonable.
// JUST AN EXAMPLE FOR SOMETHING NOT REASONABLE:
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
alert
(
"Measurement Units horizontal / vertical"+"\r"+
myDocument.viewPreferences.horizontalMeasurementUnits.toString()+"\r"+
myDocument.viewPreferences.verticalMeasurementUnits.toString()
);
return
};
}
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
Thanks for your response.
Actually my process was to import a xml and then drag drop its elements.After importing the xml I am able to get my reference setting.I have a doubt.Is it possible to get the preference setting without any document open and have the same preference setting for the new imported xml?I am able to get the prefence setting only while drag drop the imported elements?
Regards,
Revathi V