Some Ruby Help
-
I am trying to set a layer to be visible on one page using the code:
page = page.set_visibility layer visibilityI have put this code in the ruby console and it runs without error but the layer is not visible on the page as I expected.
model = Sketchup.active_model entities = model.entities selection = model.selection layers = model.layers pages = model.pages page = pages["Blank Page"] if (page) UI.messagebox page layername = "A01-Test" page = page.set_visibility ["A01-Test"], [true] else UI.messagebox "Failure" endWould someone help point out the error in my code?
Keith
-
@ktkoh said:
I am trying to set a layer to be visible on one page using the code:
page = page.set_visibility layer visibility
I have put this code in the ruby console and it runs without error but the layer is not visible on the page as I expected.
...I have taken the liberty of putting your post's code inside [Code]-braces...
Assuming you have a page called "Blank Page" and a layer called "A01-Test" then the pageset_visibilitymethod takes a 'layer' (NOT a layer name) and a 'boolean' i.e. true or false (NOT an array), so just recast it as follows...
page.set_visibility(layers["A01-Test"],true)I see no need to set the result to anything unless you want to test if it's done it - the method returns the page if successful and nil if failed...
It should now work...

-
TIG thanks that worked like I needed it to. Next time I'll remember to add the code brackets. I am in the process of adding features to my makepart ruby and as someone wrote the monkey see monkey do coding only goes so far.
Keith
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