Followme in ruby not working as expected
-
My first post! I'm trying to write a sketchup importer that reads coordinates of walls from a text file then draws a line using the coordinates and draws the wall using followme.
The reason I want to use followme rather than just drawing faces is I want to draw the external brick leave and then the internal block wall and have corners drawn neatly.
Here is some example code (similar to how the importer will work)
` mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
wallGroup = ent.add_group#face points
pt1 = [0,0,0]
pt2 = [0,10,0]
pt3 = [0,10,100]
pt4 = [0,0,100]#line points
lpt1 = [0,0,0]
lpt2 = [150,0,0]
lpt3 = [100,150,0]
lpt4 = [0,100,0]face = ent.add_face pt1, pt2, pt3, pt4
line = ent.add_line lpt1, lpt2
line = ent.add_line lpt2, lpt3
#the line below doesn't work with follow me
#line = ent.add_line lpt3, lpt4#line = ent.add_line lpt4, lpt1
status = face.followme line`
follow me seems to be inconsistent in its behavior. If I draw the first two lines and use followme it works exactly how I want and the wall looks like this.
If however I try drawing three lines then followme I get this.
Can anyone explain where I'm going wrong? Any help is appreciated!
-
Draw the 3 edges in one go thus:
face = ent.add_face(pt1, pt2, pt3, pt4) lines = ent.add_edges(lpt1, lpt2, lpt3, lpt4) status = face.followme(lines)
Incidentally you set
ent=model.entities
- it would be better to refer to the active entities in case the user is in an edit mode...
ent=model.active_entities
You also make a group and do not use it ?
wallGroup = ent.add_group
Why not add the new geometry directly to that? Thus:
ents=wallGroup.entities
then refer to thatents
rather thanent
, thus:
face = ents.add_face(pt1, pt2, pt3, pt4) lines = ents.add_edges(lpt1, lpt2, lpt3, lpt4) status = face.followme(lines)
-
Thanks TIG! Will give that a go.
-
Is this what you are after?
mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection wallGroup = ent.add_group #face points pt1 = [0,0,0] pt2 = [0,10,0] pt3 = [0,10,100] pt4 = [0,0,100] #line points lpt1 = [0,0,0] lpt2 = [150,0,0] lpt3 = [100,150,0] lpt4 = [0,100,0] path = [] face = ent.add_face pt1, pt2, pt3, pt4 path.push ent.add_line lpt1, lpt2 path.push ent.add_line lpt2, lpt3 #the line below doesn't work with follow me path.push ent.add_line lpt3, lpt4 #line = ent.add_line lpt4, lpt1 status = face.followme path
-
Hi Jim,
Yes that's exactly what I wanted! Thank you. I've managed to get the code to draw the internal leaf as well. The only small problem now is I'm repeating myself in the code to get this result, which seems wrong.
Is there anyway to get this result without have almost identical code running twice? Is there anyway to push two faces along the same path at the same time to give the result below?
fyi this is how the code looks now.
` mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
wallGroup = ent.add_group#face points
pt1 = [0,0,0]
pt2 = [0,10,0]
pt3 = [0,10,100]
pt4 = [0,0,100]pt5 = [0,20,0]
pt6 = [0,30,0]
pt7 = [0,30,100]
pt8 = [0,20,100]#line points
lpt1 = [0,0,0]
lpt2 = [150,0,0]
lpt3 = [100,150,0]
lpt4 = [0,100,0]path = []
face = ent.add_face pt1, pt2, pt3, pt4
path.push ent.add_line lpt1, lpt2
path.push ent.add_line lpt2, lpt3
path.push ent.add_line lpt3, lpt4#line = ent.add_line lpt4, lpt1
status = face.followme path
path = []
face= ent.add_face pt5, pt6, pt7, pt8
path.push ent.add_line lpt1, lpt2
path.push ent.add_line lpt2, lpt3
path.push ent.add_line lpt3, lpt4status = face.followme path`
Advertisement