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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement