PDA

View Full Version : Need help with a LISP



mjohn80
2013-04-11, 10:27 PM
I am looking for some help or direction on writing a lisp to do the follow below.

I would like to be able to draw a rectangle with two offset lines (top offset, bottom offset & offset 42” from the selected line) by selecting a line within the drawing and inputting the three other values. Please see the attached drawing below.


Thanks

pbejse
2013-04-12, 04:07 AM
[SIZE=5][COLOR=#3E3E3E][FONT=times new roman]

I would like to be able to draw a rectangle with two offset lines (top offset, bottom offset & offset 42” from the selected line) by selecting a line within the drawing and inputting the three other values. Please see the attached drawing below.


command based solution:
Here you can change the entity creation from LINE to a polyline:


(Defun c:ofb ( / TheLine TopOffset HeightofRectangle BottomOffset en refpoints p1 ang90)
(if (and
(setq TheLine (car (entsel "\nSelect source Line:")))
(setq TopOffset (getdist "\nEnter Top Offset: "))
(setq HeightofRectangle (getdist "\nEnter Top Offset: "))
(setq BottomOffset (getdist "\nEnter Top Offset: "))
)

(progn
(setq en (entget TheLine))
(setq refpoints (list (cdr (assoc 10 en))
(cdr (assoc 11 en))
)
refpoints (if (< (caar refpoints) (caadr refpoints))
refpoints
(reverse refpoints)
)
)
(setq p1 (polar (car refpoints) (/ pi 2.0) 42) ang90 (/ pi 2.0))
(command "_rectang"
"_non"
p1
"_non"
(setq p2 (polar (list (car p1) (+ (cadr p1) HeightofRectangle))
0.0
(apply 'distance refpoints)
)
)
)
(command "_line"
"_non"
(polar (Car refpoints) ang90 (- 42 BottomOffset))
"_non"
(polar (Cadr refpoints) ang90 (- 42 BottomOffset))
""
)
(command
"_line"
"_non"
(polar (Car refpoints) ang90 (+ 42 TopOffset HeightofRectangle))
"_non"
(polar (Cadr refpoints) ang90 (+ 42 TopOffset HeightofRectangle))
""
)
)
)(princ)
)


This one use offsetting the source line:



(Defun c:ofb (/ TheLine TopOffset HeightofRectangle
BottomOffset en refpoints p1
ang90
)
(if (and
(setq TheLine (car (entsel "\nSelect source Line:")))
(setq TopOffset (getdist "\nEnter Top Offset: "))
(setq HeightofRectangle (getdist "\nEnter Top Offset: "))
(setq BottomOffset (getdist "\nEnter Top Offset: "))
)

(progn
(setq en (entget TheLine))
(setq refpoints (list (cdr (assoc 10 en))
(cdr (assoc 11 en))
)
refpoints (if (< (caar refpoints) (caadr refpoints))
refpoints
(reverse refpoints)
)
)
(setq p1 (polar (car refpoints) (/ pi 2.0) 42)
ang90 (/ pi 2.0)
)
(command "_rectang"
"_non"
p1
"_non"
(setq p2 (polar (list (car p1) (+ (cadr p1) HeightofRectangle))
0.0
(apply 'distance refpoints)
)
)
)
(command "_offset" (- 42 BottomOffset) TheLine p1 "")
(command "_offset" (+ 42 TopOffset HeightofRectangle) TheLine p1 "")

)
)
)

mjohn80
2013-04-12, 09:00 PM
Thanks that's great...Just one other question. Can the first or all offset have an option like (preset offset, or user input). And can the lisp recall or reset the default to last input values?

For example:

First top offset distance or <.625>:
Second top offset distance or <12>:
Third top offset distance or <1.25>:

So when I use the lisp I enter .875 for the First, 36 for the Second and 2.5 for the Third.


Can lisp look like this the next time it is used

First Top Offset distance or <.875>:
Second top offset distance or <36>:
Third top offset distance or <2.5>: