• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to add components to another component? [ruby]

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 5 Posters 466 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.
  • N Offline
    NewOne
    last edited by 8 Oct 2009, 12:39

    I want to select several component instances in my model, based on name, and group them in a bigger component.
    Something like this:

    Component#1 |
    Component#2 |--> Parent_Component
    Component#3 |

    Test#1 |
    Test#2 |
    Test#3 |--> Parent_Test
    Test#4 |
    Test#5 |

    But I really don't understand how. I thought I have to use entities.add_instance method, but I can't make it work. And there is a Transformation attribute which I don't understand. All I can do is to add a New empty component definition in model.

    Any help, please? Thanks.

    1 Reply Last reply Reply Quote 0
    • C Offline
      chrisglasier
      last edited by 8 Oct 2009, 12:49

      Add component 1, 2 & 3 to selection; make selection component ... perhaps?

      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
      • C Offline
        cjthompson
        last edited by 8 Oct 2009, 14:40

        Can you explain how you select the components?

        The easiest way would to be what chrisglasier suggested. However, if you want to do it in a ruby script, one way would be:

        add a group, add the instances inside the group (group.entities.add_instance(instance.definition,instance.transformation)), delete the previous instances, and use group.to_component

        if you add a group, you don't have to worry about transformations.

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by 8 Oct 2009, 14:50

          The easiest thing to do..

          
          model = Sketchup.active_model
          selection = model.selection
          # use any array of entities
          g = model.entities.add_group(selection.to_a)
          g.to_component
          
          

          Note the API warns against using add_group in this way, but I don't think it will be a problem when adding Instances.

          Hi

          1 Reply Last reply Reply Quote 0
          • C Offline
            chrisglasier
            last edited by 8 Oct 2009, 15:18

            @jim said:

            The easiest thing to do..

            
            > model = Sketchup.active_model
            > selection = model.selection
            > # use any array of entities
            > g = model.entities.add_group(selection.to_a)
            > g.to_component
            > 
            

            You put the code right into my words!

            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
            • T Offline
              TIG Moderator
              last edited by 8 Oct 2009, 15:30

              If you want to 'select' something ...

              
              ### Let's assume you have an array [list] of the items to add to the component, called 'list'...
              ### If you have selection made that has 'raw' faces in it then add those faces' edges too to the list, if those edges then have other faces those faces and edges too - '.all_connected. ???
              ### This is what causes bugsplats - when parts of 'connected things' are put into different entities sets...
              model=Sketchup.active_model
              selection=model.selection
              selection.clear
              selection.add(list)
              ### OR list.each{|e|selection.add(e)}
              ### then the code...
              g=model.active_entities.add_group(selection.to_a)
              inst=g.to_component
              inst.name="MyInstancesName"
              defn=inst.definition
              defn.name="MyComponentsName"
              ### check it hasn't incremented; using dname=defn.name; compare dname to "MyComponentsName", e.g. it might now be "MyComponentsName#1"
              ### etc...
              
              

              TIG

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

              Advertisement