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

    Materials vs. Entities in model (screenshot)

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 5 Posters 561 Views 5 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.
    • thomthomT Offline
      thomthom
      last edited by

      Note: model.materials.length also include materials which Image element uses.

      Say you have 2 materials listed in SU's material browser:
      Material1
      Material2
      And you also have one Image element in the model.

      Then model.materials.length will report 3.

      Even more:
      Sketchup.active_model.materials.each { |m| puts m.display_name } Material1 Material2

      Notice it only lists the two material visible in the material editor.

      This on the other hand:
      (0...Sketchup.active_model.materials.length).each { |i| puts Sketchup.active_model.materials[i].display_name } Material1 Material2 Image1

      Now you get full access to all the material - even the ones that belong to Image elements.
      Be careful! I've had models where image materials has been applied to other geometry - which has lead to problems as you can't select or interact with the material in the Material Browser. So in most cases you want to iterate using .each.

      To get a count of just the materials available in the material browser:
      m_count = 0 Sketchup.active_model.materials.each { m_count += 1 }

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

      1 Reply Last reply Reply Quote 0
      • D Offline
        draftomatic
        last edited by

        Cool... except that I purged and there is still one material left - "0135_DarkGray". What's up now?

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

          @draftomatic said:

          Cool... except that I purged and there is still one material left - "0135_DarkGray". What's up now?

          You have it selected. The currently active material will not be purged. Select the default material before you purge.

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

          1 Reply Last reply Reply Quote 0
          • D Offline
            draftomatic
            last edited by

            @thomthom said:

            You have it selected. The currently active material will not be purged. Select the default material before you purge.

            I see... is there a way to find/change the currently active material thru Ruby?

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

              Sketchup.active_model.materials.current = nil

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

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                material.current is not in the API docs. Do we have that in the thread of things for Scott to fix?

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

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

                  Sorry, it's model.materials.current

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

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    😳 Sorry, I could have checked that....

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

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

                      @chris fullmer said:

                      material.current is not in the API docs. Do we have that in the thread of things for Scott to fix?

                      Is that being checked by Scott still?
                      I'm a bit confused if we're supposed to comment in the API docs...

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

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        There is a reported difference between materials.current on PC and MAC.
                        On a PC it's the currently selected material
                        On a MAC it's the last used material and this ignores what might now be selected IF it's never been used... 🤓

                        TIG

                        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