Highlighted

Problems with ObjectValid ()

Advocate ,
Apr 25, 2016

Copy link to clipboard

Copied

Dear experts,

In my scripts I have this snippet:

var tLoc2, fRange, j, thisMarker, thisId, thatId;
//...

for (j = 0; j < markerRange.length; j++)        // loop should not be necessary due to findparms

var oTextItem = markerRange
thisMarker = oTextItem.obj;                   // should contain only one marker

if (!thisMarker.ObjectValid()) {
Alert ("IndexNearestMarker does not find a " + sMarkerName + " marker after the cursor location, first marker used");
thisMarker =  markerArray[0];
}

thisId = thisMarker.Unique;

Although thisMarker shows all expected properties, and in the document the found marker is already selected, line 8 reports "thisMarker is undefined".

data-browser.png

Replacing line 8 with this

if (!oTextItem.obj.ObjectValid()) {

the sript runs and line 12 does not create a problem at all !

What is wrong with the original line 86?

Hi Klaus,

I was looking up to the sky, instead of looking to the tip of my nose.

The solution is sooooo simple: a typo in line 20

thisMaker -> thisMarker

TOPICS
Scripting

Views

582

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Problems with ObjectValid ()

Advocate ,
Apr 25, 2016

Copy link to clipboard

Copied

Dear experts,

In my scripts I have this snippet:

var tLoc2, fRange, j, thisMarker, thisId, thatId;
//...

for (j = 0; j < markerRange.length; j++)        // loop should not be necessary due to findparms

var oTextItem = markerRange
thisMarker = oTextItem.obj;                   // should contain only one marker

if (!thisMarker.ObjectValid()) {
Alert ("IndexNearestMarker does not find a " + sMarkerName + " marker after the cursor location, first marker used");
thisMarker =  markerArray[0];
}

thisId = thisMarker.Unique;

Although thisMarker shows all expected properties, and in the document the found marker is already selected, line 8 reports "thisMarker is undefined".

data-browser.png

Replacing line 8 with this

if (!oTextItem.obj.ObjectValid()) {

the sript runs and line 12 does not create a problem at all !

What is wrong with the original line 86?

Hi Klaus,

I was looking up to the sky, instead of looking to the tip of my nose.

The solution is sooooo simple: a typo in line 20

thisMaker -> thisMarker

TOPICS
Scripting

Views

583

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 25, 2016 0
Explorer ,
Apr 25, 2016

Copy link to clipboard

Copied

I would try putting the test inside the FOR loop.  It looks to me as though you're going through all the items in the marker range, and the last item is undefined.  IO know you say it's a range of 1, but FrameMaker might do something strange like add a dummy object at the end of the range.  Text ranges and text items lists can be strange sometimes.

So check the length of markerRange and see if it's what you really expect.  And also, try putting the test inside the FOR loop -- that's probably where it belongs anyway.

Just guessing....  Hope it helps!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Mentor ,
Apr 25, 2016

Copy link to clipboard

Copied

Yes, something doesn't seem right overall, but there isn't enough code there to see the problem. If markerRange is an array of text locations, well that seems odd. Why are you creating an array of TextLocs? I think a misunderstanding of what you are doing with markerRange is the cause here.

Russ

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Advocate ,
Apr 25, 2016

Copy link to clipboard

Copied

Well, I didn't think that the full code is required, because outside of the test (line 12) thisMarker is taken as it should.

Nevertheless here is the full function:

function IndexNearestMarker (oDoc, sMarkerName) { // get nearest following marker of type sMarkerName

// function returns index in corresponding array
  var markerArray = [], markerRange = [];
  var tLoc2, fRange, j, thisMarker, thisId, thatId;
  markerArray = GetMarkerArray (sMarkerName);     // corresponding global marker array

// we are at oDoc.TextSelection and need to find the marker-index in the array.
  var currentSelection = oDoc.TextSelection;
  var tLoc2 = oDoc.TextSelection.end;             // after possible selection

  var findParams= GetFindParamsMarker (sMarkerName); // define the marker search

  fRange = oDoc.Find  (tLoc2, findParams);        // finds text range (object pgf), lenght 1
  markerRange = oDoc.GetTextForRange (fRange, Constants.FTI_MarkerAnchor);  // this is an array

  for (j = 0; j < markerRange.length; j++) {      // loop should not be necessary due to findparms
    var oTextItem = markerRange
    thisMarker = oTextItem.obj;                   // should contain only one marker
  }
//if (!thisMaker.ObjectValid()) {                 //? => thisMarker is undefined
  if (!oTextItem.obj.ObjectValid()) {
    Alert ("IndexNearestMarker does not find a " + sMarkerName + " marker after the cursor location, first marker used");
    thisMarker =  markerArray[0];
  }
  thisId = thisMarker.Unique;
  for (j = 0; j <  markerArray.length; j++) {     // find the equivalent item in array
    thatId = markerArray.Unique;
    if (thisId == thatId) {break;}
  }
  return j;
} // --- end GetNearestMarker 

So why is line 20 not a valid test if lines 25 ... correctly creates the desired result?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Mentor ,
Apr 25, 2016

Copy link to clipboard

Copied

Klaus,

Thanks for posting the code. I think that your use of "markerRange" to describe a TextItems array was throwing us off track. Now that I see the whole thing, your problem does seem unusual. This is a total guess, but maybe I would try this to set thisMarker:

var thisMarker = markerRange.obj;

A TextItems array is an array of arrays, so maybe something goofy is going on there by trying to extract a single array? I don't know. Maybe try that. If you still can't get it to work, I'll test it myself if you post the GetFindParamsMarker() function.

Russ

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Enthusiast ,
Apr 25, 2016

Copy link to clipboard

Copied

Hi Klaus,

in my opinion it has nothing to do with FrameMaker.

if markerRange.length = 0, (line 16), the constructor of thisMaker is string.

AND: String has no object, so your line 20 will result in undefined.

If debugging stops with that error, just type into the console:

"markerRange.constructor"

I'm sure the result will be "string".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Explorer ,
Apr 25, 2016

Copy link to clipboard

Copied

So....   HAVE you actually tried testing the marker inside of the for loop instead of after the for loop?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0
Advocate ,
Apr 26, 2016

Copy link to clipboard

Copied

Klaus, at that point it says:

markerRange.constructor
Result: TextItems()

Russ, IMHO your suggestion

var thisMarker = markerRange.obj;

is the same as the two steps

var oTextItem = markerRange;
thisMarker = oTextItem.obj;

Placing the test inside the loop creates the same error

Please find here: the complete test script and the test document .

The strange thing still is, that (refering to my complete script line 74)

if (!thisMaker.ObjectValid()) {

provides the information in the Data Browser as pictured in my initial post:

thisMarker = [object Marker]

Marker Text = 3rd calc marker in doc  (this depned where i have placed the cursor intially)

My pragmatic solution is this (see full script):

- do not use line 74

- but use line 75 for the test

Nevertheless Your research will clarify what's really going on here. Thank You all.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2016 0
Enthusiast ,
Apr 26, 2016

Copy link to clipboard

Copied

Hi Klaus,

your "comlete test script" doesn't run because there are only functions in it.

I'm looking forward to test this script and find the problem. Could you please post the whole script.

thanks

Klaus

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2016 0
Advocate ,
Apr 26, 2016

Copy link to clipboard

Copied

Sorry for that!

Too many experiments at a time...

The link now points to the correct test script.

Klaus

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2016 0
Enthusiast ,
Apr 26, 2016

Copy link to clipboard

Copied

Hi Klaus,

I was looking up to the sky, instead of looking to the tip of my nose.

The solution is sooooo simple: a typo in line 20

thisMaker -> thisMarker

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2016 0
K.Daube LATEST
Advocate ,
Apr 26, 2016

Copy link to clipboard

Copied

Embarrassing!

Ash on me!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2016 0
Adobe Community Professional ,
Apr 25, 2016

Copy link to clipboard

Copied

What is markerRange in your code?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 25, 2016 0