[REQ] Reverse curve script
-
You mean the order the edges appear? That start edge becomes end edge?
Or is it related to the shape of the curve? -
Reversing the vertices order.
I'm trying to animate using curves and some of them are reversed which makes the camera look backwards.
The secondary script is to put a construction point at the beginning of a curve for easy finding the reversed curves.
"Mark curve start point" or something like that. -
Here's some code snippets
curve = some_curve_object # fill in what you need # Reverse points in a curve points = curve.vertices.reverse.collect { |vertex| vertex.position } # (!) You want to delete the curve from the model at this point. How you do this depends if you need to consider attached faces. Sketchup.active_model.active_entities.add_curve(points) # Construction point at start Sketchup.active_model.active_entities.add_cpoint(curve.vertices[0].position)
-
I've tried the construction point at start but that didnt work as expected. Sometimes puts it at first vertice but other times in the middle of a curve. Hmmmm.
Here is the code I used:
Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.selection.vertices[0].position)
-
Oh.
I assumed that the vertices returned where in order. That means none of my examples works...
Maybe a sorting routine that starts with the starting edges and traverses the connected edges is required.... -
Or maybe not.
That sample code line you used didn't work for me.Error is here:
Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.%(#FF8000)[**selection.vertices[0]**].position)
corrected version that appear to work:
Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.selection[0].curve.vertices[0].position)
-
Yes thanks that seem to work.
Now if only I can reverse them... -
My example doesn't work?
-
# Get the Curve object from the selection curve = Sketchup.active_model.selection[0].curve # Reverse points in a curve points = curve.vertices.reverse.collect { |vertex| vertex.position } # Erase the original curve curve.parent.entities.erase_entities(curve.edges) # Rebuild it Sketchup.active_model.active_entities.add_curve(points)
-
Thanks, it works fine now.
I have attached the script if anyone else needs it.
Now off to fix those troublesome animation curves...
Advertisement