sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Select an object based on its attributes

    Scheduled Pinned Locked Moved Plugins
    3 Posts 2 Posters 524 Views 2 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.
    • P Offline
      Pauline01
      last edited by

      Hello,

      In this code i associate an adress and a type for an object.

      If i have 10 objects, 4 objects have as adress "9994" (in the dictionnary "MyDico", ZoneAdr="9994"), i want create a plugin to select all object with "9994" as adress.

      It's possible?

      thx

      
      def setzone
      prompt = ["Nom de la zone"]
        val = Sketchup.active_model.selection[0].get_attribute("MyDico", "ZoneAdr")
        default = [val]
        result = UI.inputbox prompt, default, "Enter le nom de la zone"
        adrresult = result[0].to_s
      
          adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "ZoneAdr", adrresult.to_s)
          UI.messagebox ("@ ; " + adr.to_s + " saved")
      
        adrresult="5"
        adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "ZoneType", adrresult.to_i)
      end
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        @pauline01 said:

        Hello,
        In this code I associate an address and a type for an object.
        If I have 10 objects, 4 objects have as address "9994" (in the dictionary "MyDico", ZoneAdr="9994"), I want create a plugin to select all object with "9994" as address.
        It's possible?
        thx

        
        > def setzone
        > prompt = ["Nom de la zone"]
        >   val = Sketchup.active_model.selection[0].get_attribute("MyDico", "ZoneAdr")
        >   default = [val]
        >   result = UI.inputbox prompt, default, "Enter le nom de la zone"
        >   adrresult = result[0].to_s
        >     adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "ZoneAdr", adrresult.to_s)
        >     UI.messagebox ("@ ; " + adr.to_s + " saved")
        >   adrresult="5"
        >   adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "ZoneType", adrresult.to_i)
        > end
        > 
        

        You need to iterate through all of the model's entities [or a selection of things] and look for that attribute...
        Here's an example...

        
        model=Sketchup.active_model
        entities=model.selection.to_a
        ### OR
        entities=model.entities.to_a
        ### THEN
        zoneAdrs=[] ### an array
        entities.each{|e|
          if e.get_attribute("MyDico","ZoneType","")=="9994"
            ### it's a string - could be integer ==
            zoneAdrs << e
          end#if
        ### NOW zoneAdrs is an array of all entities with ZoneType == "9994"
        }
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • P Offline
          Pauline01
          last edited by

          thx 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