When I write "CoatMuller.lsp" this comes out below in lisp:
(COMMAND "ARC" O41 S631 U)
(setq Arc_1 (entlast))
(setq eget (entget Arc_1))
(setq arc_len (cdr (assoc 40 eget)))
(COMMAND "TEXT" (polar U (dtr 0.0) 0.75) 0.25 75.0
(strcat "ARC_LENGTH = " (rtos arc_len))
)
This is what comes out in autocad: I need arc length, not radius (see below) --> I need length to show, but instead radius is shown
Command: list
Select objects: 1 found
Select objects: ARC Layer: "BODY"
Space: Model space
Handle = 86
center point, X= -3.8967 Y= -9.5281 Z= 0.0000
radius 15.4022
start angle 147
end angle 170
length 6.0463
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@jinkinglee wrote:
....
(COMMAND "ARC" O41 S631 U)
(setq Arc_1 (entlast))
(setq eget (entget Arc_1))
(setq arc_len (cdr (assoc 40 eget)))....
This is what comes out in autocad: I need arc length, not radius (see below) --> I need length to show, but instead radius is shown
Command: list
....
radius 15.4022
....length 6.0463
This line would be causing that:
(setq arc_len (cdr (assoc 40 eget)))
The 40 there is associated with the radius of the Arc. There is nothing in the entity data that stores the length, which is only a result of other properties. It can be calculated from the relationship between the start angle (assoc 50), end angle (assoc 51) and radius (assoc 40). That's a little complicated, but you can get it in a different way, without using the entity data list. Replace the above line with:
(setq arc_len (vlax-curve-getDistAtPoint Arc_1 (vlax-curve-getEndPoint Arc_1)))
For that, you would need to add this line:
(vl-load-com)
somewhere in your .lsp file [such as at the beginning or end]. And you may not need the eget variable at all any more, if you do it that way.
@rkmcswain wrote:
The arc length = the radius * the delta angle (in radians).
....
The reason I suggested the (vlax-curve-getDist... approach is that the sweep of the Arc [the "delta angle"] in radians is not always simply a matter of subtracting the start angle (assoc 50) in the entity data from the end angle (assoc 51), for a number to multiply by the radius (assoc 40). Much of the time that will work fine, but if the Arc crosses the zero-degree direction, that will give the wrong result. Compensating for that possibility is certainly doable, but more complicated than just getting the distance along the Arc at its end.
@Kent1Cooper wrote:
.... There is nothing in the entity data that stores the length, which is only a result of other properties. It can be calculated from the relationship between the start angle (assoc 50), end angle (assoc 51) and radius (assoc 40). That's a little complicated, ....
Just to demonstrate, here's one way to do it with entity data [after the eget variable has been set]:
(setq
startang (cdr (assoc 50 eget))
endang (cdr (assoc 51 eget))
arc_len
(*
(if (< startang endang); does not cross zero-degree direction?
(- endang startang); then -- simple subtraction
(+ (- (* pi 2) startang) endang); else -- compensation
); if
(cdr (assoc 40 eget)); radius
); end * & arc_len
); setq
Here's another way to write it without the conditional:
(defun arclen ( ent / enx ) (setq enx (entget ent)) (* (cdr (assoc 40 enx)) (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi) ) ) )
Usage:
(arclen <arc-entity>)