Index of entity
-
Hi !
I don't know if it's what you want, but here is a code counting components like the selection.class Sketchup;;ComponentInstance def count cn = 0 cdef = self.definition.name sel = Sketchup.active_model.active_entities sel.each do |ent| if ent.typename == "ComponentInstance" if ent.definition.name == cdef cn +=1 end end end cn end end
Example : Sketchup.active_model.selection[0].count
I don't know how to with groups yet ! I believe that each group is unique, no ?
I will see... -
Hey Matt - your code isn't complete.
If you want to find all the occurrences of a component, you can't just search the top level of all entities. You'll need to drill into Groups and other Components as well.
Todd
-
Hello Todd !
Ooh !! Excuse me !
class Sketchup;;ComponentInstance def count @cn = 0 boucle Sketchup.active_model.active_entities, self.definition.name @cn end end #class def boucle(entities, nam) entities.each do |entity| case entity.typename when 'Group' boucle entity.entities, nam when 'ComponentInstance' @cn +=1 if entity.definition.name == nam boucle entity.definition.entities, nam end end end
Thank you !
-
Hey men, don't re-invent the wheel...
count = component_definition.count_instances
Stock methods seems much more simple too me. -
Grmbl !
Merci didier !! -
Didier, tu as trouvé cette fonction où ??? Et yen a encore beaucoup des comme ça ???
Didier, where have you found it ??? -
Thank you for all your suggestions. I am sorry to report that I can't get any of them to give me the entity array index number for the selected entity. I guess there is something I have done elsewhere that I do not yet have the experience to spot - I will keep your suggestions for later. I think it only natural to want to click on the images if the nameset is in the same screen as sketchup but I can get the index number from the javascript that spins out the entities. But I can't get the entity to show as selected. Is this possible? Attached are a couple of shots indicating what I can manage. Thanks again.
Chris
PS The main point is purely to show what has been selected , particularly important when there are many of the same components. I plan for Javascript to handle defining of relationships, alignments and so on. The screen is then cleared and entities respun out.
-
-
-
La doc la moins mauvaise est celle de SU lui-même...
Quand je ne sais pas quelles méthodes sont valides sur un objet, j'en sélectionne un exemplaire dans le modèle, et dans la console Ruby:
a=Sketchup.active_model.selection[0] a.methods
Cela renvoie toutes les méthodes applicables à ce type d'objet.
Advertisement