• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Trying to set global axis from API

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 1.4k 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.
  • K Offline
    ktkoh
    last edited by 21 Sept 2017, 13:01

    xaxis = Geom;;Vector3d.new(3, 5, 0)
    yaxis = xaxis * Z_AXIS
    Sketchup.active_model.axes.set([10,0,0], xaxis, yaxis, Z_AXIS)
    

    when I use this API example I get the error message:
    undefined method ‘axes’ for #Sketchup::Model:0x9815c70

    What I am trying to accomplish is to draw a rectangle that is the outside extents of a face.
    Similar to a bounding box for the face except the bounding box aligns with the global axes and thus for some faces is 3 dimensional not single plane

    So I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 22 Sept 2017, 01:42

      @ktkoh said:

      xaxis = Geom;;Vector3d.new(3, 5, 0)
      > yaxis = xaxis * Z_AXIS
      > Sketchup.active_model.axes.set([10,0,0], xaxis, yaxis, Z_AXIS)
      

      when I use this API example I get the error message:
      undefined method ‘axes’ for #Sketchup::Model:0x9815c70

      The Sketchup::Model#axes() method and the Sketchup::Axes object class are only available with SketchUp version 2016 and higher.

      @ktkoh said:

      So I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default

      You can never actually change the global axes. The global origin and axes are always where they are. (They are referenced via global constants ORIGIN, X_AXIS, Y_AXIS, and Z_AXIS. **Do NOT attempt to reassign these constants!**You will only result in confusing other extensions and plugins.)

      The axes method and class changes the drawing axes, which is a temporary user axes that native tools honor, and plugins can honor IF they are written to specifically use the drawing axes. (Extension code will not use the custom drawing axes by default.)

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 22 Sept 2017, 09:17

        You need to approach the issue from the other direction...

        You want to end up with a group that includes a face, that has a bounding box which has its base on the face, thus setting the group's bounds z-axis equivalent to the face's normal.

        To achieve this you first make a group containing the face - potentially inclined and off axes.
        Make a combined transformation that moves the face, and anything else in the group, to the origin and rotated so that its normal is parallel to the z-axis.
        Immediately apply that transformation.inverse to the group.
        Now the face will look just the same, but its group's bounds are skewed to suit.
        You might also need to invalidate the group's definition's bounds to ensure the current bounding box displays properly.

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 26 Sept 2017, 20:26

          @ktkoh said:

          So I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default

          It occurs to me that you really want the maximum 2d extents of the face, and really it might best be done virtually rather than modifying the geometry of the model.

          Get the array of vertices in the face's outer loop.
          Iterate that array mapping the vertex positions to a new 2D array.
          (The first vertex should be put at coords 0,0. BTW, you can transform points if you have [or can get] the transformation of the original face. Ie, get the vector from the first vertex to the 2nd and use it to create a transformation for the face if you must.)
          Lastly, get the max X and Y value for the 2D box's height and width.

          Link Preview Image
          Module: Enumerable (Ruby 2.0.0)

          Module : Enumerable - Ruby 2.0.0

          favicon

          (ruby-doc.org)

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • K Offline
            ktkoh
            last edited by 26 Sept 2017, 23:35

            Thanks for the comments. This looks like a much more involved solution than my problem is worth. I think I will just stay with the requirement that component joint face needs to hahe 2 edges, common vertex and intersect at 90 degrees to work with my joint tool plugin. I was thinking of a plugin that would add a rectangular face on the existing face to be used for joint detail then deleted when finished. This worked for parts aligmed to the globel axis but not with rotated parts.

            Keith

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

            Advertisement