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

    Combining components into 1 component

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 2 Posters 3.3k 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.
    • K Offline
      ktkoh
      last edited by

      I am bringing 3 parts (components) which are placed such that if all 3 are exploded and then all selected and made a single component. I have not been able to accomplish this with the API. Any suggestions

      Keith

      1 Reply Last reply Reply Quote 0
      • K Offline
        ktkoh
        last edited by

        I worked on this some more and found a Solution.
        Created a new layer
        added each comp to that layer
        exploded each comp
        cleared selection
        added all entities on the layer to the selection
        added selection to new group
        cleared selection
        added group to selection
        I could now make the group a solid I did not need a component at this point.

        1 Reply Last reply Reply Quote 0
        • sdmitchS Offline
          sdmitch
          last edited by

          @ktkoh said:

          I am bringing 3 parts (components) which are placed such that if all 3 are exploded and then all selected and made a single component. I have not been able to accomplish this with the API. Any suggestions

          Keith

          1. Create a group
          2. Add instances of each component to the group and explode
          3. Convert group to component.
          mod = Sketchup.active_model
          ent = mod.active_entities
          sel = mod.selection
          SKETCHUP_CONSOLE.clear
          grp = ent.add_group
          cmp = grp.entities.add_instance(mod.definitions["component#1"],IDENTITY);cmp.explode
          cmp = grp.entities.add_instance(mod.definitions["component#2"],IDENTITY);cmp.explode
          cmp = grp.entities.add_instance(mod.definitions["component#3"],IDENTITY);cmp.explode
          cmp = grp.to_component;cmp.definition.name="Cmps1-3"
          
          
          

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • K Offline
            ktkoh
            last edited by

            I will try Mitch's code. Question there are 2 constantans I am not familiar with in your code. SKETCHUP_CONSOLE.clear and IDENTITY.

            The problem with my version is that the entities that make up the final are on the Components layer not layer0. In the code I thought I was moving them back to layer0 but it didn't work and it didn't flag an error.

            @sss.clear
            		ents = []
            		@entities.each { |e| ents << e if (e.layer.name == @assy_Name) && ( ! e.is_a?(Sketchup;;Group) && ! e.is_a?(Sketchup;;ComponentInstance) )}
            		ents.each { |e| e.layer.name = "Layer0" }
            		@ss.add(ents)
            		copedRail = @entities.add_group(@ss)
            		@ss.clear; @ss.add copedRail
            		copedRail.layer = @assy_Name
            

            Thanks
            Keith

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              @ktkoh said:

              I am not familiar with in your code. SKETCHUP_CONSOLE.clear and IDENTITY.

              SKETCHUP_CONSOLE.clear simply clears the Ruby Console so any errors that occur will be more obvious.

              IDENTITY is the same as Geom::Transformation.new().

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • K Offline
                ktkoh
                last edited by

                Thanks Mitch your code worked very well once I figured out the transformation I needed. The code also left the component entities on Layer0 which was a problem for my code.

                The forum is an amazing source of info thanks to the many people who are willing to share their knowledge.

                Keith

                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