PDA

View Full Version : Draw a line that is dimensioned


Robert.Hall
2005-06-07, 06:59 PM
I snuck this from a post by cmason.82472, no credit to me.

Can somebody design a lisp routine that would allow the user to create
a line that is already dimensioned?

Maybe something where the user would invoke a line command, pick the start point,
and then upon picking the endpoint, would get a yes/no prompt for dimensioning the line.
When the user selects yes, a linear dimension would be placed on the line at a fixed
distance and then the command would continue to create another line, much like the line command.

A similar routine would create a dimensioned rectangle. Could we create geometry
that already has dimensions???? It would be a timesaver to take the entire drawing menu and replace it with predimensioned objects (ie. circle with radius dimension).

I am guessing anything close to the above would be great for 2d work.
This routine is a little too complex for me to create.

CAB2k
2005-06-07, 11:42 PM
Not too complicated if you take advantage of COMMAND.
You can start with these.
(defun c:linedim (/ p1 p2)
(while
(and
(setq p1 (getpoint "Specify first point:"))
(setq p2 (getpoint p1 "Specify next point:"))
(null (command "._line" p1 p2 ""))
(setq elast (entlast))
(null (command "._dimaligned" p1 p2 pause))
)
)
(princ)
)

(defun c:linedimc (/ p1 p2)
(if (setq p1 (getpoint "Specify first point:"))
(while
(and
(setq p2 (getpoint p1 "Specify next point:"))
(null (command "._line" p1 p2 ""))
(setq elast (entlast))
(null (command "._dimaligned" p1 p2 pause))
(setq p1 p2)
)
)
)
(princ)
)

kennet.sjoberg
2005-06-07, 11:45 PM
rhall, here is 3 routines for You to start with.
You can add the "YES" option to the program, and of course layer and error handling.
Feel free to modify

(defun c:DimLine (/ Pkt1 Pkt2 )
(if (and (setq Pkt1 (getpoint "Specify first point: " )) (setq Pkt2 (getpoint "Specify next point: " ))) (command "._line" Pkt1 Pkt2 "" ) ( ) )
(while Pkt2
(command "._dimaligned" Pkt1 Pkt2 (polar Pkt2 (+ (angle Pkt1 Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" )(getvar "DIMSCALE" ))) )
(setq Pkt1 Pkt2 Pkt2 nil )
(if (and Pkt1 (setq Pkt2 (getpoint "Specify next point: " ))) (command "._line" Pkt1 Pkt2 "" ) ( ) )
)
(princ)
)

(defun c:DimRec (/ Pkt1 Pkt2 )
(if (and (setq Pkt1 (getpoint "Specify first corner: " )) (setq Pkt2 (getpoint "Specify next corner: " ))) (command "._rectang" Pkt1 Pkt2 ) ( ) )
(while Pkt2
(command "._dimlinear"
Pkt1 (list (car Pkt2)(cadr Pkt1)(caddr Pkt1))
(polar Pkt1 (- (angle Pkt1 Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" )(getvar "DIMSCALE" )))
)
(command "._dimlinear"
(list (car Pkt2)(cadr Pkt1)(caddr Pkt1)) Pkt2
(polar Pkt2 (- (angle (list (car Pkt2)(cadr Pkt1)(caddr Pkt1)) Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" )(getvar "DIMSCALE" )))
)
(setq Pkt2 nil )
(if (and (setq Pkt1 (getpoint "Specify first corner: " )) (setq Pkt2 (getpoint "Specify next corner: " ))) (command "._rectang" Pkt1 Pkt2 ) ( ) )
)
(princ)
)

(defun c:DimCir (/ Pkt1 Pkt2 )
(if (and (setq Pkt1 (getpoint "center point: " )) (setq Pkt2 (getpoint "digitize radius: " ))) (command "._circle" Pkt1 Pkt2 "" ) ( ) )
(while Pkt2
(command "._dimradius" Pkt1 Pkt2 "" )
(setq Pkt2 nil )
(if (and (setq Pkt1 (getpoint "center point: " )) (setq Pkt2 (getpoint "digitize radius: " ))) (command "._circle" Pkt1 Pkt2 "" ) ( ) )
)
(princ)
)

: ) Happy Computing !

kennet

CAB2k
2005-06-08, 12:10 AM
Here is an example uning a rectangle. It gives the user the option of selecting the
side to place the dimension. Trouble with the COMMAND is that it will crash if the user
selects an unexpected option.
(defun c:recdim (/ p1 p2)
(setq elst (entlast))
(while
(and
(null (command "._rectangle" pause pause ""))
(/= elst (entlast))
(setq elst (entlast))
(null (prompt "\nPick the side to dimension."))
(null (command "._dimlinear" "" pause pause))
(null (prompt "\nPick the other side to dimension."))
(null (command "._dimlinear" "" pause pause))
)
)
(princ)
)

Robert.Hall
2005-06-08, 03:35 PM
These work great, gracias un mil. I am going to set up a toolbar with these to use instead of the standard drawing commands. :-D

jwanstaett
2005-06-08, 04:30 PM
put this code in a toolbar
the 3,3 at the end is for the dim off set change as needed

^C^Cline;;_dimaligned;;_from _mid @ @3,3

kennet.sjoberg
2005-06-09, 12:40 AM
rhall, if you remove (getvar "DIMSCALE" ) from my function DimLine and DimRec you will have a better result.

: ) Happy Computing !

kennet

Robert.Hall
2005-06-09, 02:35 PM
rhall, if you remove (getvar "DIMSCALE" ) from my function DimLine and DimRec you will have a better result.

: ) Happy Computing !

kennet

Thanks, I am still trying to figure out the circle command..........I should be able to pick the center and then somehow specify the radius via numerical entry???

kennet.sjoberg
2005-06-09, 03:14 PM
... via numerical entry???
No problem, feel free to modify the code.

: ) Happy Computing !

kennet

CAB2k
2005-06-09, 03:45 PM
You could also write it like this.
The points you pick determine the dim location.
The is just a revised version of Kennet's routine.
Good job Kennet.

(defun c:DimCir (/ Pkt1 Pkt2)
(while (and (setq Pkt1 (getpoint "center point: "))
(setq Pkt2 (getpoint pkt1 "Pick the radius: "))
)
(command "._circle" Pkt1 Pkt2 "")
(command "._dimradius" Pkt1 Pkt2 "")
)
(princ)
)

fat_abjobe
2005-06-09, 07:03 PM
hey group

is it possible to get a lisp to plot floor plans to appear on paper at 1:100 ?
help needed . drawings are in metric and millimetres. I also want to check if after
plotting, i can get a ruler place it on the drawing and test the scale factor.

thanks
fat_abjobe

kennet.sjoberg
2005-06-16, 01:39 AM
Hi rhall, added DimArc
and adjusted DimLine, DimRec and DimCir

(defun c:DimArc (/ Pkt1 Pkt2 Pkt3 )
(while (and (setq Pkt1 (getpoint "\nCommand: Start point: " )) (setq Pkt2 (getpoint "pkt2 : " ))(setq Pkt3 (getpoint "end point : " )))
(command "._arc" Pkt1 Pkt2 Pkt3 )
(command "._dimradius" Pkt2 Pkt2 )
)
(princ)
)

(defun c:DimLine (/ Pkt1 Pkt2 )
(if (and (setq Pkt1 (getpoint "Specify first point: " )) (setq Pkt2 (getpoint "Specify next point: " ))) (command "._line" Pkt1 Pkt2 "" ) ( ) )
(while Pkt2
(command "._dimaligned" Pkt1 Pkt2 (polar Pkt2 (+ (angle Pkt1 Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" ))) )
(setq Pkt1 Pkt2 Pkt2 nil )
(if (and Pkt1 (setq Pkt2 (getpoint "Specify next point: " ))) (command "._line" Pkt1 Pkt2 "" ) ( ) )
)
(princ)
)

(defun c:DimRec (/ Pkt1 Pkt2 )
(if (and (setq Pkt1 (getpoint "Specify first corner: " )) (setq Pkt2 (getpoint "Specify next corner: " ))) (command "._rectang" Pkt1 Pkt2 ) ( ) )
(while Pkt2
(command "._dimlinear"
Pkt1 (list (car Pkt2)(cadr Pkt1)(caddr Pkt1))
(polar Pkt1 (- (angle Pkt1 Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" )))
)
(command "._dimlinear"
(list (car Pkt2)(cadr Pkt1)(caddr Pkt1)) Pkt2
(polar Pkt2 (- (angle (list (car Pkt2)(cadr Pkt1)(caddr Pkt1)) Pkt2 ) (/ pi 2 ) ) (* 3 (getvar "TEXTSIZE" )))
)
(setq Pkt2 nil )
(if (and (setq Pkt1 (getpoint "Specify first corner: " )) (setq Pkt2 (getpoint "Specify next corner: " ))) (command "._rectang" Pkt1 Pkt2 ) ( ) )
)
(princ)
)

(defun c:DimCir (/ Pkt1 Pkt2 )
(while (and (setq Pkt1 (getpoint "center point: " )) (setq Pkt2 (getpoint "digitize radius: " )))
(command "._circle" Pkt1 Pkt2 "" )
(command "._dimradius" Pkt1 Pkt2 "" )
)
(princ)
)
: ) Happy Computing !

kennet

Wouldn’t fat_abjobe be better served if his question was moved to a corresponding or new thread?

Robert.Hall
2005-06-16, 02:55 PM
Dimarc is a great routine..........what about also drawing the arc???
We are trying to make a toolset that will draw geometry while adding the dimensions
at the same time.

So far we have lines, circles, and rectangles defined. :shock:

kennet.sjoberg
2005-06-16, 03:39 PM
......what about also drawing the arc???
?? Haa... in 2002 it works great, but in 2006 there is already a dimarc command.
Rename the function like this :

(defun c:DimArc2 (/ Pkt1 Pkt2 Pkt3 )
(while (and (setq Pkt1 (getpoint "nCommand: Start point: " )) (setq Pkt2 (getpoint "pkt2 : " ))(setq Pkt3 (getpoint "end point : " )))
(command "._arc" Pkt1 Pkt2 Pkt3 )
(command "._dimradius" Pkt2 Pkt2 )
)
(princ)
)
: ) Happy Computing !

kennet

Robert.Hall
2005-06-16, 03:53 PM
No wonder I wasn't getting the arc..........thats funny.

:Puffy: