Skip to main content
K.Daube
Community Expert
Community Expert
November 3, 2018
Question

ESTK - draw a graphic

  • November 3, 2018
  • 1 reply
  • 1967 views

Dear all,

After the first step (drawing a single line) I now try to draw a polyline. But i have no success:

  • Obviously the defintion for the points is not correct
  • Same is for the defintion of the dash pattern.

I tried to interprete the the FDK reference and the Scripting Guide - but I fail to transfer these definitions to JS data types.

FDK reference

F_PointsT: describes a set of coordinate pairs. It is normally used to describe the vertices of a graphic object, such as a polyline or polygon.

typedef struct {

   UIntT len;     /* Number of coordinate pairs */

   F_PointT *val; /* Vector of coordinate pairs */

} F_PointsT;

Dash: Data type Metrics. Specifies a dash pattern that is repeated for the length of an object's border. The

pattern is stored in a MetricsT structure. The 0th element of the MetricsT.MetricsT_val array stores the length of the first dash; the 1st element

stores the following space; the 2nd element stores the next dash; and so on for an even number of elements.

Metrics: Under this heading some functions to handle metrics are given, but no explanation. I do not find a useful definition.

MetricsT structure: defined as

typedef struct {

   UIntT len;    /* Number of metric values*/

   MetricT *val; /* Array of metric values */

} F_MetricsT;

Scripting Guide

Points: An Array of Point objects with integer indexing and a length property.

Point: is described just as two integer values x and y.

Dash: Same text as in FDK

Metrics: An Array of objects with integer indexing and a length property. ➔ what kind of objects?

This is my script

#target framemaker

var oDoc = app.ActiveDoc, cm = 1857713;

Main(oDoc);

function Main(oDoc) {

var oFrame, oLine1, oPoly1;

  if (!oDoc.ObjectValid()) {

    alert ("A document must be active.");

    return;

  }

 

  oFrame = oDoc.FirstSelectedGraphicInDoc;

  if (!oFrame.ObjectValid()) {

    alert ("An anchored frame must be selected.");

    return;

  }

  oPoly1  = DrawPoly(oDoc, oFrame);

}

function DrawPoly(oDoc, oFrame) {

var j, jLast, k, oPoly = oDoc.NewPolyline(oFrame), oPoints = [4, 1, 6, 2, 8, 1, 10, 2];

  jLast = oPoints.length-1;                       // last index

  for (j = 0; j <= jLast; j++) {                  // convert into internal units

    oPoints = oPoints * cm;

  }

  oPoly.PolyIsBezier = 0;                         // 0: unsmooth; 1: smooth ?

  oPoly.BorderWidth = 0.05*cm;                    // Stroke-width

  oPoly.LocX = oPoints[0];                        // otherwise has

  oPoly.LocY = oPoints[1];                        // precedence over 1st point

  oPoly.Points = oPoints;

  oPoly.Width = oPoints[jLast-1] - oPoints[0];    // object dimensions

  oPoly.Height= oPoints[jLast] - oPoints[1];      // default : 1/4"

  oPoly.Fill  = 15;                               // Pattern: 0: filled, 7: white, 15: clear

  oPoly.Color = 0;                                // black?

  oPoly.Dash  = [cm, 0.5, 0.5, 0.2, 0.2];         // ?

  return oPoly;

}

And this is the output

The red item is what I want to achieve and the black is what the script produces.

This topic has been closed for replies.

1 reply

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
November 5, 2018

Even using the function Point (x,y) as described in the Scripting Guide (Function Summary), i have no success. The statement

oPoints = [Point(4*CM, 1*CM), Point(6*CM, 2*CM), Point(8*CM, 1*CM), Point(10*CM, 2*CM)];

yields message Point() is not a function!

var oPoints = [[4*CM, 1*CM], [6*CM, 2*CM], [8*CM, 1*CM], [10*CM, 2*CM]];

is accepted by ESTK, but creates only a line. The UI reports a PolyLine at 0/0 with width=height = 0.635 cm (1/4"). The Stroke width is as set in the script:

I have also found this:

  • The FDK constants FV_METRIC_xx are not mapped to ESTK.
  • For the typographic unit didot I see a discrepancy between the definition in FM (1/72” * 69977/65536) = 0.376684 and the official definition (1/72 French Royal inch = 0.375972 mm).
  • For Line my simple definition of the points
    var oPoints = [1, 1, 3, 2];
    seems to work - why then not in Polyline?

Where is a description of the required data types in JS terminology?

I'ts also an imposition that for every graphic object (line, arc, ellipse...) simply all properties for any object are listed (most likely by a text inset). IMHO it is at least misleading that a circle can have an arrow head. Well this is obvious, but others are not at all.

Maybe I need to bridle the tail of the ferd and look for a script which lists the set of properties of a selected object...

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
November 5, 2018

I have now selected my reddish polyline  and run this simple script:

var oDoc = app.ActiveDoc;

var oObject = oDoc.FirstSelectedGraphicInDoc;

$.writeln (oObject.Points[0]);

But I get only this:

[object Point]

And the Data Browser is very closed about the Points:

So even inspecting existing objects does not reveal the nature of the point structure... GRRRRRRRRRRRRRR

How on earth can i find out how to define the points for the polyline?

Ian Proudfoot
Legend
November 5, 2018

Klaus,

The Data Browser does hide some useful information, but it can be made to reveal its secrets. In your case if you address the object's x or y properties like this you will get the result that may help:

$.writeln (oObject.Points[0].x);

$.writeln (oObject.Points[0].y);

I've not tried to create a polyline yet, but perhaps explicitly referencing x and y will do what you need?

Ian