sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Adding Flipped Component Instance

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 177 Views 3 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

      In the script I am writing I need to add a copy of a flipped component. After selecting the flipped component I use this code but the copy is the same if I have selected the orgional component or flipped component.

      @model = Sketchup.active_model
      @layers = @model.layers
      @ss = @model.selection
      @ents = @model.active_entities
      @entities = @model.entities
      @pages = @model.pages
      @count = @pages.count
      @length = @layers.length
      @definitions = @model.definitions
      
      entity = @ss.first
      ent_def = entity.definition
      insert_tran = Geom;;Transformation.new [0,0,0]
      c2=@model.active_entities.add_instance(ent_def,insert_tran)
      

      Keith

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

        You are adding an un-transformed instance with your code.
        If you want simply to duplicate whatever is selected then you can group it, copy the group and explode the group... provided it all takes place in the same entities context [aka model.active_entities]...

        gp=@model.active_entities.add_group(entity)
        cp=@model.active_entities.add_instance(gp.entities.parent, Geom;;Transformation.new())
        gp.explode!
        

        Now you have 'cp' which is a group containing an exact duplicate of the selection. IF you know it's one component-instance then ccopy=cp.entities[0] then cp.explode! - you now have a duplicate of ' entity' referred to as ' ccopy'... This works for all selected objects...

        TIG

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

          Thanks TIG that worked like I wanted it to. Seem a long way around but results are good.

          Keith

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            TIG, why are you exploding stuff when the question was about inserting a component instance mirrored? I'm I missing something there?

            Thomas Thomassen โ€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

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

              He wanted to copy a selected component-instance [that happens to be mirrored] and was trying to get its definition and place an instance etc.
              Obviously he could reuse the original's transformation...***
              I was trying to show him how he might copy "anything" that is selected, by grouping it.
              The code groups the selection, adds another instance of it and explodes the original.
              At that point if he knows the selection was the one component-instance then he has the option to explode its group, giving the same result as placing a second instance using the original's transformation, but if the selection is of something different - e.g. groups, geometry, mixed objects etc - he can choose to do other things with them within the safety of his group - e.g. non-merging geometry is preserved...
              ***For the avoidance of doubt here is how to duplicate an instance with the same matching transformation [i.e. position,rotation,scaling,mirroring etc]... Assuming that 'instance' is what's been selected/found and it has been tested and found to be a ComponentInstance...
              copy_of_instance = instance.parent.entities.add_instance(instance.definition, instance.transformation)
              ๐Ÿ˜’

              TIG

              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