Providing radial dimensions for multiple arcs in a polyline

Providing radial dimensions for multiple arcs in a polyline

javeed4teen
Participant Participant
397 Views
6 Replies
Message 1 of 7

Providing radial dimensions for multiple arcs in a polyline

javeed4teen
Participant
Participant

Hello Everyone,

Is it possible to automate the creation of radial dimensions for multiple arcs or polylines that contain arc segments? I’m looking for a way to apply radial dimensions efficiently across a number of such elements, ideally in a batch or automated way.

 

Any suggestions will be greatly appreciated.

 

Thanks.

javeed4teen_0-1750741486543.png

 

0 Likes
Accepted solutions (3)
398 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

Not as simple as I was hoping... You might want to adjust the size of dims according to your unit range...

 

(vl-load-com)

(defun c:DimArcs ( / s i o e j ll ur p)
  
  (if (setq s (ssget '((0 . "LWPOLYLINE,ARC"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (setq o (vlax-ename->vla-object e))
      (setq j -0.5)
      (if (= "AcDbArc" (vla-get-objectname o))
	(command "_.dimradius" (list e (trans (vlax-curve-getpointatdist o (/ (vlax-curve-getdistatpoint o (vlax-curve-getendpoint o)) 2)) 0 1)) "_non" "@-2,-2")
	(repeat (fix (vlax-curve-getendparam o))
	  (if (/= 0 (vla-getbulge o (fix (setq j (1+ j)))))
	    (progn
	      (setq p (list (trans (vlax-curve-getpointatparam o (fix j)) 0 1)
			     (trans (vlax-curve-getpointatparam o j) 0 1)
			     (trans (vlax-curve-getpointatparam o (fix j)) 0 1)))
	      (setq ll (list (apply 'min (mapcar 'car p)) (apply 'min (mapcar 'cadr p))))
	      (setq ur (list (apply 'max (mapcar 'car p)) (apply 'max (mapcar 'cadr p))))
	      (command "_.zoom" ll ur)
	      (command "_.dimradius" "_nea" (trans (vlax-curve-getpointatparam o j) 0 1) "_non" "@-2,-2")))))))
  (princ)
  )

 

0 Likes
Message 3 of 7

-didier-
Advisor
Advisor
Accepted solution

Bonjour @javeed4teen 

 

Here is my proposition.

I wrote it this morning after reading your question, but I am not as fast as some members ( @ВeekeeCZ )

 

Amicalement

 

