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

    Rotating faces to create a u-shape

    Scheduled Pinned Locked Moved Newbie Forum
    1 Posts 1 Posters 0 Views 1 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.
    • J Offline
      j_jones
      last edited by

      Hello again, I am just learning the Ruby API and am back with another simpler question.

      My goal is to draw a face in an arbitrary point in space (not at the origin). Then I want to copy the face and rotate it 90 degrees to create a corner shape. Then copy the second face and rotate it 90 degrees to create a u-shape

      This is the code I came up with to do this, however, I'm running into a problem in that I can't seem to access the points of the rotated face. The positions of the points are identical the ones in the original face for some reason.

      Here is the script.

      By the way, I must be doing something really weird because when I run this script in
      Ruby Console Plus, it freezes and then goes blank. I haven't had any trouble with the
      console until I ran this script!

      
      
      model = Sketcup.active_model
      active_entities = model.active_entities
      
      # draw first face
      
      #     p3         p2 
      #      +---------+
      #      |         |
      #      |         |
      #      |         |
      #      |         |
      #      +---------+
      #     p0         p1
      
      model.start_operation("first face",true,false,true)
      
      pts = [[10,10,0], [20,10,0], [20,10,10], [10,10,10]]
      pt0, pt1, pt2, pt3 = pts
      group1 = active_entities.add_group
      g1_entities = group1.entities
      face1 = g1_entities.add_face(pts)
      
      # print out the vertexes of the first face
      puts("first group")
      group1.entities.each do |thing|
         if thing.is_a?(Sketchup;;Edge)
           puts "#{thing.start.position} #{thing.end.position}"
         end
      end
      
      # end of first face
      model.commit_operation
      
      
      

      So far so good, here is the face, ready to go

      first face

      Now on to the second face

      
      
      model.start_operation("second face",true,false,true)
      
      # make a copy of the first face
      # then rotate it to create a corner shape
      
      #            pt0 
      #             +---------+
      #            /|         |
      #           / |         |
      #          /  |         |
      #         +   |         |
      #         |   +---------+
      #         |  /pt3
      #         | /
      #         |/
      #         +  
      
      group2 = group1.copy
      g2_entities = group2.entities
      
      axis = pt0.vector_to(pt3)
      angle = -90.degrees
      xform = Geom;;Transformation.rotation(pt0, axis, angle)
      group2.transform!(xform)
      
      # notice that the points of the group2 face have not been rotated
      #   they still reflect the points of the first face
      puts("second group")
      group2.entities.each do |thing|
         puts thing
         if thing.is_a?(Sketchup;;Edge)
           puts "#{thing.start.position} #{thing.end.position}"
         end
      end
      # end of second face
      
      model.commit_operation
      
      
      

      Second face rotated, looks good except if I query the second face for the
      positions of its vertices, it just reports the same positions as the first face

      second face

      BTW, at this point Ruby Console Plus tends to freeze and then ultimately goes blank and has to be restarted. I have no idea why.

      At this point I would like to rotate the second face to create a u-shape, but
      I don't know what points to pick because the points given don't reflect the rotation

      
      
      model.start_operation("third face",true,false,true)
      
      # make a copy of the second face
      # then rotate it to create a u-shape
      group3 = group2.copy
      g3_entities = group3.entities
      
      #         goal 
      #             +---------+
      #            /|         |
      #           / |         |
      #          /  |         |
      #         +---------+   |
      #         |   +-----|---+
      #         |  /      |
      #         | /       |
      #         |/        |
      #         +---------+  
      
      # at this point I don't really know which points to choose to create
      # the axis for rotating the third face as I don't seem to be able
      # to access the rotated shape's actual points?
      
      puts("third group")
      group3.entities.each do |thing|
         puts thing
         if thing.is_a?(Sketchup;;Edge)
           puts "#{thing.start.position} #{thing.end.position}"
         end
      end
      # end of third face
      
      # model.commit_operation
      
      
      

      Thanks for any clues
      j_jones

      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