• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Select an object based on its attributes

Scheduled Pinned Locked Moved Plugins
3 Posts 2 Posters 524 Views
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 18 Jan 2010, 16:18

    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
    • T Offline
      TIG Moderator
      last edited by 18 Jan 2010, 17:10

      @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 19 Jan 2010, 07:33

        thx TIG

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

        Advertisement