Creating/Appending a Dimension through LISP

Creating/Appending a Dimension through LISP

Anonymous
Not applicable
1,150 Views
4 Replies
Message 1 of 5

Creating/Appending a Dimension through LISP

Anonymous
Not applicable

I've got the following bit of code and I can't seem to figure out why it won't create the dimension object. 

(defun C:DIMDIA (/ pr cl osm obj rad ep sp ss count newdim d ) 
	(setvar "cmdecho" 0)										;Variables
	(setq pr (getvar "luprec"))
	(setq cl (getvar "clayer"))
	(setq osm (getvar "osmode"))
	(setvar "osmode" 0)
	(if (= (getvar "lunits") 2) (setvar "luprec" 3))
	(setq obj (vlax-ename->vla-object (setq e (car (entsel "\nSelect circle to Dimension: ")))))
	(if (= (vla-get-objectname obj) "AcDbCircle")
		(progn	
			(setq rad (vla-get-radius obj))
(setq f (getpoint "\nLeader Location: ")) (command "LAYER" "M" "DIM" "") (command "AMPOWERDIM_DIA" e f ) (princ "\nSelect Circles for hole count") (setq ss (ssget (list '(0 . "CIRCLE")(cons 40 rad)))) (if (/= (setq count (sslength ss)) 0) (progn (setq newdim (entlast)) (setq d (strcat "<>" "[]" " (" (itoa count) " PLACES)")) (command "dimedit" "n" d newdim "") ) ) ) (princ "\nSelected Object is not a circle.") ) (setvar "clayer" cl) (setvar "luprec" pr) (setvar "osmode" osm) (princ) )

It seems to completely skip over the (command "AMPOWERDIM_DIA" e f ) portion of code, while the rest of it executes flawlessly, instead altering the previously placed dimension. 

 

Also, would there be a way to show the preview of the dimension location before its placed? I tried nesting the (getpoint) within the "AMPOWERDIM_DIA" command, but no such luck, though that might be tied to the first issue.

0 Likes
Accepted solutions (2)
1,151 Views
4 Replies
Replies (4)
Message 2 of 5

ronjonp
Mentor
Mentor
Accepted solution

I don't have AutoCAD Mechanical but if you want to see the placement of the dimension try this:

(command "AMPOWERDIM_DIA" e "\\" )

And comment out:

(setq f (getpoint "\nLeader Location: "))
0 Likes
Message 3 of 5

dbhunia
Advisor
Advisor
Accepted solution

Try with this change....

 

(defun C:DIMDIA (/ pr cl osm obj rad ep sp ss count newdim d ) 
	(setvar "cmdecho" 0)										;Variables
	(setq pr (getvar "luprec"))
	(setq cl (getvar "clayer"))
	(setq osm (getvar "osmode"))
	(setvar "osmode" 0)
	(if (= (getvar "lunits") 2) (setvar "luprec" 3))
	(setq obj (vlax-ename->vla-object (car (setq e (entsel "\nSelect circle to Dimension: ")))))
	(if (= (vla-get-objectname obj) "AcDbCircle")
		(progn	
			(setq rad (vla-get-radius obj))
                        (setq f (getpoint "\nLeader Location: "))
			(command "LAYER" "M" "DIM" "")
			;(command "AMPOWERDIM_DIA" e f )
			(command "AMPOWERDIM_DIA" (cadr e))
			;(command "DIMDIAMETER" (cadr e));;; Or Try this
			(while (/= (getvar "cmdactive") 0)(command f))
			(princ "\nSelect Circles for hole count")
			(setq ss (ssget (list '(0 . "CIRCLE")(cons 40 rad))))
			(if (/= (setq count (sslength ss)) 0)
				(progn
					(setq newdim (entlast))
					(setq d (strcat "<>" "[]" " (" (itoa count) " PLACES)"))
					(command "dimedit" "n" d newdim  "")
				)
			)
		)
		(princ "\nSelected Object is not a circle.")
	)
	(setvar "clayer" cl)
	(setvar "luprec" pr)
	(setvar "osmode" osm)
	(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 5

Anonymous
Not applicable

Well, that seems to fix the first issue.

Oddly enough, now I'm getting an error about invalid selection expecting single object after selecting holes, though nothing has changed for that piece of code. 

 

Scratch that, it only doesn't work with AMPOWERDIM_DIA. Using DIMDIAMETER works fine. 

 

Thanks for the help, both of you.

0 Likes
Message 5 of 5

dbhunia
Advisor
Advisor

You Welcome 🙂

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes