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

    Def help!

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 219 Views 4 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.
    • T Offline
      tomot
      last edited by

      The following definition statement has been an invaluable time saver for me
      when I scripted my WindowTools and DoorTools rubies. Its never to late to thank Didier for writing it a long time ago, when I found it in one of his scripts.

      # creates a new point from p1 in the direction of p2-p3 with length d
      # params are Point3d, 2 vertices, a length, returns a Point3d
          def translate(p1, p2, p3, d)
              v = p3 - p2
              v.length = d
              trans=Geom;;Transformation.translation(v)
              return p1.transform(trans)
          end   
      

      I'm wondering if its possible to someone here to help construct a similar time saver definition for the following statements, I lack some fundamental ruby programming skills to create such a definition.

      #------Computer new point pt11, $width (6") and at the same angle plus 90 degrees from pt1
          vec = @ip2.position - $pt1
          ang = 1.5707963267948965
          vec.length = $width # $width of wall (6")
          translate = Geom;;Transformation.translation(vec)
          rotate = Geom;;Transformation.rotation( $pt1, Geom;;Vector3d.new(0, 1, 0), ang)
          trans = $pt1.transform(translate)
          $pt11 = trans.transform(rotate)
      

      It seems like a lot of work to go on repeating this code snippet 20 more times to find 20 additional points.
      BTW: It should be observed that the same scripted in the AutoLisp for AutoCad involved the following single statement:

      (setq pt3 (polar pt1 (+ ang (dtr 90)) 6))
      

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

      1 Reply Last reply Reply Quote 0
      • K Offline
        kyyu
        last edited by

        Try this:

        def method_name(pt1, pt2, width)
            vec = pt2 - pt1
            ang = 90.degrees
            rotate = Geom;;Transformation.rotation( pt1, Geom;;Vector3d.new(0, 1, 0), ang)
            vec = vec.transform(rotate)
            pt11 = pt1.offset(vec, width)
        end
        
        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          What will be the name of the this method?

          I'm not here much anymore.

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

            I think if you explained in 'words' not pseudo-code what you want to do then suggestions would be more forthcoming...
            Kyyu's suggested method takes arguments of two points and a 'width'; it gets the vector between the points, it then transforms the vector by rotating about the Y_AXIS by 90 degrees, and then moving a clone of the first point along the adjusted vector by 'width'. This new point is returned by the method. This seems a very specific 'tool' and could be made far more general - e.g. by passing an angle too...
            What is it you want these methods to 'do' for you ? ... πŸ˜•

            TIG

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomot
              last edited by

              @tig said:

              I think if you explained in 'words' not pseudo-code what you want to do then suggestions would be more forthcoming...
              Kyyu's suggested method takes arguments of two points and a 'width'; it gets the vector between the points, it then transforms the vector by rotating about the Y_AXIS by 90 degrees, and then moving a clone of the first point along the adjusted vector by 'width'. This new point is returned by the method. This seems a very specific 'tool' and could be made far more general - e.g. by passing an angle too...
              What is it you want these methods to 'do' for you ? ... πŸ˜•

              Thanks for your comments: Your description precisely describes what this method is supposed to do. Its not really all that specific. As I commented above its the typical way an Autolisp routine works, when one is defining points one after the other. In Autolisp Its called polar - derive point from angle and distance function, without it you would not be able to do 80 percent of the stuff involving angles. Sadly the Ruby API dose not include robust code dealing with angles, or arcs. 😞

              [my plugins](http://thingsvirtual.blogspot.ca/)
              tomot

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomot
                last edited by

                @kyyu said:

                Try this:

                thanks I will give it a try!

                [my plugins](http://thingsvirtual.blogspot.ca/)
                tomot

                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