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_operationKeith
-
You never set the layer property for your group.
at where you got this line:
group = entities.add_groupadd:
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.
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