Copy link to clipboard
Copied
Dear friends,
While this task was solved in FrameScript with ease ...
If ActiveDoc = 0
MsgBox 'No active document. ';
LeaveSub;
EndIf
Set vGraphic = FirstGraphicInDoc;
Loop While(vGraphic)
Set vNextGraphic = vGraphic.NextGraphicInDoc;
If vGraphic.ObjectName = 'TextLine'
If vGraphic.Text = ''
Delete Object(vGraphic);
EndIf
EndIf
Set vGraphic = vNextGraphic;
EndLoop
I struggle in ES by the simple fact, that there is no text attribute available:
Fot the test I use an FM document without Ref pages. On the only one body page I have removed everything but a text line containing some text.
Text line is found, but I have no clue how to chek whether it is empty or not, because I can't get to the string:
FindEmptyTextLine = function () {
// Reference E:\FM-FrameScript\DeleteEmptyTextlines.fsl
var oDoc, oGraphic, objType, asText, oTextLoc;
oDoc = app.ActiveDoc;
if (!oDoc.ObjectValid()) { return;}
oGraphic = oDoc.FirstGraphicInDoc;
while (oGraphic.ObjectValid()) {
objType = oGraphic.constructor.name;
if (objType == "TextLine") {
$.bp(true);
oTextLoc = new TextLoc (oGraphic, 0); // how to find the string?
asText = oGraphic.ObjectAttributes;
if (asText.length == 0) { // string array is empty
bFound = true;
} else { // is there a real textline ?
alert ("have we found a real text line?");
}
oGraphic.GraphicIsSelected = true; // Nothing to see
}
oGraphic = oGraphic.NextGraphicInDoc;
}
return oGraphic;
} //--- end FindEmptyTextLine
var object = FindEmptyTextLine ();
Any help available here?
Thanks You.
Thanks to the information given in the FDK documentation I could solve this issue - using an important function from Rick: getText(..):
var KLD_Z = KLD_Z || {}; // global script object
KLD_Z.GetText = function (oText, oDoc) { //================================
// Reference Rick Quatro
var aTextItems, iTxtLen, j, sText= "";
if (oText.constructor.name !== "TextRange") { // Get a list of the strings in the sText object or sText range
aTextItems = oText.GetText(C
...
Copy link to clipboard
Copied
Thanks to the information given in the FDK documentation I could solve this issue - using an important function from Rick: getText(..):
var KLD_Z = KLD_Z || {}; // global script object
KLD_Z.GetText = function (oText, oDoc) { //================================
// Reference Rick Quatro
var aTextItems, iTxtLen, j, sText= "";
if (oText.constructor.name !== "TextRange") { // Get a list of the strings in the sText object or sText range
aTextItems = oText.GetText(Constants.FTI_String); // text objects
} else {
aTextItems = oDoc.GetTextForRange(oText, Constants.FTI_String); // text range
}
iTxtLen = aTextItems.len;
for (j = 0; j < iTxtLen; j += 1) { // Concatenate the strings
sText += (aTextItems[j].sdata);
}
return sText; // Return the sText
} //--- end GetText
KLD_Z.FindEmptyTextLine = function () { // ==============================
/* Find and select empty text line
Arguments oDoc Current document
asNames Array of xy-names
Returns Function value is object:
object.obj the found graphic object
object.grouped false | true
Called by ButtonFind
Calling GetText, IsEmptyString (internal)
Comment Grouped text lines can be found, indication is just by the blinking text cursor.
To delete them they must be undgrouped first.
Ungrouped text lines are indicated by their 8 handles.
Reference DeleteEmptyTextlines.fsl by Michael Müller-Hillebrand (200-04-22)
Used in FMmngFindRepl
History 2021-02-09
*/
var oDoc, oGraphic, objType, oTL, sText, oTR, oResult = {};
function IsEmptyString(string) {
var re_Trim = /(^[\s\n\r\t\x0B]+)|([\s\n\r\t\x0B]+$)/g;
string = string.replace(re_Trim, "");
return string.length == 0;
}
oResult.grouped = false;
oDoc = app.ActiveDoc;
if (!oDoc.ObjectValid()) { return;}
oGraphic = oDoc.FirstGraphicInDoc;
while (oGraphic.ObjectValid()) {
objType = oGraphic.constructor.name;
if (objType == "TextLine") {
sText = KLD_Z.GetText(oGraphic, oDoc);
if (IsEmptyString(sText)) { // string is empty or blank
if (oGraphic.GroupParent.ObjectValid()) {
oResult.grouped = true;
}
oTL = new TextLoc (oGraphic, 0);
oTR = new TextRange(oTL, oTL);
oDoc.ScrollToText(oTR);
oGraphic.GraphicIsSelected = true; // indicate it
break;
}
}
oGraphic = oGraphic.NextGraphicInDoc;
}
oResult.obj = oGraphic;
return oResult;
} //--- end FindEmptyTextLine ---------------------------------------------------------
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
var object = KLD_Z.FindEmptyTextLine ();
if (!object.obj.ObjectValid()) {
alert ("No empty textline found");
} else if (object.grouped) {
alert ("This empty textline is grouped. To delete it, it first must be ungrouped.");
} else {
alert ("This empty textline can be deleted.");
object.obj.Delete();
}