(defun c:dim-poly-ray ( / acsp adoc angle-arc bulge centre corde gis-centre n p1 p2 pmil pol polvla rayon)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (if (zerop (getvar "tilemode"))
        (setq acsp (vla-get-paperspace adoc))
        (setq acsp (vla-get-modelspace adoc))
    )

  (setq pol (car (entsel "\nChoix de la polyligne\n")))
  (if ( = "LWPOLYLINE" (cdr (assoc 0 (entget pol))))
    (progn
      (setq polvla (vlax-ename->vla-object pol))
      (setq n 0)
      (repeat (- (cdr (assoc 90 (entget pol)))1)
	(setq bulge (vla-GetBulge polvla n))
	(if (not (zerop bulge))
	  (progn
	    (setq p1 (vlax-curve-getpointatparam polvla n)
		  p2 (vlax-curve-getpointatparam polvla (1+ n))
		  angle-arc (* 4.0 (atan (abs bulge)))
		  corde (distance p1 p2)
		  rayon (/ (/ corde 2.0) (sin (/ angle-arc 2.0)))
		  Gis-Centre (if (>= bulge 0)
			       (+ (angle p1 p2) (/ (- pi angle-arc) 2.0))
			       (- (angle p1 p2) (/ (- pi angle-arc) 2.0))
			       )
		  centre (polar p1 Gis-Centre (/ (/ corde 2.0) (sin (/ angle-arc 2.0))))
		  pmil (vlax-curve-getpointatparam polvla (+ 0.5 n))
		  )
	    (vlax-invoke acsp 'Adddimradial centre pmil 0.0)
	    (setq n (1+ n))
	    ); deuxième progn
	  (setq n (1+ n))
	  );deuxième if
	);repeat
      );premier progn
    (progn
      (prompt "\Vous n'avez pas choisi une polyligne !")
      (princ)
      )
    );prenier if
  );defun
		   

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 4 of 7

Moshe-A
Mentor
Mentor
Accepted solution

@javeed4teen hi,

 

check DMR command.

 

The dimension leader (for the radius) is 0.7 * radius long

if overlapping arcs exist, the arc in question may not found.

 

dimension style settings is on you 😀

 

enjoy

Moshe

 

 

; custom dimradius

(defun c:dmr (/ data_filter ; local function
	        LEADER_FACTOR ss ename elist m0 m1 m2 sa ea r0 item p0 p1 blg a0 ax)

 (defun data_filter (xdata / i)
  (setq i -1)
  (vl-remove-if
    'not
    (mapcar
      (function
       (lambda (item)
        (setq i (1+ i))
        (if (and
	      (= (car item) 10)
	      (=  (car (nth (+ i 3) xdata)) 42)
	      (/= (cdr (nth (+ i 3) xdata)) 0.0)
	      (=  (car (nth (+ i 5) xdata)) 10)
	    )
	 (list (cdr item) (cdr (nth (+ i 3) xdata)) (cdr (nth (+ i 5) xdata)))
        ); if
       ); lambda
     ); function
     xdata
    ); mapcar
  ); vl-remove-if
 ); data_filter


 ; here start c:dmr
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (setq LEADER_FACTOR 0.7) ; const
  
 (if (setq ss (ssget '((0 . "arc,lwpolyline"))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq elist (entget ename))
   (cond
    ((eq (cdr (assoc ' 0 elist)) "ARC")
     (setq m1 (cdr (assoc '10 elist)))
     (setq sa (cdr (assoc '50 elist)))
     (setq ea (cdr (assoc '51 elist)))
     (setq r0 (cdr (assoc '40 elist)))

     (if (< sa ea)
      (setq m2 (polar m1 (+ sa (/ (- ea sa) 2)) r0))
      (setq m2 (polar m1 (+ ea (/ (- sa ea) 2)) r0))
     )
    ); case
    ( t
     (foreach item (data_filter elist)
      (setq p0 (car item))
      (setq blg (cadr item))
      (setq p1 (caddr item))
      (setq a0 (* (atan (abs blg)) 2))
      (setq ax (* (distance p0 p1) 0.5))
      (setq m0 (polar p0 (angle p0 p1) ax))
      (setq r0 (/ ax (sin a0)))

      (if (minusp blg)
       (setq m1 (polar p0 (- (angle p0 p1) (- (* pi 0.5) a0)) r0))
       (setq m1 (polar p0 (+ (angle p0 p1) (- (* pi 0.5) a0)) r0))
      )
	
      (setq m2 (polar m1 (angle m1 m0) r0))
     ); foreach
    ); case
   ); cond

   ; execute command
   (if (ssget m2 '((0 . "arc,lwpolyline"))) ; make sure the arc is there
    (command "._dimradius" m2 (polar m1 (angle m1 m2) (* r0 LEADER_FACTOR)))
   )
  ); foreach
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ)
); c:dmr

 

 

 

0 Likes
Message 5 of 7

Moshe-A
Mentor
Mentor
Accepted solution

@javeed4teen 

 

with some fine tunning

 

 

0 Likes
Message 6 of 7

javeed4teen
Participant
Participant

Dang. U guys made my work much easier. Thanks guys. @-didier- @ВeekeeCZ @Moshe-A 

 

@javeed4teen - this post has been edited due to Community Rules & Etiquette violation.

0 Likes
Message 7 of 7

javeed4teen
Participant
Participant

Sorry everyone, it was a typo — I didn’t even realize it until I saw this message.

0 Likes