sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Index of entity

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 5 Posters 936 Views 5 Watching
    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.
    • Didier BurD Offline
      Didier Bur
      last edited by

      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

        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

          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

            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
            • Didier BurD Offline
              Didier Bur
              last edited by

              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

                😲

                😕

                😞

                🤢

                Grmbl !
                Merci didier !! 😆

                Frenglish at its best !
                My scripts

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Matt666
                  last edited by

                  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
                  • chrisglasierC Offline
                    chrisglasier
                    last edited by

                    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
                    • Didier BurD Offline
                      Didier Bur
                      last edited by

                      @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

                        @unknownuser said:

                        Dans la doc pardi.

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

                        1 Reply Last reply Reply Quote 0
                        • Didier BurD Offline
                          Didier Bur
                          last edited by

                          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
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement