evalCommandGetLabels problem

János Losonczi shared this question 2 months ago
Answered

Dear All,

I have a tool "MyTool", which creates many labelled objects (points, segments, conics, a quadrilateral and a list). At this moment I can manipulate these objects by the help of the information stored in the list.

I'd like to change my way and my new idea is to utilise the evalCommandGetLabels command in JavaScript.

At first I tested this technique in a simple case, I created only one object, a point, then I hid it. It worked.

var Labels = ggbApplet.evalCommandGetLabels("A = (0, 0)");
ggbApplet.evalCommand("SetVisibleInView("+Labels+" , "+1+", "+false+")");	// it does work
My problem is that when I try to change the type of my variable "Labels" to array (because "MyTool" creates more than one object), it doesn't work neither with- nor with index.

var Labels = [];
ggbApplet.evalCommand("A = (0, 0)");
ggbApplet.evalCommand("B = (0, 5)");
Labels = ggbApplet.evalCommandGetLabels("MyTool(A, B)");
ggbApplet.evalCommand("SetVisibleInView("+Labels+" , "+1+", "+false+")"); 	// it doesn't work (without index)
ggbApplet.evalCommand("SetVisibleInView("+Labels[0]+" , "+1+", "+false+")");	// it doesn't work (with index)
Can anybody help me?

Best regards,

JL

Comments (4)

photo
1

you can use this line to get a javascript array:

Labels = Labels.toString().split(",")

photo
1

Then, you can use Labels[0], Labels[1] etc.

photo
photo
1

As Tang Dashi say: evalCommandGetLabels return a String and not a JS-list.

attached test with alert.

photo
1

Thank you both for the useful answers.

JL

© 2018 International GeoGebra Institute