I do a lot of repetitive tasks in my daily drawings and I’d like to make life easier! I was researching how I could write a lisp to draw a walkway path for a roof. I came across a couple of interesting posts but couldn’t follow the code because of my lack of understanding the language. Can anyone help point me in a direction that I could learn the language?
So what I do is draw a 30” x 30” square (using the rectangle command). Then copy it so there is a 2” gap between them. Then I go back and hatch them with a dot hatch scaled to 96. What I’d like to do is type a command and it would draw the walkways for me and hatch them if possible. The problem is the last one is a custom cut size depending on the length of the walkway run?
Now I know I can draw a line, draw the square, hatch the square, array it on the path with set distance between items, then fix the last one so it looks the way I want it to, and then delete the line. But why do all that when I have a program that allows me to customize it to be done for me?
Any help would be greatly appreciated and I’m looking to learn so I can create more on my own and maybe someday help somebody new like me! Thanks in Advance!
Also I've attached a sketch of what I am kind of looking for?
I believe I did this right? Let me know if it doesn't work. I've drawn in the walkway pads for location and I'm hopeful I've explained it well enough to understand my intent?
Michael , you did it rigth, a DWG serve as source to make a LISP.
I full understand your need.
Let me see the DWG , to know if I need further info.
Thanks.
@Anonymous wrote:
.... I was researching how I could write a lisp to draw a walkway path for a roof. ....
So what I do is draw a 30” x 30” square (using the rectangle command). Then copy it so there is a 2” gap between them. Then I go back and hatch them with a dot hatch scaled to 96. What I’d like to do is type a command and it would draw the walkways for me and hatch them if possible. The problem is the last one is a custom cut size depending on the length of the walkway run?
....
I draw those too, sometimes, so I can use such a thing. Give this a try:
(defun C:RWW ; = Roof Walk-Way (/ *error* pt1 pt2 len ang angl angr len qua pad) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break")) (princ (strcat "\nError: " errmsg)) ); end if (setvar 'snapbase snapb) (setvar 'osmode osm) (setvar 'blipmode blipm) (command "_.undo" "_end") (setvar 'cmdecho cmde) (princ) ); end defun - *error* (setq cmde (getvar 'cmdecho) osm (getvar 'osmode) blipm (getvar 'blipmode) snapb (getvar 'snapbase) ); setq (setvar 'cmdecho 0) (command "_.undo" "_begin") (setq pt1 (getpoint "\nOne end of walkway center-line [including end gaps]: ") pt2 (getpoint pt1 "\nOther end: ") ang (angle pt1 pt2) angl (+ ang (/ pi 2)); leftward from path direction angr (- ang (/ pi 2)); rightward pt1 (polar pt1 ang 2); replace w/ starting edge of first pad [after 1st gap] len (distance pt1 pt2); including one gap per pad qua (fix (/ len 32)); quantity of full-size squares inc 0 ); setq (setvar 'snapbase (reverse (cdr (reverse pt1)))) ; for consistent Hatch positioning [must be XY only] (setvar 'osmode 0) (setvar 'blipmode 0) (command "_.pline" (polar pt1 angr 15) (polar (getvar 'lastpoint) ang 30) (polar (getvar 'lastpoint) angl 30) (polar pt1 angl 15) "_close" "_.hatch" "dots" 96 (angtos ang) "_last" "" ); command (setq pad (ssget "_P"); Polyline square pad (ssadd (entlast) pad); Hatch ); setq (repeat (1- qua) (command "_.copy" pad "" pt1 (polar pt1 ang (* 32 (setq inc (1+ inc))))) ); repeat (setq pt1 (polar pt1 ang (* qua 32)) pt2 (polar pt2 (+ ang pi) 2) ); setq (setvar 'snapbase (reverse (cdr (reverse pt1)))); again (if (> (- len (* qua 32) 2) 0); partial pad yet to draw (command ; then "_.pline" (polar pt1 angr 15) (polar pt2 angr 15) (polar pt2 angl 15) (polar pt1 angl 15) "_close" "_.hatch" "dots" 96 (angtos ang) "_last" "" ); command ); if (setvar 'snapbase snapb) (setvar 'osmode osm) (setvar 'blipmode blipm) (command "_.undo" "_end") (setvar 'cmdecho cmde) (princ) ); defun
Limited testing, but it seems to work. It could perhaps also use Layer controls, and some other little stuff. Consider also whether to use a Block for the full-size pad, and Minsert to put the full-size ones in [big memory-saver!] -- I may convert it to that approach for my own use, later.
If the overall run length is up to 4" longer than a series of full pads, it leaves a gap at the end of that whole more-than-2" leftover space -- otherwise in the case of exactly 4" overage, it would be a 2" gap after the last pad, a zero-length "pad" and the final 2" gap. Some possible compensation could be made for that, if that's not good [shorten the first pad, too, or something].
@Anonymous wrote:
Just a little testing but this worked great! I did change it so that the hatch pattern would show on my hatch layer. I understood a good portion of your code and am constantly amazed at how guys like you can just throw something together like this!
I'm glad it works for you, but here's the MINSERTing version I speculated about before. It uses less memory, and it's detectably faster for paths of any length. Also, it handles System Variable settings in a collective sort of way, and correctly handles a total path length shorter than one full pad, for short connecting bits, which the previous version didn't. [And the previous one didn't have a completely correct localized variables list.]
;; RoofWalkWay.lsp [command name: RWW] ;; To draw a straight-run Roof WalkWay of 30" square pads and 2" gaps ;; between them and at ends of specified run. Minserts full pad(s) if any, ;; and draws final partial pad separately if needed. ;; Kent Cooper, last edited 7 January 2014 (defun C:RWW ; = Roof Walk-Way (/ *error* cmde svnames svvals pt1 pt2 ang angl angr len qua) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break")) (prompt (strcat "\nError: " errmsg)) ); end if (mapcar 'setvar svnames svvals) (command "_.undo" "_end") (setvar 'cmdecho cmde) (princ) ); end defun - *error* (setq cmde (getvar 'cmdecho) ; separate from others so changing others can be inside Undo begin/end svnames '(osmode blipmode snapbase) svvals (mapcar 'getvar svnames) ); setq (setvar 'cmdecho 0); suppress following, before changing other SysVars (command "_.undo" "_begin") (setq pt1 (getpoint "\nOne end of walkway center-line [including end gaps]: ") pt2 (getpoint pt1 "\nOther end: ") ang (angle pt1 pt2) angl (+ ang (/ pi 2)); leftward from path direction angr (- ang (/ pi 2)); rightward pt1 (polar pt1 ang 2); replace w/ starting edge of first pad [after 1st gap] len (distance pt1 pt2); including one gap per pad qua (fix (/ len 32)); quantity of full-size squares ); setq (mapcar 'setvar svnames (list 0 0 (reverse (cdr (reverse pt1))))) ; Osnap & Blips off, ; snapbase for symmetrical Hatch positioning [must be XY only] (if (not (tblsearch "block" "RoofWalkWayPad")) (command ; then -- make Block [at 0-degree orientation] "_.pline" (polar pt1 (* pi 1.5) 15) (polar (getvar 'lastpoint) 0 30) (polar (getvar 'lastpoint) (/ pi 2) 30) (polar pt1 (/ pi 2) 15) "_close" "_.hatch" "dots" 96 0 "_last" "" "_.block" "RoofWalkWayPad" pt1 "_previous" "_last" "" ); command ); if (if (> qua 0) ; at least one full pad (command "_.minsert" "RoofWalkWayPad" pt1 "" "" (angtos ang) 1 qua 32) ); if (setq pt1 (polar pt1 ang (* qua 32)) ; for possible partial end pad, after full pads & gaps pt2 (polar pt2 (+ ang pi) 2); back off for final end gap ); setq (setvar 'snapbase (reverse (cdr (reverse pt1)))); again (if (> (- len (* qua 32) 2) 0); partial pad yet to draw (command ; then "_.pline" (polar pt1 angr 15) (polar pt2 angr 15) (polar pt2 angl 15) (polar pt1 angl 15) "_close" "_.hatch" "dots" 96 (angtos ang) "_last" "" ); command ); if (mapcar 'setvar svnames svvals) (command "_.undo" "_end") (setvar 'cmdecho cmde) (princ) ); defun
Again, add your own Layer control.