Jump to content

Recommended Posts

Posted

Question for all and special for Lee Mac: (think u use almost always this funcs).

 

I nedd module:

Grvecs ARC RUBBER LINE.

 

(defun GV-ARL (startpt secondpt)

???

)

 

(draw elastic line while waiting end point)

 

 

Same behavior like native arc function.

 

Thanks in front masters of Lisp.

Posted

(command "arc" startpt secondpt pause)

try something like this the pause will wait for user to pick the end point.

Posted

As John says, does this really need the use of grvecs...?

 

Bear in mind that the grvecs would need to be within a grRead loop to track the mouse movements - hence Osnaps/ortho are out (unless imitated), and you lose most other functionalities.

Posted

i have to agree, seems like a lot of work for something that can be achieved with the use of command.

i use this ALL the time for placing an arc b/w 2 points, then i can input the radius.

;arc by 2 selected endpoints, then entering or selecting radius
(defun c:AR ( / point_1 point_2 )
(if
 (and
  (setq point_1 (getpoint "\nPick 1st Point: "))
  (setq point_2 (getpoint point_1 "\nPick 2nd Point: "))
 );and
 (command "_.arc" "_non" point_1 "_e" "_non" point_2 "_r")
 (princ "\nMissed, try again.")
);if
(princ)
);defun

Posted

ye. command with pause.

Of course, i already know that, but i have abandoned command calls in

my subroutines few years ago.

I guess, this must remain.

Thanks.

Posted
ye. command with pause.

Of course, i already know that, but i have abandoned command calls in

my subroutines few years ago.

I guess, this must remain.

Thanks.

you don't have to use PAUSE, you just set the command as much as possible before issuing.

Posted

I’m just curious, could explain in more detail what you want.

Looks like you have a routine and you are passing it 2 augments (pt1 pt2)

Then you want the user to pick pt3.

Then what?

  • 3 weeks later...
Posted

This is my sub, and this is the form that i asked.

This work of course, but i don't like to use command calls.

Anyway, i suppose that use of grvecs and grread will be feeble solution.

 

thanks for time

 

;;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;; ARC RUBBER LINE (GETPOINT manner)                        
;; arg p1 p2 string > ret point or nil                      
;; (GETARCLASTPOINT (GETPOINT) (GETPOINT) "Specify end point of arc:")
;; (GETARCLASTPOINT (GETPOINT) (GETPOINT) NIL)                     
;;____________________________________________________________________
(DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *-nm *-ce *-pt)
  (SETQ *-ce (GETVAR "cmdecho")
        *-nm (GETVAR "nomutt")
  )
  (PROGN (SETVAR "cmdecho" 1) (SETVAR "nomutt" 0))
  (IF _msg`str
     (PROMPT (STRCAT "\n" _msg`str))
  )
  (PROGN (SETVAR "cmdecho" 0) (SETVAR "nomutt" 1))
  (IF (VL-CMDF (GETCNAME "_ARC") _pt1 _pt2 "\\")
     (PROGN (SETQ *-pt (GETVAR "LASTPOINT")) (ENTDEL (ENTLAST)))
  )
  (PROGN (SETVAR "cmdecho" *-ce) (SETVAR "nomutt" *-nm))
  *-pt
)

Posted

i removed a few of your 'progn' (not required), added an error handler to fix cmdecho, removed nomutt (didn't see any need for it) and the message prompt to display a default if nil.

 

(DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *error* *-ce _msg`str *-pt)
 (defun *error* (msg)
   (and *-ce (setvar "cmdecho" *-ce))
 ) ;_ defun
 (SETQ *-ce (GETVAR "cmdecho"))
 (SETVAR "cmdecho" 0)
 (or _msg`str (setq _msg`str (strcat "\nSpecify point: ")))
 (PROMPT (STRCAT "\n" _msg`str))
 (IF (VL-CMDF (GETCNAME "_ARC") _pt1 _pt2 "\\")
   (PROGN (SETQ *-pt (GETVAR "LASTPOINT")) (ENTDEL (ENTLAST)))
 ) ;_ IF
 (*error* nil)
 *-pt
) ;_ DEFUN

 

 

nothing wrong with yours, just offering a set of eyes.

Posted

Another set of eyes being offered:

 

(DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *error* *-ce _msg`str *-pt)
 
 (defun *error* (msg)
   (and *-ce (setvar "cmdecho" *-ce)))
 
 (SETQ *-ce (GETVAR "cmdecho"))
 (SETVAR "cmdecho" 0)
 (or _msg`str (setq _msg`str "Specify point: "))
 (PROMPT (strcat "\n" _msg`str))
 (and (VL-CMDF (GETCNAME "_ARC") _pt1 _pt2 pause)
      (SETQ *-pt (GETVAR "LASTPOINT"))
      (ENTDEL (ENTLAST)))
 (*error* nil)
 
 *-pt)

Posted

Hi,

 

If you really want to use grread to draw an arc by 3 points, you can inspire the following routine(s).

But I agree with Lee and Alan, command provides more options and overall osnaps.

 

;; Make3PointsArc (gile)
;; Entmakes an arc
;; Returns the arc ename
;;
;; Arguments
;; p1, p2, p3: points (UCS coordinates)

(defun Make3PointsArc (p1 p2 p3 / m1 m2 a1 a2 pi/2 cen Xang norm cen rad)
 (setq m1   (midPoint p1 p2)
       m2   (midPoint p2 p3)
       a1   (angle p1 p2)
       a2   (angle p2 p3)
       pi/2 (/ pi 2)
       norm (trans '(0. 0. 1.) 1 0 T)
       Xang (angle '(0. 0. 0.) (trans (getvar 'ucsxdir) 0 norm))
       cen  (inters m1 (polar m1 (+ a1 pi/2) 1.0) m2 (polar m2 (+ a2 pi/2) 1.0) nil)
       rad  (distance cen p1)
 )
 (if (clockwise-p p1 p2 p3)
   (setq start (angle cen p3)
         end   (angle cen p1)
   )
   (setq start (angle cen p1)
         end   (angle cen p3)
   )
 )
 (entmakex
   (list
     '(0 . "ARC")
     (cons 10 (trans cen 1 norm))
     (cons 40 rad)
     (cons 50 (+ Xang start))
     (cons 51 (+ Xang end))
     (cons 210 norm)
   )
 )
)

;; MidPoint (gile)
;; Returns the middle point between p1 and p2

