sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Component names

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 2 Posters 323 Views 2 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.
    • chrisglasierC Offline
      chrisglasier
      last edited by

      As you can see from this:

      screenMachine 01.jpg

      I can retrieve the names of scenes and layers. I can also seem to do things with properties to save, views, and styles. Collections and groupings are something for later. But I can't get to grips with retrieving component names. For example, what is bed.skp all about here?

      path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path name = componentdefinition.name

      I just want to make an array of each of the names that appear in the entity info box.

      Any help yet again 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
      • chrisglasierC Offline
        chrisglasier
        last edited by

        @tig said:

        To do stuff on the model's content you need to ...

        Looks great; many thanks 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
        • chrisglasierC Offline
          chrisglasier
          last edited by

          screenMachine 02.jpg

          Sorry one more bit of bother

          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
          • TIGT Offline
            TIG Moderator
            last edited by

            Sorry typo by me...

            insts=[];model.active_entities.each{|inst|insts.push(inst)if inst.typename=="ComponentInstance"}
            

            I usually use 'e' as my block variable BUT changed it to 'inst' to help you BUT forgot to change one !!! It's inst.typename... NOT e.typename... I've edited the original too...

            TIG

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              To do stuff on the model's content you need to find the placed component instances...

              insts=[];model.active_entities.each{|inst|insts.push(inst)if inst.typename=="ComponentInstance"}
              

              To find an instance's definition name use

              inst.definition.name
              

              , to find its individual instance name (you can also give each instance its own name using entity info...) you can use

              inst.name
              

              .
              To do stuff on the model's data-base definitions etc use

              defns=model.definitions;defns.each{|defn|insts=defn.instances;insts.each{|inst|###etc###} }
              

              Again defn.name or inst.name to give you their names...
              You can also find an instance's unique enduring ID if needed...
              Groups work slightly differently... but similar enough...

              TIG

              1 Reply Last reply Reply Quote 0
              • chrisglasierC Offline
                chrisglasier
                last edited by

                No sorry please! (Chinglish)

                Yes I thought that but thought maybe it was some special thing when I did not get the answer I was expecting with inst. I thought active_entities was the same as select all, but I see now it's not ... so I get all components rather than just those in the scene (like outliner does). If you have time to figure that out for me that would be great ...

                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
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  model.selection
                  

                  gives only currently selected entities

                  model.active_entities
                  

                  gives only entities that are currently 'active' i.e. editable - e.g. inside a group edit when you would want to ignore other external things

                  model.entities
                  

                  gives all of the model's entities, even those currently not editable.

                  It is often best to use 'active_entities' as it is equal to 'entites' if you are currently at the base model level but it's limited to the edited instance-definition/group's entities if you are not. If you use 'entities' and were to add something to them it is put at the base level - and it might then be outside of the group edit and lead to confusion/splats, whereas with 'active_entities' it is put at the lowest level in that edit, also note that definition.entities or group.entities returns the specified definition's or group's entities etc...

                  I think in your case 'model.entities' is what you want ?

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • chrisglasierC Offline
                    chrisglasier
                    last edited by

                    Ok thanks but it's not quite there yet I'm afraid, and this is of course a very important part of the whole.

                    If I select all from the edit menu, and then use model.selection instead of active_entities I can abstract just the instances that show in that scene (page). Is it possible to "ruby" the select all?

                    Chris

                    screenMachine 03.jpg

                    edit added pic

                    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
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      Use 'model.entities' and filter it thus ?

                      insts=[]
                      model.entities.each{|e|insts.push(e)if e.typename=="ComponentInstance"}
                      ### insts is then an array containing all of the instances in the model
                      ### you could also add names, groups etc
                      

                      If you want only things that are active then use 'model.active_entities'.
                      I'm not sure you can get things only if they are visible in a scene ?
                      Do you mean not 'behind' the camera ?
                      You can of course get if they are hidden or on off-layers etc and remove them from the array...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • chrisglasierC Offline
                        chrisglasier
                        last edited by

                        @tig said:

                        You can of course get if they are hidden or on off-layers etc and remove them from the array...

                        That's it ... but of course?? I'll get back on it tomorrow. In the meantime thanks for your help.

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

                          @chrisglasier said:

                          I'll get back on it tomorrow. In the meantime thanks for your help.
                          Chris

                          Here's the result:

                          # Lists components and groups (with hidden status) in a scene
                          	
                          @dlg.add_action_callback("findComponents") {|d, p|
                          	
                          model = Sketchup.active_model
                          entities = model.active_entities
                          
                          a = 0
                          array = []
                          
                          entities.each do |entity|
                          
                          if  entity.class == Sketchup;;Group || entity.class == Sketchup;;ComponentInstance 
                          
                          if entity.layer.visible?
                          
                          array[a] = []
                          
                          if  entity.class == Sketchup;;ComponentInstance 
                          array[a][0] = entity.definition.name
                          end
                          
                          if  entity.class == Sketchup;;Group
                          array[a][0] = entity.name
                          end
                          
                          array[a][1] = entity.hidden?
                          
                          array[a] = array[a].join(",")
                          
                          a+=1
                          
                          end  #if class
                          end  # if visible
                          end  #loop
                          
                          array = array.join(";")
                          
                          cmd = "receiveComponents('#{array}');"
                          @dlg.execute_script (cmd)      }
                          

                          Showing scene, aspect and component lists - 3 column,19 row nameset display
                          Tally ho!

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

                          Advertisement