Find name of variable
Dear friends and experts, I'm again at the end of my knowledge:
- A variable just behind a marker is found and the variable can be deleted in the text

- This variable should also be removed from the catalogue. I'ts name is not known, because the name is generated at the time of insertion (the current name is 2016-11-10T09:46:52.136Z).
- Experiments with the text selection after finding the variable (line 31) did not reveal anything useful to get the name of the variable.
- Do You have an idea?
#target framemaker
// Required doc: #calc Marker with text containing "C7 at the beginning
// behind this marker the variable of unknown name is found
sMarkerText = '"C7';oDoc = app.ActiveDoc;
oMarker = oDoc.FirstMarkerInDoc;
while (oMarker.ObjectValid()) {
if (oMarker.MarkerTypeId.Name == "#calc") {
if (oMarker.MarkerText == sMarkerText) {
bFound = FindAndDeleteVariable (goCurrentDoc, goCurrentMarker); // remove already existing variable
// How to get the name of the variable to be able to remove it from the catalogue also?
oTextLoc = goCurrentMarker.TextLoc;
oTextLoc.offset = oTextLoc.offset + 1; // insert temp variable behind marker
InsertVariable (goCurrentDoc, oTextLoc, "#TEST", "\+1.275×10<super>\+9" );
}
}
}function FindAndDeleteVariable (oDoc, oMarker) { //=== Find variable behind marker and remove it ==
// In oMarker: current marker
// Out Function returns true for found+removed variable
var tLoc1 = oMarker.TextLoc,
tLoc2 = oMarker.TextLoc, // should be just behind the marker
iUnique1= oMarker.TextLoc.obj.Unique, // ¶ of the marker
myTextRange, findParams, fRange;
tLoc2.offset = tLoc2.offset + 1; // a - c are required!
myTextRange = new TextRange(tLoc1,tLoc2); // b
oDoc.TextSelection = myTextRange; // c
findParams= GetFindParamsVariable (); // search for any variable
fRange = oDoc.Find (tLoc1, findParams); // finds variable
if (fRange.beg.obj.ObjectValid()) { // variable found ?
if (fRange.beg.obj.Unique == iUnique1) { // same ¶ as the marker ?
if (fRange.beg.offset == tLoc1.offset+1) { // TR =? variable behind marker
oDoc.DeleteText(fRange); // Delete the selected Variable
return true;
}
}
}
return false; // there was'nt a variable
} //--- end FindAndDeleteVariablefunction GetFindParamsVariable () { //=== Set up parameters to Find a variable ====================
// Out Returns parameters for the find function: no wrapping around ?
// Reference Klaus Göbel, https://forums.adobe.com/thread/2227993
// FDK Function Reference, F_ApiFind()
var findParams = new PropVals() ;
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindObject;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = Constants.FV_FindAnyVariable ;
findParams.push(propVal);
return findParams;
} //--- end GetFindParamsVariable
function InsertVariable (oDoc, oTextLoc, sVarName, sContent) { //=== Insert variable at location ==
// In oTextLoc: where to insert the variable
// sVarName: name of the variable
// sContent: content of the variable
var oVar;
oVar = oDoc.NewAnchoredFormattedVar (sVarName, oTextLoc);
oVar.Fmt = sContent;
}
BTW the marker contains this text: "C7 ¶ after T2 TB" = @Pi19_2 / 180.0; which is successfully evaluated and placed in the temporary variable - there is progress in my project¨.
Thank You very much for Your help!
Klaus

