Selection start/end detection
-
Hello Ruby noob alert

I manually draw a line with the pencil tool and select it. If I then have a script with the code below the variable selection contains my line,I know because the clear deselects my line on the screen. My question is how do i get the start and end points of the selected line? I have been reading the google api site, but tbh the code examples are very fragmentry and putting stuff together is hard.
model = Sketchup.active_model selection = model.selection selection.clear -
I made this mistake just yesterday (with def), but
endis a Ruby keyword and not such a good name for a variable. -
@jim said:
I made this mistake just yesterday (with def), but
endis a Ruby keyword and not such a good name for a variable.
-
A "Selection" is a collection of entities (lines, faces, etc.)
In order to get the line, you have to get the first object in the Selection, since you only have one thing selected:
line = selection[0]Then, once you have the line, you can get the start and end vertices like this:
vtxStart = line.start vtxEnd = line.endTo get the positions of the vertices, just type either:
startPosition = vtxStart.positionorendPosition = vtxEnd.positionHopefully this is clear enough to get you started.
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