Length line/Edge
-
hello,
how can i change the length of line/edge by ruby script ?regevz
-
Apply a scaling transformation to it.
-
The
edgehas twovertices- its 'ends'.
Found byedge.startandedge.endoredge.vertices[0]andedge.vertices[1].
Let's assume you want to move the edge's end bydist=100.mm
We know the 'line' of the edge fromline=edge.line, whereline[0]==edge.start.positionandvector=line[1]is the line's vector towards its 'end'.
Now work out where the new end would be by using anoffseton a copy of the end-point bydist...
new_end_point = edge.end.position.clone.offset(vector,dist)
So now we have the point where we want the end-vertex to move to.
You have to make atransformationto apply to thatvertex
[ruby:3gl99xg3]tr=Geom::Transformation.new(new_end_point)[/ruby:3gl99xg3]
Now you apply it to thevertex- it's done in a convoluted way for avertexcompared to other '[ruby:3gl99xg3]entities[/ruby:3gl99xg3]'...
If you are working in a group use '[ruby:3gl99xg3]group.entities...[/ruby:3gl99xg3]', but here I assume it's in the model...
[ruby:3gl99xg3]Sketchup.active_mode.active_entities.transform_entities(tr, edge.end)[/ruby:3gl99xg3]
The end-vertex of the edge should now move 100.mm further away from the start-vertex...
If you want to move the start-vertex then use [ruby:3gl99xg3]vector.reverse[/ruby:3gl99xg3] and substitute the start/end vertices.
For other units change the method e.g. [ruby:3gl99xg3]0.1.m[/ruby:3gl99xg3] or with no suffix it's taken as [ruby:3gl99xg3]inches[/ruby:3gl99xg3]...........
-
TIG, 10x allot for your detailed post.
very useful.regevz
@tig said:
The
edgehas twovertices- its 'ends'.
Found byedge.startandedge.endoredge.vertices[0]andedge.vertices[1].
Let's assume you want to move the edge's end bydist=100.mm
We know the 'line' of the edge fromline=edge.line, whereline[0]==edge.start.positionandvector=line[1]is the line's vector towards its 'end'.
Now work out where the new end would be by using anoffseton a copy of the end-point bydist...
new_end_point = edge.end.position.clone.offset(vector,dist)
So now we have the point where we want the end-vertex to move to.
You have to make atransformationto apply to thatvertex
[ruby:anqq9m2l]tr=Geom::Transformation.new(new_end_point)[/ruby:anqq9m2l]
Now you apply it to thevertex- it's done in a convoluted way for avertexcompared to other '[ruby:anqq9m2l]entities[/ruby:anqq9m2l]'...
If you are working in a group use '[ruby:anqq9m2l]group.entities...[/ruby:anqq9m2l]', but here I assume it's in the model...
[ruby:anqq9m2l]Sketchup.active_mode.active_entities.transform_entities(tr, edge.end)[/ruby:anqq9m2l]
The end-vertex of the edge should now move 100.mm further away from the start-vertex...
If you want to move the start-vertex then use [ruby:anqq9m2l]vector.reverse[/ruby:anqq9m2l] and substitute the start/end vertices.
For other units change the method e.g. [ruby:anqq9m2l]0.1.m[/ruby:anqq9m2l] or with no suffix it's taken as [ruby:anqq9m2l]inches[/ruby:anqq9m2l]...........
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