• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Rotate face in ruby

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 428 Views
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.
  • I Offline
    ipomea
    last edited by 16 Jan 2014, 09:36

    Hello !

    I am a beginner with ruby, and I want to rotate a face, and retrieve the new face
    I have the following code:

    ` model = Sketchup.active_model # Open model
    entities = model.entities # All entities in model
    selection = model.selection # Current selection

    pt1 = [x,y,0]
    pt2 = [x1,y1,0]
    pt3 = [x1,y1,h]
    pt4 = [x,y,h]
    fc = entities.add_face pt1,pt2,pt3,pt4,pt1

    tr = Geom::Transformation.rotation ptm,vector,angle
    bas1 = entities.transform_entities(tr,fc)`

    this returns a status, what I want is the face after rotation. If I try anithing else, I always end up with an error

    Is the rotated face still fc or is it an other one and how can I find the new one ?

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 16 Jan 2014, 14:56

      You didn't show us how you get/set
      ptm,vector,angle
      but let's assume they are setup properly, because you'd get worse errors otherwise ๐Ÿ˜’

      The face ' fc' should remain a reference to the face even after it's transformed: however, it it lands on top of or overlapping another pre-existing face you might loose the reference, or find it refers to an unexpected face...
      If you are doing the transformations of a limited number of faces within a container context [ some_group.entities etc] then you have more control of what's there already, compared with the model.entities...
      If you want real comfort consider adding a temp-group and putting your new face inside that:
      **gp = entities.add_group()** fc = **gp.**entities.add_face(pt1,pt2,pt3,pt4)
      [Note: there's no need to repeat pt1 at the end - unlike with ' add_edges()' if you want all 4 edges created]
      Then you can transform the temp-group with ' gp.transform!(tr)'... OR transform the entities inside the temp-group:
      gp.entities.transform_entities(tr, gp.entities.to_a)
      Although, because the temp-group is unlikely to share the same ORIGIN, you would then need to consider the point about which you are rotating [ ptm], relatively to the gp.transformation.origin - Hint: after the face is created inside gp use ptm.offset!(gp.transformation.origin.vector_to(ptm))... THEN define the tr transformation using the corrected ptm
      At this point ' fc' is still the same face, because it cannot have interacted with other geometry...
      After doing whatever it is you are doing ๐Ÿ˜• explode the temp-group gp.explode ...

      TIG

      1 Reply Last reply Reply Quote 0
      • I Offline
        ipomea
        last edited by 16 Jan 2014, 17:33

        Thank you very much. This has really been helpful. It was OK the first time I tried

        This is the end result:

        moebius.jpg

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement