### Author Topic: Arc Radius  (Read 252 times)

0 Members and 1 Guest are viewing this topic.

#### Fabricio28

• Swamp Rat
• Posts: 611
« on: August 03, 2017, 10:51:20 am »
Hi guys!

How are you friends?

I have a very hard task to insert points start and end of the arcs and radius value.
I'm doing that manually.

I was wondering if anyone could help me, please.

Fabricio

#### Master_Shake

• Swamp Rat
• Posts: 1256
##### Re: Arc Radius
« Reply #1 on: August 03, 2017, 11:02:06 am »
That's readily do-able. Let's break it down into sub-functions and build the routine.

First, you'll need to select an entity which contains a radius, in this case an arc.

My suggestion is Lee-Mac's select if routine

Code - Auto/Visual Lisp: [Select]
`(defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))  ;;---------------------=={ Select if }==----------------------;;;;                                                            ;;;;  Provides continuous selection prompts until either a      ;;;;  predicate function is validated or a keyword is supplied. ;;;;------------------------------------------------------------;;;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;;;------------------------------------------------------------;;;;  Arguments:                                                ;;;;  msg  - prompt string                                      ;;;;  pred - optional predicate function [selection list arg]   ;;;;  func - selection function to invoke                       ;;;;  keyw - optional initget argument list                     ;;;;------------------------------------------------------------;;;;  Returns:  Entity selection list, keyword, or nil          ;;;;------------------------------------------------------------;;   (while    (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))      (cond        ( (= 7 (getvar 'ERRNO))          (princ "\nMissed, Try again.")        )        ( (eq 'STR (type sel))          nil        )        ( (vl-consp sel)          (if (and pred (not (pred sel)))            (princ "\nInvalid Object Selected.")          )        )      )    )  )  sel)`

In order to call the sub-function, additional parameters must be passed. Lee's website includes the full command call.

Code - Auto/Visual Lisp: [Select]
` (LM:SelectIf "\nSelect an Arc: "	(lambda ( x ) (eq "ARC" (cdr (assoc 0 (entget (car x)))))) entsel nil)`

Next you need to obtain the radius, if you have access to VLISP it's a rather simple operation

Code - Auto/Visual Lisp: [Select]
`(setq rad (vla-get-radius obj)) ;obj being the entity returned by selectif`

To test that everything up until now works, create an alert window to display the radius of obj.

Code - Auto/Visual Lisp: [Select]
`(alert (strcat "Arc has a radius of " (rtos rad 2 4))`

#### ronjonp

• Needs a day job
• Posts: 6334
##### Re: Arc Radius
« Reply #2 on: August 03, 2017, 12:06:32 pm »
Here's a quickie

Code - Auto/Visual Lisp: [Select]
`(defun c:foo (/ _angle a ep h mp ss)  (defun _angle	(ename pt / clpt e param)    (if	(and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))	     (setq clpt (vlax-curve-getclosestpointto ename pt))	     (setq param (vlax-curve-getparamatpoint ename clpt))	)      (angle '(0 0) (vlax-curve-getfirstderiv ename param))      0.0    )  )  ;; Text height  (setq h 1)  (if (setq ss (ssget '((0 . "arc"))))    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))      (entmakex (list '(0 . "point") '(8 . "Point") (cons 10 (vlax-curve-getstartpoint x))))      (entmakex (list '(0 . "point") '(8 . "Point") (cons 10 (setq ep (vlax-curve-getendpoint x)))))      (setq mp (vlax-curve-getpointatdist x (* (vlax-curve-getdistatpoint x ep) 0.5)))      (setq mp (polar mp (+ (/ pi 2) (setq a (_angle x mp))) (* 0.75 h)))      (entmake (list '(0 . "TEXT")		     '(8 . "Text")		     ;; Insertionpoint		     (cons 10 mp)		     ;; Text height		     (cons 40 h)		     ;; Radius		     (cons 1 (strcat "R=" (vl-princ-to-string (cdr (assoc 40 (entget x)))) "m"))		     ;; Rotation		     (cons 50 a)		     '(72 . 1)		     ;; Alignment point		     (cons 11 mp)		     '(73 . 2)	       )      )    )  )  (princ))`
« Last Edit: August 03, 2017, 12:42:21 pm by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC

#### Fabricio28

