[REQ] Reverse curve script
-
Could someone please write a script to reverse the direction of a selected curve?
Possibly a secondary script to put a construction point at the first point of a curve for finding reverse curves.
Please!
-
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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement