sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Question about pages

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 336 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      ktkoh
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • K Offline
        ktkoh
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          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.

          Hi

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Also, string comparisons are slow. Instead of "yes"/ "no" it's better to use true or false.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              By the way, what is the difference between a page .name and a page .label?

              Hi

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @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.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement