• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Textline property not set within function, but available outside

Community Expert ,
May 09, 2019 May 09, 2019

Copy link to clipboard

Copied

Dear all.

Let's see whether I can explain my current problem:

I have a function DrawTextLine which - at it's end - decides whether the text is just placed at the coordinates x0/y0 or it shall be centered within a given length (or right adjusted within this space) - line 20.

// ---------------------------------------------- Centre/right adjust within tLength

  boundLeft = 0.;

  if (tLength == (undefined || null)) {

    oTextLine.BasePointX = x0 * goFgr.CM;         // .Width, .Height set by text contents !

    oTextLine.BasePointY = y0 * goFgr.CM;         //

    oTextLine.Angle = angle * goFgr.DEGREE;

    return oTextLine;

  } else {

    textLen = oTextLine.Width/goFgr.CM;           // cm

    if (tLength > 0){

      boundLeft = (Math.abs(tLength) - textLen)/2;

    } else {

      boundLeft = (Math.abs(tLength) - textLen);

    }

  }

// ---------------------------------------------- Place and rotate text

  dY = dX = 0.;

  dX = boundLeft * angSin;

  dY = boundLeft * angCos;

  oTextLine.BasePointX = (x0 + dX) * goFgr.CM;    // units

  oTextLine.BasePointY = (y0 + dY) * goFgr.CM;

  oTextLine.Angle = angle * goFgr.DEGREE;

  return oTextLine;

} //--- end DrawTextLine

In all tests this routine works fine, as the following diagram demonstrates (watch the numbers within the 1cm grid):

Test-DawTextLine.png

Now, when using this function within in another function DrawAxisCal to center the month name between the adjacent scale tics - it does not behave!

When stepping through the code the text properties show that it should be placed correctly, but it is not.

- Still within DrawTextLine the property oTextLine.Width is 0

- After DrawTextLine ahs been left the Width is set correctly.

Hence in  DrawAxisCal I again set the proper value for oTextLine.BasePointX

xLabel  = xTic;

monthLen = (monStart[j+1] - monStart)*vUnit;

if (xLabel + monthLen > progressEnd) {break Cycles; } // no space for month annotation

aText.length = 0;                       // clear prophylactically

aText[0] = sMonShort[langMonth];

if (monthLen > 1.35) {aText[0] = sMonNames[langMonth];} // 1.35 determined by trial

oObject = DrawTextLine (xLabel, yLabel, aText, aFormat, angle, monthLen); // centred

// for unknown reason centring does not work inside of DrawTextLine!

oObject.BasePointX =  xLabel* goFgr.CM + (monthLen*goFgr.CM - oObject.Width)/2; // units

I have carefully checked the scope of the variables. My only guess is that ESTK may become tired and skip certain statements. Yes, I have observed this in other circumstances already. Only after restarting FM and ESTK it worked correctly again...

… And while I'm writing this - after taking a screenshot from the open FM-document - FM-15.0.603 quits with Internal Error …

Test-DawTextLine2.png

TOPICS
Scripting

Views

254

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 10, 2019 May 10, 2019

Well, checking oTextLine.Width at nearly every code line revealed:

At entry to line 20 (first code snipped) the Width is 0

After line 20 has been executed, the Width is set!

Hence I insert before the line 9 a "teasing code":

oTextLine.BasePointX = x0*goFgr.CM  ;        // required to get the Width!

Et voilà - things are correct!

Votes

Translate

Translate
Community Expert ,
May 10, 2019 May 10, 2019

Copy link to clipboard

Copied

LATEST

Well, checking oTextLine.Width at nearly every code line revealed:

At entry to line 20 (first code snipped) the Width is 0

After line 20 has been executed, the Width is set!

Hence I insert before the line 9 a "teasing code":

oTextLine.BasePointX = x0*goFgr.CM  ;        // required to get the Width!

Et voilà - things are correct!

Votes

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
community guidelines