(defun MidPoint (p1 p2)
 (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
)

;; Clockwise-p (gile)
;; evaluates if p1, p2, p3 are clockwise

(defun clockwise-p (p1 p2 p3)
 (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
)

;; STR2PT (gile)
;; Converts a string into a point (grread input)
;;
;; Argument: a string
;; Return: a 3d point or nil (if incorrect string)

(defun str2pt (str)
 (setq str (mapcar 'read (str2lst str ",")))
 (if (and (vl-every 'numberp str)
          (< 1 (length str) 4)
     )
   (trans str 0 0)
 )
)

;; STR2LST (gile)
;; Splits a string with separator into a list
;;
;; Arguments
;; str = string
;; sep = separator

(defun str2lst (str sep / pos)
 (if (setq pos (vl-string-search sep str))
   (cons (substr str 1 pos)
         (str2lst (substr str (+ (strlen sep) pos 1)) sep)
   )
   (list str)
 )
)

;; gr-3PointsArc (gile)
;; grread using to create an arc by 3 points
;;
;; Arguments
;; p1 p2: the 2 first points (UCS coordinates)

(defun gr-3PointsArc (p1 p2 / *error* loop gr p3 arc str)
 (defun *error* (msg)
   (or (= msg "Function cancelled")
       (princ (strcat "Error: " msg))
   )
   (and arc (entdel arc) (setq arc nil))
   (princ)
 )
 (setq loop T)
 (while (and (setq gr (grread T 12 0)) loop)
   (and arc (entdel arc) (setq arc nil))
   (cond
     ((= 5 (car gr))
      (setq p3 (cadr gr))
      (setq arc (Make3PointsArc p1 p2 p3))
     )
     ((= 3 (car gr))
      (setq arc  (Make3PointsArc p1 p2 p3)
            loop nil
      )
     )
     ((equal gr '(2 13))
      (cond
        ((and str (setq pt (str->pt str)))
         (setq arc (Make3PointsArc p1 p2 p3))
         (setq loop nil)
         (grtext)
        )
        (T
         (setq str nil)
         (princ
           "\nIncorrect point.\nSpecify the third point: "
         )
        )
      )
     )
     (T
      (if (= (cadr gr)  ;_ backspace
        (or
          (and str
               (/= str "")
               (setq str (substr str 1 (1- (strlen str))))
               (princ (chr )
               (princ (chr 32))
          )
          (setq str nil)
        )
        (or
          (and str (setq str (strcat str (chr (cadr gr)))))
          (setq str (chr (cadr gr)))
        )
      )
      (and str (princ (chr (cadr gr))))
     )
   )
 )
)

(defun c:test (/ p1 p2)
 (if (and
       (setq p1 (getpoint "\nSpecify the first point: "))
       (setq p2 (getpoint p1 "\nSpecify the second point: "))
       (not (equal p1 p2))
       (princ "\nSpecify the third point: ")
     )
   (gr-3PointsArc p1 p2)
 )
 (princ)
)

Posted

very nice gile!

 

btw, lee. !pause = "\\"

 

good catch on the 'and', but we both forgot to use osnap overrides:

(DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *error* *-ce _msg`str *-pt)
 
 (defun *error* (msg)
   (and *-ce (setvar "cmdecho" *-ce)))
 
 (SETQ *-ce (GETVAR "cmdecho"))
 (SETVAR "cmdecho" 0)
 (or _msg`str (setq _msg`str "\nSpecify point: "))
 (PROMPT (strcat "\n" _msg`str))
 (and (VL-CMDF "_.ARC" "_non" _pt1 "_non" _pt2 pause)
      (SETQ *-pt (GETVAR "LASTPOINT"))
      (ENTDEL (ENTLAST)))
 (*error* nil)
 
 *-pt)

i didn't notice it before, but i also replaced (GETCNAME "_ARC") with "_.ARC" since that's all you really need.

Posted

Very Nice Gile! :D

 

Thanks Alan, yeah, I kinda forgot about Snaps as well... oh well - looks like two sets of eyes are better than one.. :)

Posted
Very Nice Gile! :D

 

Thanks Alan, yeah, I kinda forgot about Snaps as well... oh well - looks like two sets of eyes are better than one.. :)

generally how it goes. :)

Posted

Being curious as I am... just had to dissect your method Gile... :P

 

Here is my diagram for others to benefit :)

 

ex.png

Posted

A slight twist on it:

 

;; Make3PointsArc (gile)
;; Entmakes an arc
;; Returns the arc ename
;;
;; Arguments
;; p1, p2, p3: points (UCS coordinates)

(defun Make3PointsArc (p1 p2 p3 / m1 m2 a1 a2 pi/2 cen Xang norm cen rad)
 (setq m1   (midPoint p1 p2)
       m2   (midPoint p2 p3)
       a1   (angle p1 p2)
       a2   (angle p2 p3)
       pi/2 (/ pi 2)
       norm (trans '(0. 0. 1.) 1 0 T)
       Xang (angle '(0. 0. 0.) (trans (getvar 'ucsxdir) 0 norm))
       cen  (inters m1 (polar m1 (+ a1 pi/2) 1.0) m2 (polar m2 (+ a2 pi/2) 1.0) nil)
       rad  (distance cen p1)
 )
 (if (clockwise-p p1 p2 p3)
   (setq start (angle cen p3)
         end   (angle cen p1)
   )
   (setq start (angle cen p1)
         end   (angle cen p3)
   )
 )
 (entmakex
   (list
     '(0 . "ARC")
     (cons 10 (trans cen 1 norm))
     (cons 40 rad)
     (cons 50 (+ Xang start))
     (cons 51 (+ Xang end))
     (cons 210 norm)
   )
 )
)

;; MidPoint (gile)
;; Returns the middle point between p1 and p2

(defun MidPoint (p1 p2)
 (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
)

;; Clockwise-p (gile)
;; evaluates if p1, p2, p3 are clockwise

(defun clockwise-p (p1 p2 p3)
 (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
)

;; STR2PT (gile)
;; Converts a string into a point (grread input)
;;
;; Argument: a string
;; Return: a 3d point or nil (if incorrect string)

(defun str2pt (str)
 (setq str (mapcar 'read (str2lst str ",")))
 (if (and (vl-every 'numberp str)
          (< 1 (length str) 4)
     )
   (trans str 0 0)
 )
)

;; STR2LST (gile)
;; Splits a string with separator into a list
;;
;; Arguments
;; str = string
;; sep = separator

(defun str2lst (str sep / pos)
 (if (setq pos (vl-string-search sep str))
   (cons (substr str 1 pos)
         (str2lst (substr str (+ (strlen sep) pos 1)) sep)
   )
   (list str)
 )
)

;; gr-3PointsArc (gile)
;; grread using to create an arc by 3 points
;;
;; Arguments
;; p1 p2: the 2 first points (UCS coordinates)

(defun gr-3PointsArc (p1 p3 / *error* loop gr p3 arc str)
 (defun *error* (msg)
   (or (= msg "Function cancelled")
       (princ (strcat "Error: " msg))
   )
   (and arc (entdel arc) (setq arc nil))
   (princ)
 )
 (setq loop T)
 (while (and (setq gr (grread T 12 0)) loop)
   (and arc (entdel arc) (setq arc nil))
   (cond
     ((= 5 (car gr))
      (setq p2 (cadr gr))
      (setq arc (Make3PointsArc p1 p2 p3))
     )
     ((= 3 (car gr))
      (setq arc  (Make3PointsArc p1 p2 p3)
            loop nil
      )
     )
     ((equal gr '(2 13))
      (cond
        ((and str (setq pt (str->pt str)))
         (setq arc (Make3PointsArc p1 p2 p3))
         (setq loop nil)
         (grtext)
        )
        (T
         (setq str nil)
         (princ
           "\nIncorrect point.\nSpecify the third point: "
         )
        )
      )
     )
     (T
      (if (= (cadr gr)  ;_ backspace
        (or
          (and str
               (/= str "")
               (setq str (substr str 1 (1- (strlen str))))
               (princ (chr )
               (princ (chr 32))
          )
          (setq str nil)
        )
        (or
          (and str (setq str (strcat str (chr (cadr gr)))))
          (setq str (chr (cadr gr)))
        )
      )
      (and str (princ (chr (cadr gr))))
     )
   )
 )
)

(defun c:test (/ p1 p3)
 (if (and
       (setq p1 (getpoint "\nSpecify the first point: "))
       (setq p3 (getpoint p1 "\nSpecify the second point: "))
       (not (equal p1 p3))
       (princ "\nSpecify the third point: ")
     )
   (gr-3PointsArc p1 p3)
 )
 (princ)
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...