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#if
thanks 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") end
Because 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 usetrue
orfalse
. -
By the way, what is the difference between a page
.name
and a page.label
? -
@jim said:
By the way, what is the difference between a page
.name
and 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.
Advertisement