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

    Can I tag an object with data and color the object....

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 580 Views 4 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.
    • N Offline
      not registered yet
      last edited by

      I guess this is a two part question. Is it possible to add custom fields to an object, for example an object name and color? Can I color an object based on the data in a custom field?

      Basically I'd like to use sketchup to do some performance mapping. I'd like to import a file containing a number that identifies an object and a number representing it's performance. Based on that I'd like each object to be colored or shaded based upon that number.
      Is this possible or practical?
      Thanks,
      Mark

      [marsol]

      1 Reply Last reply Reply Quote 0
      • R Offline
        RickW
        last edited by

        Generally speaking, attributes are the way to go for something like this.

        RickW
        [www.smustard.com](http://www.smustard.com)

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

          As RickW said - you'd import the ID and value list and in turn assign each to an instance of something in SUp - that could be a face or perhaps a component that is pre-inserted - with each located as also set out in the list ?

          Then once they are all insertd and have had their attributes assigned - say you call them "Marsol's" "ID" and "Value" - your script would then loop through and gives each of them a material [colour] that matches the value it now has as an attribute. You'd need to set up some range rules since I expect you'll only want say 8, 16 or 32 colours, applied to more that that number of values... Say Bright-Red, Orange, Yellow, Green, Blue, Indigo, Violet and Dark-Purple for high to low, with the extra intermediate ones shades in between... You can readily make material/colours and give them names, then assign them to entities.

          Once inserted then rerunning with a new list of the same things with that ID, but new values could update the colours to suit...

          TIG

          1 Reply Last reply Reply Quote 0
          • daikuD Offline
            daiku
            last edited by

            One issue you may run into is wanting to color two instances of the same component with different colors. I've wanted to do that in my scripts, and haven't been able to find a way. If someone knows differently, I'd love to hear about it. CB.

            Clark Bremer
            http://www.northernlightstimberframing.com

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

              @daiku said:

              One issue you may run into is wanting to color two instances of the same component with different colors. I've wanted to do that in my scripts, and haven't been able to find a way. If someone knows differently, I'd love to hear about it. CB.

              Make the component with the default material - either manually beforehand as a component on a knowable path or better within the script - make a group, add faces etc (they'll have the default material 'by default' !), make that group into a component definition, place instances of that component as desired etc.
              For each instance of the component you place, as you place it just set its material to the required colour...

              component_instance.material="Red"
              

              etc...
              Here's how to make new colors/materials, that aren't the built-in ones like "Red"...

              mat_new="My New Material"### or whatever name you like...
              extg=nil
              Sketchup.active_model.materials.each{|mat|extg=mat if mat.name==mat_new}
              if extg ### it is made already
                    mat_n=extg
              else ### it hasn't been made yet
                    mat_n=Sketchup.active_model.materials.add(mat_new)
                    mat_n.color=[66,100,200]### adjust RGB colors here as desired.
              end ### if
              ### then give that material to the instance...
              component_instance.material=mat_new
              

              ...

              TIG

              1 Reply Last reply Reply Quote 0
              • daikuD Offline
                daiku
                last edited by

                My Mistake. The problem I had been stuggling with was painting individual faces within an instance without changing the other instances. CB.

                Clark Bremer
                http://www.northernlightstimberframing.com

                1 Reply Last reply Reply Quote 0
                • R Offline
                  RickW
                  last edited by

                  Yeah, that can't be done. It would violate the rules of component definitions. 😄

                  Your options: either paint the instance, or make an instance unique (but then you are creating a new definition).

                  Sorry I don't have better news...

                  RickW
                  [www.smustard.com](http://www.smustard.com)

                  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