lisp routine to label arc length, arc radius and total arc angle

lisp routine to label arc length, arc radius and total arc angle

ale
Participant Participant
7,816 Views
19 Replies
Message 1 of 20

lisp routine to label arc length, arc radius and total arc angle

ale
Participant
Participant

Hello everybody in the forum.
I am in need of a lisp routine to label arc length, arc radius and total arc angle. attached dwg.
Thank you.

0 Likes
Accepted solutions (2)
7,817 Views
19 Replies
Replies (19)
Message 2 of 20

doaiena
Collaborator
Collaborator
Accepted solution

You may need to tweak some things like text style, unit type and precision, but this will basically get you started.

(defun c:test ( / ss acadModel precision ctr obj len rad ang txt txtObj)
  
(if (setq ss (ssget '((0 . "ARC"))))
(progn

(setq acadModel (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq precision 2)

(setq ctr 0)
(repeat (sslength ss)

(setq obj (vlax-ename->vla-object (ssname ss ctr)))
(setq len (rtos (vla-get-arcLength obj) 2 precision))
(setq rad (rtos (vla-get-radius obj) 2 precision))
(setq ang (rtos (cvunit (vla-get-totalAngle obj) "radians" "degrees") 2 precision))

(setq txt (strcat "L=" len " R=" rad " A=" ang))
(setq txtObj (vla-addtext acadModel txt (vla-get-center obj) 1))
(vla-put-alignment txtObj acAlignmentMiddleCenter)
(vla-put-textAlignmentPoint txtObj (vla-get-center obj))
);repeat

));if ss
(princ)
);defun
0 Likes
Message 3 of 20

john.uhden
Mentor
Mentor

You have reminded me of my very ambitious LABEL_IT program written primarily for Softdesk and Land Desktop.  You could pick arcs, lines, and polyline segments even if nested in a block or xref and create labels and tables in many different formats selected from a dialog. Included bearing and distance, radius, delta, length, tangent, and chord, and from/to coordinates.

At some point point I should will all my crap to someone who cares.

John F. Uhden

Message 4 of 20

ale
Participant
Participant

muchas gracias, por la pronta respuesta, solo que yo no se de lisp, y para la parte del angulo como lo cambio para que me aparesca como grados minuts y segundos.
Gracias

0 Likes
Message 5 of 20

ale
Participant
Participant

thank you very much, for the quick response, only that I do not know lisp, and for the part of the angle as I change it so that it appears to me like degrees minutes and seconds.
Thank you.

0 Likes
Message 6 of 20

john.uhden
Mentor
Mentor
Accepted solution
(setq ang (vl-string-subst (chr 176) "d" (angtos (vla-get-totalAngle obj) 1 4)))

John F. Uhden

0 Likes
Message 7 of 20

ale
Participant
Participant

thank you very much john.uhden the code line worked very well.

0 Likes
Message 8 of 20

barry2104
Collaborator
Collaborator

can this Lisp be Extended to have the L/R/A Output sit within a (curved) Dimension-entity rather than be Output as simple text at the centre of the arc?

 

 

Here is a Lisp I already have for doing just this, but it just needs to be expanded to include the arc angle-Change within the Dimension entity

Thanks in advance!

 

;;  DimArcLengthRad.LSP [command name: DIMALR]
;;  Dimension an Arc or Polyline arc segment for its Length along the curve and its Radius
;;  Kent Cooper, 26 October 2015

(vl-load-com)

(defun C:DIMALR ; = DIMension Arc Length & Radius
  (/ *error* cmde arcsel arctype plctr picknear pickpar arcobj arclrtext)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); end if
    (setvar 'cmdecho cmde)
    (vla-endundomark doc)
    (princ)
  ); end defun - *error*

  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (setq cmde (getvar 'cmdecho))
  (while
    (not
      (and
        (setq arcsel
          (entsel "\nSelect Arc or Polyline arc segment for Length/Radius Dimension: ")
        ); setq
        (setq arctype (cdr (assoc 0 (entget (car arcsel)))))
        (or
          (= arctype "ARC")
          (and
            (wcmatch arctype "*POLYLINE")
            (setq plctr (osnap (cadr arcsel) "_center")); picked on arc segment
          ); and
        ); or
      ); end and
    ); end not
    (prompt "\nNothing selected, or not an Arc or Polyline arc segment -- ")
  ); end while
  (if (wcmatch arctype "*POLYLINE")
    (setq
      picknea (osnap (cadr arcsel) "_nearest")
      pickpar (vlax-curve-getParamAtPoint (car arcsel) picknea)
    ); setq
  ); if
  (setq
    arcobj (vlax-ename->vla-object (car arcsel))
    arclrtext
      (strcat
;; for comma as decimal separator, remove initial semicolons from 4 lines below:
;        (vl-string-subst "," "."
        (rtos
          (if (= arctype "ARC")
            (vla-get-ArcLength arcobj); then
            (- ; else
              (vlax-curve-getDistAtParam arcobj (1+ (fix pickpar)))
              (vlax-curve-getDistAtParam arcobj (fix pickpar))
            ); -
          ); if
          2 1 ;; <-- EDIT mode/precision as desired
        ); rtos
;        ); vl-string-subst
        " (R = "
;        (vl-string-subst "," "."
        (rtos
          (if (= arctype "ARC")
            (vla-get-Radius arcobj); then
            (distance plctr picknea); else
          ); if
          2 1 ;; <-- EDIT mode/precision as desired
        ); rtos
;        ); vl-string-subst
        ")"
      ); strcat & arclrtext
  ); end setq

  (setvar 'cmdecho 0)
  (command "_.dimangular"); leave in Dimangular command
  (if (= arctype "ARC")
    (command arcsel); then
    (command ; else
      "" plctr ; specify-vertex option
      (vlax-curve-getPointAtParam arcobj (fix pickpar))
      (vlax-curve-getPointAtParam arcobj (1+ (fix pickpar)))
    ); command
  ); if
  (command "_text" arclrtext pause); finish Dimension
  (setvar 'cmdecho cmde)

  (vla-endundomark doc)
  (princ)
); defun -- DIMALR

(prompt "\nType DIMALR to DIMension an Arc or Polyline arc segment with its Length & Radius.")

 

 

Running AutoCAD Architecture 2020, in German
0 Likes
Message 9 of 20

Kent1Cooper
Consultant
Consultant

@barry2104 wrote:

can this Lisp be Extended to have the L/R/A Output sit within a (curved) Dimension-entity rather than be Output as simple text at the centre of the arc? 

Here is a Lisp I already have for doing just this, but it just needs to be expanded to include the arc angle-Change within the Dimension entity

.... 


 

Here's a modification [to add the included Angle] of a modification of that [a later version, that doesn't construct the text content as a variable beforehand, but within  the Text-option input in the DIMANGULAR command] -- DimArcLengthRadAngle.lsp with its DIMALRA command.  Lightly tested.

Kent Cooper, AIA
Message 10 of 20

john.uhden
Mentor
Mentor
If I didn't sell it to Rex Cooper (SmartDraft), then maybe I can give you a
copy of my LABEL_IT to try out. I need to check when at home, but I think
it does what you want, even if the arcs are polyline segments and even if
they are embedded in a block or xref.

John F. Uhden

0 Likes
Message 11 of 20

john.uhden
Mentor
Mentor

I did not sell Rex Cooper LABEL_IT, so I can do anything I want with it.

I checked and it does draw the radius and length as arced text (my own emulation), but the delta, tangent, and chord options are available only with a leader or with tags and a table  I do not think I would rewrite it.  At 278 Kb (excluding the DCL) it's the largest program I've ever written.

LABEL_IT.jpg

John F. Uhden

Message 12 of 20

barry2104
Collaborator
Collaborator

Hi,

the Lisp from Kent Cooper is just what I was after.

The program we use to model the 3d lines unfortunately spits out the result as a multi-Point, straight-segmented polyline rather than with arcs to get around the curves. So a new Problem/request has now arisen...

Ideally there is /can be a Lisp that I can type "TANGLE" (Total Angle, perhaps similarly coded to the well known TLEN (Total Length) Lisp), select the polyline in question, and get a resulting window/output showing me:

  1. how many nodes the selected polyline has
  2. length of the polyline
  3. the total sum of all node-angle-changes

(I am Aware that the above Points 1 and 2 are easily seen in the properties of the polyline itself, but this should be easy to build into the code and would be a good "sanity check" to double check the selected line is in fact the length you were expecting)

 

Doable?

Running AutoCAD Architecture 2020, in German
0 Likes
Message 13 of 20

Kent1Cooper
Consultant
Consultant

@barry2104 wrote:

... a multi-Point, straight-segmented polyline rather than with arcs to get around the curves. So a new Problem/request has now arisen....  the total sum of all node-angle-changes ….


 

That could be a challenge.  Consider a very simple case -- one quadrant of a regular octagon.  Two segments, sweeping through what you would consider 90 degrees relative to the center of the octagon, but there's only one angle change, of only 45 degrees.  I'm trying to imagine how to have a routine figure out where the "center" is and therefrom the angles to the ends -- maybe the intersection of virtual line bisectors or something....

 

Are your segmented Polylines always regular, i.e. are all their segments in a given "arc"-equivalent stretch the same length, with the same bend angle  between each?  It might be possible to work something out if they are.  But maybe only if such an "arc" equivalent is isolated from other things, not part of a longer Polyline that extends beyond that portion.

Kent Cooper, AIA
0 Likes
Message 14 of 20

barry2104
Collaborator
Collaborator

The polyline Output I deal with is in no way regular (irregular angle changes and irregular Segment lengths).

Your example of a "quadrant of a regular octagon" can be one of two scenarios… blue or red. The nodes of the polyline making up the octagon are numbered below.

Blue has 2x45° bends in the clouded Quadrant, so the Output should read simply 90° angle Change

Red has only 1x45° bend in the clouded quandrant.

(The below examples are a closed shape, which my polylines will never be... so the transparent numbers/nodes/segments you can pretend don't exist for the purpose of this exercise)

cad.JPG

Running AutoCAD Architecture 2020, in German
0 Likes
Message 15 of 20

Kent1Cooper
Consultant
Consultant

@barry2104 wrote:

... a "quadrant of a regular octagon" can be one of two scenarios… blue or red. ....


 

I was picturing the red, as being more likely what your scenario in Message 12 would be like [though yours would presumably be many more segments] -- that is, between the outer ends of end-most segments, not between midpoints of segments.

 

Your black lines between which the 90 degrees is measured in your red octagon are bisectors of the angles, which means that "sweep" across those two segments would not  be 90 degrees if those adjacent segments [3-4 and 1-8] headed in different directions than they do.  That kind of thing is what makes it hard to picture how a routine could deal with an "arc-equivalent" segmented Polyline if it can't be counted on to be regular about it.

 

But if you're only after an overall  end-to-end change in angle, maybe it's not necessary to calculate bend angles and add them up [or subtract some if they bend the other way].  Could it just take the angle difference between perpendiculars from the end segments, as in your blue octagon?

TotalBend.PNG

Or the same directly between the end segments?

TotalBend2.PNG

Kent Cooper, AIA
0 Likes
Message 16 of 20

barry2104
Collaborator
Collaborator

The output should ideally provide only the absolute sum of all angle changes (e.g. clockwise and anticlockwise added together) and not the differential angle change where clockwise is considered + and anticlockwise –

e.g. with the following example of a polyline with 11 subsegments, the output should read:

Total Angle Change = 650.4°

(650.4° is the sum of 56.7+54.3+39.1+26.6+64.0+63+105.7+140.8+100.2)

 

To be able to fly through to make sure no bend is larger than a certain amount, listing each node-angle-Change similar to the 2nd bold row of the output above would also be helpful, but not completely necessary.

cad.JPG

Running AutoCAD Architecture 2020, in German
0 Likes
Message 17 of 20

john.uhden
Mentor
Mentor
BTW, positive deflections are CCW and negative ones are CW.
If your polyline zigzags, the sum can look more like 30+20-40+15-10.

John F. Uhden

0 Likes
Message 18 of 20

Kent1Cooper
Consultant
Consultant

@barry2104 wrote:

The output should ideally provide only the absolute sum of all angle changes (e.g. clockwise and anticlockwise added together) and not the differential angle change where clockwise is considered + and anticlockwise – ....


 

Without the second feature listing the individual bends [yet], and assuming, as you describe, an open-ended Polyline made of straight segments only, try this:

(defun C:TANGLE (/ pl asum par a1 a2 adif); = Total ANGLE change [bends]
  (setq pl (car (entsel)) asum 0 par 0)
  (repeat (1- (fix (vlax-curve-getEndParam pl)))
    (setq
      a1
        (angle
          (vlax-curve-getPointAtParam pl par)
          (vlax-curve-getPointAtParam pl (setq par (1+ par)))
        ); angle
      a2
        (angle
          (vlax-curve-getPointAtParam pl par)
          (vlax-curve-getPointAtParam pl (setq par (1+ par)))
        ); angle
      adif (abs (- a1 a2))
      asum
        (+ asum
          (if (< adif pi) adif (- (* pi 2) adif))
        ); + & asum
    ); setq
    (setq par (1- par)); back up one for next bend
  ); repeat
  (prompt
    (strcat
      "\nNumber of vertices = " (itoa (1+ (fix (vlax-curve-getEndParam pl)))) "."
      "\nLength = " (rtos (vlax-curve-getDistAtPoint pl (vlax-curve-getEndPoint pl))) "."
      "\nTotal Angle Change = " (rtos (/ (* asum 180) pi) 2 1) " degrees."
    ); strcat
  ); prompt
  (princ)
); defun

[Interestingly, I first tried using (angtos) for the total angle change report, so it would report in whatever your current angular units setting is.  But that lops off excess beyond a full circle, i.e. a total of 360 becomes 0, etc.  So I took it back to a calculated decimal number of degrees.  If you want it reported in degrees/minutes/seconds, though I think it would be possible, some shenanigans would be required.]

 

Kent Cooper, AIA
Message 19 of 20

barry2104
Collaborator
Collaborator

that is exactly what i was after!

Thank you muchly for your speedy input

Running AutoCAD Architecture 2020, in German
0 Likes
Message 20 of 20

hiraram_prajapati
Contributor
Contributor

Hi Dear @Kent1Cooper @john.uhden 

Please sent me lisp, I Want to insert angles (DD.MM.SS) on polyline. snap is attached for your reference, 

Thanks you.

NEED.jpg

0 Likes