• Swamp Rat
• Posts: 611
##### Re: Arc Radius
« Reply #3 on: August 03, 2017, 01:32:02 pm »
Here's a quickie

Code - Auto/Visual Lisp: [Select]
`(defun c:foo (/ _angle a ep h mp ss)  (defun _angle	(ename pt / clpt e param)    (if	(and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))	     (setq clpt (vlax-curve-getclosestpointto ename pt))	     (setq param (vlax-curve-getparamatpoint ename clpt))	)      (angle '(0 0) (vlax-curve-getfirstderiv ename param))      0.0    )  )  ;; Text height  (setq h 1)  (if (setq ss (ssget '((0 . "arc"))))    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))      (entmakex (list '(0 . "point") '(8 . "Point") (cons 10 (vlax-curve-getstartpoint x))))      (entmakex (list '(0 . "point") '(8 . "Point") (cons 10 (setq ep (vlax-curve-getendpoint x)))))      (setq mp (vlax-curve-getpointatdist x (* (vlax-curve-getdistatpoint x ep) 0.5)))      (setq mp (polar mp (+ (/ pi 2) (setq a (_angle x mp))) (* 0.75 h)))      (entmake (list '(0 . "TEXT")		     '(8 . "Text")		     ;; Insertionpoint		     (cons 10 mp)		     ;; Text height		     (cons 40 h)		     ;; Radius		     (cons 1 (strcat "R=" (vl-princ-to-string (cdr (assoc 40 (entget x)))) "m"))		     ;; Rotation		     (cons 50 a)		     '(72 . 1)		     ;; Alignment point		     (cons 11 mp)		     '(73 . 2)	       )      )    )  )  (princ))`

Thank you very much Ron.
Worked perfect your code.

Thanks
Fabricio

#### Fabricio28

• Swamp Rat
• Posts: 611
##### Re: Arc Radius
« Reply #4 on: August 03, 2017, 01:35:10 pm »
That's readily do-able. Let's break it down into sub-functions and build the routine.

First, you'll need to select an entity which contains a radius, in this case an arc.

My suggestion is Lee-Mac's select if routine

Code - Auto/Visual Lisp: [Select]
`(defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))  ;;---------------------=={ Select if }==----------------------;;;;                                                            ;;;;  Provides continuous selection prompts until either a      ;;;;  predicate function is validated or a keyword is supplied. ;;;;------------------------------------------------------------;;;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;;;------------------------------------------------------------;;;;  Arguments:                                                ;;;;  msg  - prompt string                                      ;;;;  pred - optional predicate function [selection list arg]   ;;;;  func - selection function to invoke                       ;;;;  keyw - optional initget argument list                     ;;;;------------------------------------------------------------;;;;  Returns:  Entity selection list, keyword, or nil          ;;;;------------------------------------------------------------;;   (while    (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))      (cond        ( (= 7 (getvar 'ERRNO))          (princ "\nMissed, Try again.")        )        ( (eq 'STR (type sel))          nil        )        ( (vl-consp sel)          (if (and pred (not (pred sel)))            (princ "\nInvalid Object Selected.")          )        )      )    )  )  sel)`

In order to call the sub-function, additional parameters must be passed. Lee's website includes the full command call.

Code - Auto/Visual Lisp: [Select]
` (LM:SelectIf "\nSelect an Arc: "	(lambda ( x ) (eq "ARC" (cdr (assoc 0 (entget (car x)))))) entsel nil)`

Next you need to obtain the radius, if you have access to VLISP it's a rather simple operation

Code - Auto/Visual Lisp: [Select]
`(setq rad (vla-get-radius obj)) ;obj being the entity returned by selectif`

To test that everything up until now works, create an alert window to display the radius of obj.

Code - Auto/Visual Lisp: [Select]
`(alert (strcat "Arc has a radius of " (rtos rad 2 4))`

I really appreciated your help my friend.
I'm just beginner with lisp. I'll study the code.

Fabricio

#### Master_Shake

• Swamp Rat
• Posts: 1256
##### Re: Arc Radius
« Reply #5 on: August 03, 2017, 01:37:19 pm »
Ron's is great, the way it's written you should be able to break down line by line on what's happening.

#### ronjonp

• Needs a day job
• Posts: 6334
##### Re: Arc Radius
« Reply #6 on: August 03, 2017, 02:32:20 pm »
Glad to help out

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC