PDA

View Full Version : Automatic Dimensioning of Circles



Drafter_Joe
2015-11-18, 02:38 PM
Hello!

Does anyone have or has anyone seen a LISP routine that can automatically dimension (diameter only) groups of circles? I have done some searching and have not seen anything like that. The only part of this type of routine I have seen so far is a checking of circles to see if they are all the same radius. My particular use is when I have several circles within a rectangular or circular shape, like swiss cheese, where one of each different diameter sizes has a diameter dimension with the number of other circles with the same diameter. i.e. "(dia. symbol) 2.25 TYP 5 PLCS". I can kind of see at least few different loops and such being needed, but when I try to think of how to put them together, my brain starts to hurt. If anyone can assist in any way, I'd greatly appreciate it!

Thank you!

Drafter_Joe

cadhelp Van
2015-11-19, 06:31 PM
(defun c:DimCircle ( / ss circle #mdsp# rad centre i)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimradial #mdsp# (vlax-3d-point centre)(vlax-3d-point (polar centre 0.5 rad))(/ rad 2)))
(setq i (1+ i))
)
)

Drafter_Joe
2015-11-20, 12:58 PM
(defun c:DimCircle ( / ss circle #mdsp# rad centre i)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimradial #mdsp# (vlax-3d-point centre)(vlax-3d-point (polar centre 0.5 rad))(/ rad 2)))
(setq i (1+ i))
)
)


Well done! Thank you cadhelp Van! That is a huge step in the right direction for me! I will try to figure out the other things I want to do, but if anyone might have any other suggestions, I'd greatly appreciate it!

Thanks again, cadhelp Van!!

Bruno.Valsecchi
2015-11-20, 03:13 PM
For diameter, you can change to this:


(defun c:DimCircle ( / ss circle #mdsp# rad centre i)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimdiametric #mdsp# (vlax-3d-point (polar centre (* 0.25 pi) rad))(vlax-3d-point (polar centre (* 1.25 pi) rad)) (* 2 rad)))
(setq i (1+ i))
)
)

Drafter_Joe
2015-11-20, 03:47 PM
For diameter, you can change to this:


(defun c:DimCircle ( / ss circle #mdsp# rad centre i)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimdiametric #mdsp# (vlax-3d-point (polar centre (* 0.25 pi) rad))(vlax-3d-point (polar centre (* 1.25 pi) rad)) (* 2 rad)))
(setq i (1+ i))
)
)

Thank you, Bruno! I was wondering how to do that. I'll look into this as I have more time.

cadhelp Van
2015-11-20, 04:34 PM
If there are identical circles



(defun c:DimCircle ( / ss circle #mdsp# rad centre i count)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimdiametric #mdsp# (vlax-3d-point (polar centre (* 0.25 pi) rad))(vlax-3d-point (polar centre (* 1.25 pi) rad)) (/ rad 2)))
(if(>(setq count(sslength(ssget "X" (list'(0 . "CIRCLE")(assoc 40 (entget circle))))))1)
(vla-put-TextSuffix dim (strcat " TYP " (itoa count) " PLCS" ))
)
(setq i (1+ i))
)
)

Drafter_Joe
2015-11-20, 06:15 PM
If there are identical circles



(defun c:DimCircle ( / ss circle #mdsp# rad centre i count)
(setq ss (ssget '((0 . "CIRCLE")))i 0)
(setq #mdsp# (vla-get-ModelSpace(vla-get-activedocument(vlax-get-acad-object))))
(while (setq circle (ssname ss i))
(setq rad (cdr(assoc 40(entget circle)))centre (cdr(assoc 10(entget circle))))
(setq dim (vla-adddimdiametric #mdsp# (vlax-3d-point (polar centre (* 0.25 pi) rad))(vlax-3d-point (polar centre (* 1.25 pi) rad)) (/ rad 2)))
(if(>(setq count(sslength(ssget "X" (list'(0 . "CIRCLE")(assoc 40 (entget circle))))))1)
(vla-put-TextSuffix dim (strcat " TYP " (itoa count) " PLCS" ))
)
(setq i (1+ i))
)
)


Thanks cadhelp Van! It's looking real good! I really appreciate the kick-start help I've received so far!

Drafter_Joe
2015-12-04, 05:22 PM
Edit: Actually the code is good. There is something up with two 2.5 diameter circles in the lower object. I tried many different circles and the routine worked just fine. If anyone has ways to streamline the routine, that would be great to see.



Here's an update, if anyone might be interested. Below is the code that I have put together so far. Also, attached is a drawing that I have been using as a test. This routine is not working quite right. Some circles are still getting dimensioned when there is another circle with the same diameter. Seems like the if statement checking on equality of radii is not working all the time and the same if I use "eq" or "equal". Please excuse me for not noting my code very well, I'm not exactly sure what everything does in it. If anyone can take a look and give any help, I would greatly appreciate it! Oh, one more question. The gray box just underneath my name says I've "taken a wrong turn". What does this mean and how would that be changed?


(defun c:DimCircles (/ ss circle #mdsp# rad center i count);credit goes to Bruno.Valsecchi & cadhelp Van from the augi forum
(setvar "cmdecho" 0) ;unless otherwise stated elsewhere
(setq oldlayer (getvar "clayer"))
(command "-layer" "s" "Dim" "")
(setq ss (ssget "_X" '((0 . "CIRCLE") (8 . "0"))))
(setq sslist (vl-sort ;from here to
(vl-remove-if 'listp
(mapcar 'cadr(ssnamex ss)))
'(lambda(x y)
(>
(cdr(assoc 40(entget x)))
(cdr(assoc 40(entget y)))))) ;here, for this little section credit goes to ASMI from the cadtutor forum
)
(setq rad2 nil)
(setq #mdsp# (vla-get-ModelSpace
(vla-get-activedocument (vlax-get-acad-object))
)
)
(setq ss(ssadd));and from here
(foreach ent sslist
(ssadd ent ss)
); end foreach ;to here, from ASMI also.
(repeat (setq i (sslength ss))
(setq rad2 rad)
(setq circle (ssname ss (setq i (1- i))))
(setq rad (cdr (assoc 40 (entget circle))))

(if (= rad2 rad)
(princ)
(progn
(setq center (cdr (assoc 10 (entget circle))))
(setq dim (vla-adddimdiametric
#mdsp#
(vlax-3d-point (polar center (* 0.25 pi) rad))
(vlax-3d-point (polar center (* 1.25 pi) rad))
(/ rad 2)
)
)
(if (> (setq
count (sslength
(ssget
"X"
(list '(0 . "CIRCLE")
(assoc 40 (entget circle))
)
)
)
)
1
)
(vla-put-TextSuffix
dim
(strcat " TYP \n" (itoa count) " PLCS")
)
)
(princ)
)
)
);end repeat
(command "-layer" "s" oldlayer "")
(setvar "cmdecho" 1)
(princ)
)

Thank you for taking a look!

Drafter_Joe

Drafter_Joe
2015-12-07, 01:53 PM
Hi!

Another update. I have added dimensioning of arcs. Seems to work pretty well although the code is probably twice as long as it needs to be. If anyone could streamline it, that would be great! Also, I was wondering if anyone would know how to make it possible for the user place each dimension as it goes along? Perhaps as an option?


(defun c:DimCircles (/ ss e #mdsp# rad center i count)
;credit goes to Bruno.Valsecchi & cadhelp Van from the augi forum
(setvar "cmdecho" 0) ;unless otherwise stated elsewhere
(setq oldlayer (getvar "clayer"))
(command "-layer" "s" "Dim" "")
(setq ss (ssget "_X" '((0 . "CIRCLE") (8 . "0"))))
(setq ss2 (ssget "_X" '((0 . "ARC") (8 . "0"))))
(setq sslist (vl-sort ;credit for sort by size goes to ASMI of cadturor forum, from here
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss))
)
'(lambda (x y)
(>
(cdr (assoc 40 (entget x)))
(cdr (assoc 40 (entget y)))
)
)
)
) ;to here
(setq rad2 nil)
(setq #mdsp# (vla-get-ModelSpace
(vla-get-activedocument (vlax-get-acad-object))
)
)
(setq ss (ssadd)) ;from here
(foreach ent sslist
(ssadd ent ss)
) ; end foreach ;to here, this little section credit also goes to ASMI from the cadtutor forum


(repeat (setq i (sslength ss))
(setq rad2 rad)
(setq circle (ssname ss (setq i (1- i))))
(setq rad (cdr (assoc 40 (entget circle))))

(if (= rad2 rad)
(princ)
(progn
(setq center (cdr (assoc 10 (entget circle))))
(setq dim (vla-adddimdiametric
#mdsp#
(vlax-3d-point (polar center (* 0.25 pi) rad))
(vlax-3d-point (polar center (* 1.25 pi) rad))
(/ rad 2)
)
)
(if (> (setq
count (sslength
(ssget
"X"
(list '(0 . "CIRCLE")
(assoc 40 (entget circle))
)
)
)
)
1
)
(vla-put-TextSuffix
dim
(strcat " TYP \n" (itoa count) " PLCS")
)
)
(princ)
)
)
) ;end repeat
(if (/= ss2 nil)
(progn
(setq sslist2 (vl-sort
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss2))
)
'(lambda (x y)
(>
(cdr (assoc 40 (entget x)))
(cdr (assoc 40 (entget y)))
)
)
)
)
(setq ss2 (ssadd))
(foreach ent sslist2
(ssadd ent ss2)
)
(setq rad2 nil)
(repeat (setq i (sslength ss2))
(setq rad2 rad)
(setq arc (ssname ss2 (setq i (1- i))))
(setq rad (cdr (assoc 40 (entget arc))))

(if (= rad2 rad)
(princ)
(progn
(setq center (cdr (assoc 10 (entget arc))))
(setq dim (vla-adddimradial
#mdsp#
(vlax-3d-point center)
(vlax-3d-point (polar center 0.5 rad))
(/ rad 2)
)
)
(if (> (setq
count (sslength
(ssget
"X"
(list '(0 . "ARC")
(assoc 40 (entget arc))
)
)
)
)
1
)
(vla-put-TextSuffix
dim
(strcat " TYP \n" (itoa count) " PLCS")
)
)
(princ)
)
)
) ;end repeat
) ;end arc progn
(princ)
) ;end arc if
(command "-layer" "s" oldlayer "")
(setvar "cmdecho" 1)
(princ)
)


Thank you for any assistance!

Drafter_Joe

Bruno.Valsecchi
2015-12-11, 03:29 PM
Hi,

This update? for "to make it possible for the user place each dimension"



(defun c:DimCircles ( / ss ss2 sslist rad2 AcDoc #mdsp# i circle rad center pt_user dim count arc)
;credit goes to Bruno.Valsecchi & cadhelp Van from the augi forum
(setq ss (ssget "_X" '((0 . "CIRCLE") (8 . "0"))))
(setq ss2 (ssget "_X" '((0 . "ARC") (8 . "0"))))
(setq sslist (vl-sort ;credit for sort by size goes to ASMI of cadturor forum, from here
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss))
)
'(lambda (x y)
(>
(cdr (assoc 40 (entget x)))
(cdr (assoc 40 (entget y)))
)
)
)
) ;to here
(setq rad2 nil)
(setq
AcDoc (vla-get-activedocument (vlax-get-acad-object))
#mdsp# (vla-get-ModelSpace AcDoc)
)
(cond
((null (tblsearch "LAYER" "Dim"))
(vlax-put (vla-add (vla-get-layers AcDoc) "Dim") 'color 5)
)
)
(setq ss (ssadd)) ;from here
(foreach ent sslist
(ssadd ent ss)
) ; end foreach ;to here, this little section credit also goes to ASMI from the cadtutor forum


(repeat (setq i (sslength ss))
(setq rad2 rad)
(setq circle (ssname ss (setq i (1- i))))
(setq rad (cdr (assoc 40 (entget circle))))

(if (= rad2 rad)
(princ)
(progn
(initget 9)
(setq pt_user (trans (getpoint (trans (setq center (cdr (assoc 10 (entget circle)))) 0 1) "\nPosition ?: ") 1 0))
(setq pt_user (polar center (angle center pt_user) rad))
(setq dim (vla-adddimdiametric
#mdsp#
(vlax-3d-point (polar center (angle center pt_user) rad))
(vlax-3d-point (polar center (angle pt_user center) rad))
(/ rad 2)
)
)
(vla-put-Layer dim "Dim")
(if (> (setq
count (sslength
(ssget
"X"
(list '(0 . "CIRCLE")
(assoc 40 (entget circle))
)
)
)
)
1
)
(vla-put-TextSuffix
dim
(strcat " TYP \n" (itoa count) " PLCS")
)
)
(princ)
)
)
) ;end repeat
(if (/= ss2 nil)
(progn
(setq sslist2 (vl-sort
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss2))
)
'(lambda (x y)
(>
(cdr (assoc 40 (entget x)))
(cdr (assoc 40 (entget y)))
)
)
)
)
(setq ss2 (ssadd))
(foreach ent sslist2
(ssadd ent ss2)
)
(setq rad2 nil)
(repeat (setq i (sslength ss2))
(setq rad2 rad)
(setq arc (ssname ss2 (setq i (1- i))))
(setq rad (cdr (assoc 40 (entget arc))))

(if (= rad2 rad)
(princ)
(progn
(initget 9)
(setq pt_user (trans (getpoint (trans (setq center (cdr (assoc 10 (entget arc)))) 0 1) "\nPosition ?: ") 1 0))
(setq pt_user (polar center (angle center pt_user) rad))
(setq dim (vla-adddimradial
#mdsp#
(vlax-3d-point center)
(vlax-3d-point pt_user)
(/ rad 2)
)
)
(vla-put-Layer dim "Dim")
(if (> (setq
count (sslength
(ssget
"X"
(list '(0 . "ARC")
(assoc 40 (entget arc))
)
)
)
)
1
)
(vla-put-TextSuffix
dim
(strcat " TYP \n" (itoa count) " PLCS")
)
)
(princ)
)
)
) ;end repeat
) ;end arc progn
(princ)
) ;end arc if
(princ)
)

Drafter_Joe
2015-12-14, 05:29 PM
Thank you Bruno! That looks like it will work just fine.

I really appreciated your help!

Drafter_Joe
2015-12-16, 01:47 PM
The code really works well except for when the dimensions are created, the dimscale is 1. How do I make the added dimensions to match the existing dimscale of the other dimensions?

[Edit:] Nevermind. I got it.


(vla-put-scalefactor dim scale)

So simple, a simpleton like myself can use it! :lol: