Why does this code take a long time and runing SketchUp menus the effect is immediate? Is there any instructions to do the same directly, like group.soft=true / group.smooth=true?
model = Sketchup.active_model
selection = model.selection
edges=[]
selection.to_a.each{|e|
edges << e if e.class==Sketchup::Edge
e.entities.each{|ee|edges << ee if ee.class==Sketchup::Edge}if e.class==Sketchup::Group
}
edges.each{|edge|
ang=edge.faces[0].normal.angle_between(edge.faces[1].normal)
if edge.faces[1]
edge.soft=true if ang < 20.degrees
edge.smooth=true if ang < 20.degrees
end
The #soft and the #smooth instance methods can be apply only for the edges. You have to do recursively similar as in your exampleā¦ however I think it could be optimized more.
As far as i know, since Ruby API is just a wrapper on top of C++ core, I guess, the āSketchUp menus the effect is immediateā is much more effective because it written naively in C++ ā¦ (But Iām not much familiar with thisā¦ even Iām not really sure if it s C++ at all )
model = Sketchup.active_model
selection = model.selection
groups = selection.grep(Sketchup::Group)
### now examine the selected group[s] entities for suitable edges...
groups.each{|group|
edges = group.entities.grep(Sketchup::Edge)
edges.each{|edge|
ang = edge.faces[0].normal.angle_between(edge.faces[1].normal)
if edge.faces[1]
edge.soft=true if ang < 20.degrees
edge.smooth=true if ang < 20.degrees
end
}
}
@dezmo
How about this to minimize the ātestingā and weirdness with multi-faced edges? ā¦
###...
edges.each{|edge|
if edge.faces.length == 2
ang = edge.faces[0].normal.angle_between(edge.faces[1].normal)
if ang < 20.degrees
edge.soft=true
edge.smooth=true
end
end
}
###
@ene_su
Clearly the OPās post is just a snippet of codeā¦
It needs to be enclosed inside its own modules[s] and as you suggest the model.start/commit_operations need adding to ensure undoing etcā¦