Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download
Select an object based on its attributes
-
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 -
@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" } -
thx TIG
Advertisement