Well they title is a little bit misleading cause its hard to describe a situation in few words.
Here is the "task"
Let us start with a simple Line (just two points, but use polyline cause we want that line to grow)
What i want? To let the user SPLIT the line in 2 if he wants, create 2 lines, and then if he wishes to split,... split... making a huge polyline at subdivided at will.
My try was the following
1) create 2 arrays x y to hold the coord of the poly points
2) create a boolean array devide (on/off parameter)
I created the line, and put a hotspot in the center of the line, just to control the value of devide. (so if you go and drag the hospot you are changing the value of devide from 0 to 1 and signaling a split of the line)
The problems start now.
Unfortuantelly to make the programm do smthg you have to put code to master script as there are no ONParameter change functions
The problem is that after you update the x,y arrays with the new coord which can be doen using a temp array, you have to reset the devide array back to zero.... But this cannot be done
Why? if i try to reset the divide array back to zero, then i cannot change the value with the hotspots (it just locks to zero).
If i ignore it... it sticks to 1 which signals subdivision, and i get mutliple unwanted divisions...
Does anyone have any suggestion on how to workaround that part?
If i could only simulate the Onchange parameter even...
The last time I did what you were doing, I used 4 arrays:
Array of current points (before edit)
Array of new points
Array of Midpoints for each leg (before edit)
Array of Midpoints for each leg (after edit)
You cannot use GLOB_MODPAR_NAME with arrays, so I had to increment through each midpoint array and its counterpart and see if there were any changes between them... even more fun is the reverse, if a point is moved on top of another removing a leg....
It's been so long since I did it, I can barely understand my own code, and it was one of the few people I ever wrote an object for who kept the rights to their code so I cannot even post an example.... sorry....
I am posting the testgdl i am writing because that is a better way to demonstrate the problem.
It draws a 2 point polyline. THats easy.
Ofcourse all nodes are movable.
In the middle of the line segment there is a hotspot the controls if the segment will be subdivided or not.
If i change the value of the array directly from the parameters box then the polyline subdivides and the new nodes appear. Everything runs fine.
BUT the middlenode hotspot does not work. It is locked.
Why? because at the master script i check if the divide swhich is one.. do the subdivision and then revert it back to zero. It seems that when a hotspot tryes to change the value of a variable the master script is run first and THEN the 2dscript. When a parameter value is changed from the parameter panel, the opposite happens. first the 2d script is run and then the master script....
I've created this a long time ago and I'm not sure in the exact method, but it works.
You can add new corners to the polygon by dragging the mid-points of the edges to a new location and dragging the Confirm hotspot. (It was necessary to give an event)
-Confirm text appears
-drag confirm hotspot
-Confirm text disappears
You can apply the same method for polylines as well.
Here is the code.
The variable divide can be any positive integer
The corresponding segment will be divided as many times.
So 1 will divide it in the middle and 9 will give you 10 segments... and so on....
Well actually is Ultra usefull cause you can use it in tons of gdl
( i am thinking of creating that way a 3dprofiler without the need of an addon, and that way a portable object)
Next version would let you create arc segments (although i dont know if its usefull or more a slow down of the system)
Hope its helpfull
P.S I think its obvious gdl needs events (both user triggered and programmer triggered)
Have You figured out how to remove particular segment from the polyline?
I am trying basing on the script published by Oreopoulos, but no success yet.
I hope someone figured it out. The optimal way of use would be by moving one vertex on the other - I added a variable that checks which segment was treated like that - but I could not get it to use.
Anyway I have modified the object so that closing poly does not use the status code but equals the endpoint with the startpoint - may be usable for using the closed poly (the matrix variable for it to be exact) as shape for 3d objects.
I also added hotlines and lines instad of poly_ command.
I also modified the way of addin the segments so that one segment could be added at a time (practically by clicking on middle hotspot - the real variables) - because the default polyline objects in AC work that way - and normal users would be confused.
I saw your attempts and now I'm trying to make my "dynamic" polyline object in GDL.
I don't understand why, in my code, something doesn't work properyly.
In fact as soon as I drag one of the middle points, the number of vertex increases by 4 (instead of 1) and the new vertex are put without considering the localtion of the middle points.
It's easier seeing the object's ehaviour it than trying to explain it ...
Thanks to everyone wants to give me a help ...
I've been using the PolyTest line to create dynamic elements linked along a path (hand rail posts, fence posts). I can graphically edit the object to create new segments, but I cannot set the number of segments in the object dialog box without getting errors. I think something has to be added to the parameter script to update the arrays and array values when the number of segments is changed in the object dialog box. Any ideas?