Ruby Help for Components & Layers
-
I am trying to move a component created in a rb file to a new layer also created by that file. This code moves the enities so they are only visible on the new layer but when I check the Info the component is still on layer0. Is there a way to define the component layer knowing the name? Or is there a way to select the component knowing the name? (As I am able to change the layer of a selected component so I could make that work.)
model = Sketchup.active_model model.start_operation "CreateBox" name = "WebTest" layerno = "01" # Create new layer for Part Assembly layers = model.layers newname = "A" + layerno + "-" + name if layers[newname] UI.messagebox("Layer \"#{newname}\" exists, exiting.") return end layer = layers.add newname pb = layer.page_behavior = LAYER_IS_HIDDEN_ON_NEW_PAGES model.pages.each { |p| p.set_visibility( layer, false ) } entities = model.active_entities group = entities.add_group entities = group.entities pts = [] pts[0] = [0, 0, 0] pts[1] = [10, 0, 0] pts[2] = [10, 1, 0] pts[3] = [0, 1, 0] base = entities.add_face pts width = -4if( base.normal.dot(Z_AXIS) < 0 ) # Now we can do the pushpull base.pushpull width # Put entities on layer named "newname" entities.each{|e|e.layer=newname} # Now we are done and we can end the operation model.commit_operation # If you want the group to be a Component try the following. component_instance=group.to_component component_instance.definition.name=name model.commit_operation
Keith
-
You never set the layer property for your group.
at where you got this line:
group = entities.add_group
add:
group.layer = layer
-
And if you want to create components, then you use
model.definitions.add "newCompName"
http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#addAnd then place an instance of the definition. http://code.google.com/apis/sketchup/docs/ourdoc/entities.html#add_instance
Instead of making a groups and then converting the group.
Advertisement