sketchucation logo sketchucation
    • Login
    1. Home
    2. SJH333
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 5
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: How do I move a Group of entities on their own?

      Now the Penny is dropping! Slowly... πŸ˜‰
      After a day going round in circles, I've had a productive evening...

      For absolute Newbies, here are some Group transformations (thanks yet again TIG):

      # 30/04/2011 SJH_Groups_Add_v03.rb
      puts "Running... SJH_Groups_Add"
      
        require 'sketchup.rb'
      
        model = Sketchup.active_model
        entities = model.entities
        #entities = model.active_entities
        selection = model.selection
      
        # Set some length variables
        rl = 1
        gl = 1
        bl = 1
        
        rlmid = rl*0.5  
        glmid = gl*0.5
        blmid = bl*0.5
        
        # To convert to SU current Model units
        rl = rl.to_s.to_l
        gl = gl.to_s.to_l
        bl = bl.to_s.to_l
        
        rlmid = rlmid.to_s.to_l
        glmid = glmid.to_s.to_l
        blmid = blmid.to_s.to_l
        
        
        # Create Face points array
        fpts = []
        fpts[0] = [0, 0, 0]
        fpts[1] = [rl, 0, 0]
        fpts[2] = [rl, gl, 0]
        fpts[3] = [0, gl, 0]
        
        # Create String and counter for incrementing group names
        sjhname = "SJHGroup"
        groupcount = 0
      
      # ---------- Start Main Code ----------
      
        groupcount+= 1
        groupname = sjhname + groupcount.to_s
        
        
      # Create a Group - mygroup1
        mygroup1 = []                                        # Create an empty array to prevent Bug Splat!
        mygroup1 = entities.add_group                        # Make the array a Group Entities class
        gentities1 = mygroup1.entities                       # Create an array of the Entities in mygroup
        mygroup1.name = groupname                            # Change the Group name
        face = gentities1.add_face fpts                      # Add a face to gentities1
        pullface = face.pushpull -bl                         # Do a push/pull to the face
        tcoordinates = [rlmid, glmid, blmid]                 # Set coordinates for text
        tpoint = Geom;;Point3d.new tcoordinates              # Create a 3d point for text
        mytext = gentities1.add_text "#{groupname}", tpoint  # Add a text label
        model.close_active                                   # Close mygroup1
      # Closed the Group
       
        UI.messagebox("mygroup1 added.  What's next?")       # User Message to see what happened!
        
      # Move everything in the model
        entlen = entities.length
        transform = Geom;;Transformation.new([(rl*2),0,0])
        
        for e in (0... entlen)
        entities.transform_entities(transform, entities[e])
        end
        
      # Select mygroup1
        #selection.add(mygroup1)  
      
        UI.messagebox("All entities moved.  What's next?")   # User Message to see what happened!
        
        groupcount+= 1
        groupname = sjhname + groupcount.to_s
        
        
      # Create a Group - mygroup2
        mygroup2 = []                                        # Create an empty array to prevent Bug Splat!
        mygroup2 = entities.add_group                        # Make the array a Group Entities class
        gentities2 = mygroup2.entities                       # Create an array of the Entities in mygroup
        mygroup2.name = groupname                            # Change the Group name
        face = gentities2.add_face fpts                      # Add a face to gentities2
        pullface = face.pushpull -bl                         # Do a push/pull to the face
        tcoordinates = [rlmid, glmid, blmid]                 # Set coordinates for text
        tpoint = Geom;;Point3d.new tcoordinates              # Create a 3d point for text
        mytext = gentities2.add_text "#{groupname}", tpoint  # Add a text label
        model.close_active                                   # Close mygroup2
      # Closed the Group
        
        UI.messagebox("mygroup2 added.  What's next?")       # User Message to see what happened!
        
      # Move everything in the model
        entlen = entities.length
        transform = Geom;;Transformation.new([(rl*2),0,0])
        
        for e in (0... entlen)
        entities.transform_entities(transform, entities[e])
        end
        
      # Select mygroup
        #selection.add(mygroup2)  
      
        UI.messagebox("All entities moved.  What's next?")         # User Message to see what happened!
          
      # Move (mygroup1) ONLY
      # Try making it as a proper transformation (TIG 30/04/2011)
        pt=Geom;;Point3d.new(rl*2, 0, 0)
        tr=Geom;;Transformation.new(pt)
        mygroup1.transform!(tr)
      
        UI.messagebox("mygroup1 moved by Point3d.  What's next?")  # User Message to see what happened!  
        
      # Move (mygroup2) ONLY
      # To move by a set vector use (TIG 30/04/2011)
        vt=Geom;;Vector3d.new(-rl*2, 0, 0)
        tr=Geom;;Transformation.translation(vt)
        mygroup2.transform!(tr)
      
        UI.messagebox("mygroup2 moved by Vector3d.  What's next?")  # User Message to see what happened!  
        
      # Rotate (mygroup1) along Red axis
        pt=Geom;;Point3d.new(0, 0, 0)
        vt=Geom;;Vector3d.new(rl, 0, 0)
        an=45.degrees
        tr=Geom;;Transformation.rotation(pt,vt,an)
        mygroup1.transform!(tr)
      
        UI.messagebox("mygroup1 rotated along Red axis.  What's next?")  # User Message to see what happened!  
      
      # Rotate (mygroup1) along Green axis
        pt=Geom;;Point3d.new(rl*6, 0, 0)
        vt=Geom;;Vector3d.new(0, gl, 0)
        an=45.degrees
        tr=Geom;;Transformation.rotation(pt,vt,-an)
        mygroup1.transform!(tr)
      
        UI.messagebox("mygroup1 rotated along Green axis.  What's next?")  # User Message to see what happened!  
      
      # Scale (mygroup2) uniform about origin x3
        tr=Geom;;Transformation.scaling(3)
        mygroup2.transform!(tr)
      
        UI.messagebox("mygroup2 scaled uniform from origin.  What's next?")  # User Message to see what happened!  
      
      # Scale (mygroup2) uniform about origin
        tr=Geom;;Transformation.scaling(0.3)
        mygroup2.transform!(tr)
      
        UI.messagebox("mygroup2 scaled uniform from origin.  What's next?")  # User Message to see what happened!  
      
      # Scale (mygroup2) non-uniform about origin
        tr=Geom;;Transformation.scaling(3, 2, 1.5)
        mygroup2.transform!(tr)
      
        UI.messagebox("mygroup2 scaled non-uniform from origin.  The End! ;o\)")  # User Message to see what happened!  
        
      # ---------- End Main Code ---------- 
        
      puts("\n   END \n..........")
      # end of SJH_Groups_Add.rb
      

      Attached is a pic of my moved, rotated and scaled Groups. Doesn't seem much but this morning that would have been a pic of a Bug Splat! Happy, happy! πŸ˜„


      Capture4-Rotate-Scale

      posted in Developers' Forum
      S
      SJH333
    • RE: How do I move a Group of entities on their own?

      Thanks Tig.
      I've got it to work with your suggestion:

      # Move (mygroup1) ONLY  
        tr = [(rl*2),0,0]            # Set transformation
        mygroup1.transform!(tr)      # Move mygroup1 (apply transformation)
       
      

      I was making it more difficult than it needed to be! πŸ˜‰
      I didn't need to touch the Groups Entities.

      Easy, when you know how! πŸ˜„
      Thanks again.

      Attached is the 'moved' (transform!)ed Group.


      Capture3-Working as required

      posted in Developers' Forum
      S
      SJH333
    • How do I move a Group of entities on their own?

      Please excuse my ignorance, this is all new to me!
      I'm having trouble moving a Group of entities on their own; if I move both my Groups (all entities) everything is OK, but if I move entities from only one Group, SU displays a crazy result.
      I'm really not too sure that I'm understanding, the entities = model.entities
      vs entities = model.active_entities idea, is this my problem?

      Any help would be appreciated. Thanks, Steve.

      I've attached two screen shots, one OK and one very obviously NOT OK!
      Here's my Code:

      # 30/04/2011 SJH_Groups_Add_v02.rb
      puts "Running... SJH_Groups_Add"
      
        require 'sketchup.rb'
      
        model = Sketchup.active_model
        entities = model.entities
        #entities = model.active_entities
        selection = model.selection
      
        # Set some length variables
        rl = 1
        gl = 1
        bl = 1
        
        rlmid = rl*0.5  
        glmid = gl*0.5
        blmid = bl*0.5
        
        # To convert to SU current Model units
        rl = rl.to_s.to_l
        gl = gl.to_s.to_l
        bl = bl.to_s.to_l
        
        rlmid = rlmid.to_s.to_l
        glmid = glmid.to_s.to_l
        blmid = blmid.to_s.to_l
        
        
        # Create Face points array
        fpts = []
        fpts[0] = [0, 0, 0]
        fpts[1] = [rl, 0, 0]
        fpts[2] = [rl, gl, 0]
        fpts[3] = [0, gl, 0]
        
        # Create String and counter for incrementing group names
        sjhname = "SJHGroup"
        groupcount = 0
      
      # ---------- Start Main Code ----------
      
        groupcount+= 1
        groupname = sjhname + groupcount.to_s
        
        
      # Create a Group - mygroup1
        mygroup1 = []                                        # Create an empty array to prevent Bug Splat!
        mygroup1 = entities.add_group                        # Make the array a Group Entities class
        gentities1 = mygroup1.entities                       # Create an array of the Entities in mygroup
        mygroup1.name = groupname                            # Change the Group name
        face = gentities1.add_face fpts                      # Add a face to gentities1
        pullface = face.pushpull -bl                         # Do a push/pull to the face
        tcoordinates = [rlmid, glmid, blmid]                 # Set coordinates for text
        tpoint = Geom;;Point3d.new tcoordinates              # Create a 3d point for text
        mytext = gentities1.add_text "#{groupname}", tpoint  # Add a text label
        model.close_active                                   # Close mygroup1
      # Closed the Group
        
        
      # Move everything in the model
        entlen = entities.length
        transform = Geom;;Transformation.new([(rl*2),0,0])
        
        for e in (0... entlen)
        entities.transform_entities(transform, entities[e])
        end
        
      # Select mygroup1
        #selection.add(mygroup1)  
      
      
        groupcount+= 1
        groupname = sjhname + groupcount.to_s
        
        
      # Create a Group - mygroup2
        mygroup2 = []                                        # Create an empty array to prevent Bug Splat!
        mygroup2 = entities.add_group                        # Make the array a Group Entities class
        gentities2 = mygroup2.entities                       # Create an array of the Entities in mygroup
        mygroup2.name = groupname                            # Change the Group name
        face = gentities2.add_face fpts                      # Add a face to gentities2
        pullface = face.pushpull -bl                         # Do a push/pull to the face
        tcoordinates = [rlmid, glmid, blmid]                 # Set coordinates for text
        tpoint = Geom;;Point3d.new tcoordinates              # Create a 3d point for text
        mytext = gentities2.add_text "#{groupname}", tpoint  # Add a text label
        model.close_active                                   # Close mygroup2
      # Closed the Group
        
        
      # Move everything in the model
        entlen = entities.length
        transform = Geom;;Transformation.new([(rl*2),0,0])
        
        for e in (0... entlen)
        entities.transform_entities(transform, entities[e])
        end
        
      # Select mygroup
        #selection.add(mygroup2)  
      
      
      # ---------- With this Code it goes crazy ----------
      # Move gentities1 (mygroup1) ONLY
        entlen = gentities1.length
        transform = Geom;;Transformation.new([(rl*2),0,0])
        
        for e in (0... entlen)
        entities.transform_entities(transform, gentities1[e])
        end
       
      # Question; How do I move a Group on it's own (using Ruby API Code)?  
      
      # ---------- End Main Code ----------
        
      puts("\n   END \n..........")
      # end of SJH_Groups_Add.rb
      

      Capture1-Moved-OK


      Capture2-Move_NOT_OK

      posted in Developers' Forum
      S
      SJH333
    • !!! Sketchup::GDL - Undocumented Class !!!

      I don't believe it!
      And neither should you!!!

      😍 !!! Happy April 1st !!! 😍

      posted in Newbie Forum sketchup
      S
      SJH333
    • 3.times{puts("Hello and Thank you!")}

      Hello all!
      The file I've attached is the result of my first few hours playing with the api.
      Most of it started as copy/pastes from the Google examples and bits from these forums.

      It includes credits and thanks to, Dan Rathbun, TIG, Chris Fullmer, thomthom, Jim, cjthompson and MartinRinehart, the posts mentioned in my .rb file really helped me get started, thanks guys.


      For Newbies like myself

      posted in Newbie Forum sketchup
      S
      SJH333
    • 1 / 1