Question about pages
-
working on new plugin and I need to check the Text name of each existing page and this code does not work or give an error message. How should it be written?
model = Sketchup.active_model selection = model.selection pages = model.pages pages.each {|name= page.name| UI.messagebox name}Thanks Keith
-
I found the solution to the page name question.
# Add page named Assembly if not already added pagename=[] pgAssy = "no" pages.each {|p| pagename = p.name if pagename == "Assembly" pgAssy = "yes" end }#if and each loop if pgAssy == "no" pages.add "Assembly" end#ifthanks for looking
Keith -
That looks like it will work, ktkoh. You could also have done this:
pages = Sketchup.active_model.pages if (pages["Assembly"].nil?) pages.add("Assembly") endBecause when you try to retrieve a Page which does not exists, you get
nil. -
Also, string comparisons are slow. Instead of
"yes"/"no"it's better to usetrueorfalse. -
By the way, what is the difference between a page
.nameand a page.label? -
@jim said:
By the way, what is the difference between a page
.nameand a page.label?Seem to be the same, except label doesn't have a setter...
The examples for the getters are pretty much the same.
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