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

    Ruby Equivalent of Move/Copy

    Scheduled Pinned Locked Moved Plugins
    6 Posts 3 Posters 3.7k 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
      kybasche
      last edited by

      Hey all.

      I have a general understand of how to move entities using transformations.

      But here's what I don't know how to do.

      I have a group.

      group_shell=model.active_entities.add_group()
      ents=group_shell.entities
      points_box=[[0,0,0],[5,0,0],[5,10,0],[0,10,0]]
      		
      face_box=ents.add_face(points_box)
      face_box.pushpull(-20)
      

      I'd like to make a copy of that group and move it to a different location. (I want two identical boxes sitting next to each other)

      (yes, it's more complicated than just a box πŸ˜‰ )

      That's it.

      Any hints?

      Thanks!
      Derek

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

        kybasche,

        group_shell=model.active_entities.add_group()
        ents=group_shell.entities
        points_box=[[0,0,0],[5,0,0],[5,10,0],[0,10,0]]
              
        face_box=ents.add_face(points_box)
        face_box.pushpull(-20)
        group_shell_copy=group_shell.copy#create a copy
        tr=Geom;;Transformation.new([10,0,0])#copy location
        group_shell_copy.transform! tr
        
        

        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
          kybasche
          last edited by

          Brilliant!!

          Thanks sdmitch.

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

            One of the problems with using the standard group.copy method is that there are a few rogue scripts out there that mess with the function because they ill-advisedly change built-in classes/methods or have poorly formed observers etc - e.g. SketchyPhysics and DrivingDimensions... As some of these are popular it's best to avoid the .copy method in a distributed script, where you have no control over what other tools the user has installed...
            I forgot and had to recast SuperDrape the other day and I also remade Mirror a while ago too.
            The alternative way produces the same result...
            group_copy = group.copy
            becomes
            group_copy = group.parent.entities.add_instance(group.entities.parent, group.transformation)
            I know it's a lot more convoluted BUT it does the same thing and doesn't seem to have issues with other scripts so much πŸ˜’
            In you case you can do the [predefined] transformation as you add the instance
            group_copy = group.parent.entities.add_instance(group.entities.parent, tr)

            TIG

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

              TIG, Thanks for the info. As many times that I have searched through the Ruby API Document, I never saw that .add_instance could be applied to groups. It's always a good day when you learn something new.

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

              http://sdmitch.blogspot.com/

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

                You can only use entities.add_instance() of a definition, BUT there's no built in group.definition method πŸ˜’ , BUT all components, groups and images are all just types of instances of a definition.
                To find a group's definition you have to find its entities' parent which is the definition - so
                defn = group.entities.parent

                ComponentDefinition
                just as the much snappier method defn = instance.definition does for a component-instance !
                The second argument of the entities.add_instance(defn, **tr**) is the transformation used to place/manipulate the new instance...

                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