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

Index of entity

Scheduled Pinned Locked Moved Developers' Forum
12 Posts 5 Posters 907 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.
  • C Offline
    chrisglasier
    last edited by 12 Jun 2008, 10:24

    I want to find the index number of a single selected entity (componentInstance or group) in a model but I just cannot find any coding recognisable to me. Any help gratefully received.

    Chris

    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

    1 Reply Last reply Reply Quote 0
    • D Offline
      Didier Bur
      last edited by 12 Jun 2008, 11:39

      id=Sketchup.active_model.selection[0]
      

      Is that what u r looking for ?

      or

      id=Sketchup.active_model.selection[0].id
      

      ?
      or

      Sketchup.active_model.selection[0].entityID
      

      ?

      DB

      1 Reply Last reply Reply Quote 0
      • M Offline
        Matt666
        last edited by 12 Jun 2008, 11:45

        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...

        Frenglish at its best !
        My scripts

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by 12 Jun 2008, 12:52

          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

          1 Reply Last reply Reply Quote 0
          • M Offline
            Matt666
            last edited by 12 Jun 2008, 14:55

            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 !

            Frenglish at its best !
            My scripts

            1 Reply Last reply Reply Quote 0
            • D Offline
              Didier Bur
              last edited by 12 Jun 2008, 15:18

              Hey men, don't re-invent the wheel...

              count = component_definition.count_instances
              

              ☀
              Stock methods seems much more simple too me.

              DB

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by 12 Jun 2008, 18:04

                😲

                😕

                😞

                🤢

                Grmbl !
                Merci didier !! 😆

                Frenglish at its best !
                My scripts

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Matt666
                  last edited by 12 Jun 2008, 18:11

                  Didier, tu as trouvé cette fonction où ??? Et yen a encore beaucoup des comme ça ??? 😮
                  Didier, where have you found it ???

                  Frenglish at its best !
                  My scripts

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    chrisglasier
                    last edited by 13 Jun 2008, 04:15

                    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.


                    Selection Group.jpg


                    Selection Component.jpg

                    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Didier Bur
                      last edited by 13 Jun 2008, 14:05

                      @unknownuser said:

                      Didier, tu as trouvé cette fonction où ???

                      Dans la doc pardi.

                      DB

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        confitex architure
                        last edited by 13 Jun 2008, 18:55

                        @unknownuser said:

                        Dans la doc pardi.

                        Hello,
                        Quelle doc? Du moins, laquelle est la meilleur?

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Didier Bur
                          last edited by 13 Jun 2008, 20:28

                          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.

                          DB

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

                          Advertisement