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.
Advertisement