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" end
Would 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_visibility
method 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
Advertisement