Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help me find arc length????

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jinkinglee
1303 Views, 6 Replies

Help me find arc length????

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

6 REPLIES 6
Message 2 of 7
rkmcswain
in reply to: jinkinglee

The arc length = the radius * the delta angle (in radians).

For your example arc, the radius = 15.4022 and the delta is about 23° or .40 radians. So 15.4 * 0.4 = 6.1 (rounding is why it doesn't match your 6.046 exactly.)

Use the full precision when doing your calcs and then round the final answer, typically using (rtos).
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 7
Kent1Cooper
in reply to: jinkinglee


@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.

Kent Cooper, AIA
Message 4 of 7
Kent1Cooper
in reply to: rkmcswain


@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.

Kent Cooper, AIA
Message 5 of 7
Kent1Cooper
in reply to: Kent1Cooper


@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

Kent Cooper, AIA
Message 6 of 7
jinkinglee
in reply to: jinkinglee

Thank you guys so much. I figure out.

Message 7 of 7
Lee_Mac
in reply to: Kent1Cooper

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>)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost