Creating lisp routine for dimension style

Creating lisp routine for dimension style

ethan_bott
Explorer Explorer
4,078 Views
7 Replies
Message 1 of 8

Creating lisp routine for dimension style

ethan_bott
Explorer
Explorer

Hello,

 

I'm having a problem with a client and a dimension style would easily fix the problem that is occurring in the field. Our client has been pouring their foundations wrong for some reason and would like to create a diagonal dimension across the footprint of the building to aid them along with the normal dimensions. I have created a dimension by editing the properties and want to see if i can create a lisp routine in order to have this down with one easy step (Want to delay any other time consuming editing to improve workflow).

 

I have attached a picture of the dimension style wanted. Essentially I edited the properties to have the dimension lines and extensions removed, with the arrows facing opposite. The dimension is now on the outside of the house to show the diagonal length. 

 

I have edited my DIMUPT, DIMTOFL, DIMAFIT & DIMTMOVE to create this style along with the property edits. I was wondering if i could create a lisp routine based on a dimensions lisp I learned in a tutorial-

 

(defun c:cdims ()
;define the function

(setq a (getpoint "\nEnter First Point : "))
;get the first point

(setq b (getpoint "\nEnter Second Point : "))
;get the second point

(command "dimaligned" a b b)
;draw the dimline

) ;end defun

 

This allow me to pick point 1 & 2 and create a dimension. I want to see if i can set up a command to do this, but take on my properties for this 'new' dim style.

 

Although i know a dim style would elimante this, I want to see if you can create a lisp routine for this. I am new to creating lisps, but want to try to expand my knowledge of this aspect in cad. Any help would be greatly appreciated.

 

Thanks!

-Ethan

0 Likes
4,079 Views
7 Replies
Replies (7)
Message 2 of 8

leeminardi
Mentor
Mentor

You can get a list of the dimension variables here:

http://www.g-wlearning.com/cad/9781605251615/student/resourceCenter/PDF/DimVar.pdf

 

Before you change a variable you should save the current value and reset it after you add your dimension line.

 

For example, to save the current value of whether to display the first extension line you would use something like:

(setq de1 (getvar "dimse1"))

and to turn off the display (a value of 0 means display it, 1 means do not display):

(setvar "dimse1" 1)

after you add your dimension line you would state:

(setvar "dimse1" de1)

To turn off both extension lines your program would look like this:

 

(defun c:cdims ()
					;define the function
; get dim variables
(setq de1 (getvar "dimse1"))
(setvar "dimse1" 1)
(setq de2 (getvar "dimse2"))
(setvar "dimse2" 1)  

;  
  (setq a (getpoint "\nEnter First Point : "))
					;get the first point

  (setq b (getpoint "\nEnter Second Point : "))
					;get the second point

  (command "dimaligned" a b b)
					;draw the dimline

; set dim variables back to original value
(setvar "dimse1" de1)  
(setvar "dimse2" de2)  
  
)					;end defun

You can go through the list and choose the variables you want to change.

 

 

lee.minardi
Message 3 of 8

ethan_bott
Explorer
Explorer

Thank you for this. I will edit the variables to our liking, but would like to thank you for helping  me out. I will still need to figure out how to add a command to mirror it on the opposite side of the dimension, but that should be too hard to figure out. Thanks again. Was exactly what i was looking for.

0 Likes
Message 4 of 8

leeminardi
Mentor
Mentor

Here's another way to do what you want using leaders instead of dimension lines.

Note that the program includes a value for the length (llen) of the leader.  You can edit the code to change this value or make it a function of some other parameter. You may also need to change or set some of the leader line parameters for your formating requirements.

 

(defun c:cdims (/ a b os llen dis disf ang p1 p2 angdeg)
  (setq a (getpoint "\nEnter Bottom Left Point : "))
					;get the first point
  (setq b (getpoint "\nEnter Top Right Point : "))
					;get the second point
  (setq os (getvar "osmode"))		; get current osnap mode
  (setvar "osmode" 0)			; turn off osnap  
  (setq llen 1.5)			; length of leader
  (setq dis (distance a b))
  (setq disf (rtos dis 4 4))		; convert distance to arch units
  (setq ang (angle a b))
					; add bottom left dim
  (setq p1 (polar a (+ pi ang) llen))
  (command "leader" a p1 "" "" "n")
  (setq p2 (polar p1 ang (/ llen 2)))	;leader   mid-point
  (setq angdeg (/ (* ang 180.0) pi))
  (command "text" "J" "BC" p2 "" angdeg disf p2 "")
					; add top right dim
  (setq p1 (polar b ang llen))
  (command "leader" b p1 "" "" "n")
  (setq p2 (polar b ang (/ llen 2)))
  (command "text" "J" "BC" p2 "" angdeg disf p2 "")
  (setvar "osmode" os)
  (princ)
)					;end defun
lee.minardi
Message 5 of 8

scot-65
Advisor
Advisor
Another option is to use the 2 selected points to set the UCS axis "Z" method.
If not mistaken, one will need to TRANS the points so the linear dimension
is placed successfully. From there, reset the UCS axis.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 6 of 8

john.uhden
Mentor
Mentor

I would probably get an entity data list from a dimension style that suits you, delete the -1 and 5 codes and use it to entmake the style when needed.

John F. Uhden

0 Likes
Message 7 of 8

ethan_bott
Explorer
Explorer

Hey Lee, 

Thanks for the response to my question. Your method may be a little more advantageous for me and my client. Is there a way to set an arrow to the end of the leader? Also, we want each side to show the diagonal dimension of the building. We have updates to the building constantly, so the ability to stretch and keep the command intact would be so beneficial. I will do some research on this during my lunch, but any help would be appreciated. Still getting used to working with code and writing lisp routines, so very happy for the help i'm being given. Thanks again

 

-Ethan 

0 Likes
Message 8 of 8

leeminardi
Mentor
Mentor

Here's a modified version of the program.  It uses leaders and plain text.  Getting the leader to behave was a hassle.  Please make sure your leader style is not annotative and is set as follows:

s1.JPGs2.JPG

I added a scale factor prompt.

Since the text command and not mtext is used, you must have the default text size set to 0.0 

s3.JPG

The final results look like this:

s4.JPG

Here's the code.  You can tweak it to give the results you want. 

(defun c:cdims (/ sc a b os llen dis disf ang p1 p2 angdeg)
; adds two leaders the show corner to corner dimensions
; lrm 4/30/2018  
  (setq sc (getreal "\nEnter scale factor:"))
  (setq a (getpoint "\nEnter Bottom Left Point : "))
					;get the first point
  (setq b (getpoint "\nEnter Top Right Point : "))
					;get the second point
  (setq os (getvar "osmode"))		; get current osnap mode
  (setvar "osmode" 0)			; turn off osnap  
  (setq llen (* sc  1.3))		; length of leader
  (setq dis (distance a b)) 
  (setq disf (rtos dis 4 4))		; convert distance to arch units
  (setq ang (angle a b))
					; add bottom left dim
  (setq p1 (polar a (+ pi ang) llen))
  (setvar "mleaderscale" sc)
  (setq txtscale (* 0.18 sc)) ; scale text, assumes default 0.18
  (command "mleader" a p1 0.0)
  (setq p2 (polar p1 ang (/ llen 2)))	;leader   mid-point
  (setq angdeg (/ (* ang 180.0) pi)) ; convert angle to degrees
  (command "text" "J" "BC" p2 txtscale angdeg disf p2 "")
					; add top right dim
  (setq p1 (polar b ang llen)) 
  (command "mleader" b p1 0.0)
  (setq p2 (polar b ang (/ llen 2)))
  (command "text" "J" "BC" p2 txtscale angdeg disf p2 "")
  (setvar "osmode" os)  ; set osnap back 
  (princ)
)					;end defun

 

 

  

lee.minardi
0 Likes