Move in x or y only issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been using several Lisp macros for well over a decade to move or copy in a chosen x, y, or z direction only. Recently, the X copy and X move ones have not been functioning consistently. I'm posting for two reasons. First, is there a better way to snap only in a particular direction, and/or, second, is there a better macro out there for my needs?
I personally don't often use the extended autosnap tools or dynamic input that allow you work only in one direction, etc., simply because I have all the transparent snaps (and select macros and symbols) programmed into my keyboard (i.e., a embedded function call in a single key stroke that enters a series of keystrokes: "_from + enter", "end + enter", ".xy + enter", "_m2p + enter", "\u+2205", etc.). Many of my work collogues over the years have asked if I could show them how to use these functions after watching me work, and I've learned to defer to our firms CAD manager, who, I know, will simply remind them of the firms "no third party macros" and tell them to be a good boy or girl and get back to work (they stopped cleaning out my personal macros years ago after I successfully argued that the uninstalling and reinstalling of my macros just wasted the company money, or else they should just fire me...). While I myself will watch my colleagues work intuitively with the improved selection tools AutoCAD has offered over the years, and think, maybe I should learn to use those better. That is, say, until I'm watching someone trying desperately to snap to a particular line, and you remind them they can just enter "per" and it will stop grabbing the d*mn end of the vector... Often it's so much better to have instantaneous old-fashion simple absolute control.
The directional move and copy macros all work just fine when you enter a distance and the error only happens when you pick a second point.
Here's the error that comes up with the CopyX macro:
Command: cx
CopyX
Select objects: 1 found
Select objects:
Base X point of copy <(0)> end
of end
of ; error: bad argument type: lselsetp nil
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Here's the Lisp program:
; CX -- CopyX.lsp -- Copies objects in xy direction only -------------
;function to save system variable settings----------------------------------
(defun GETMODE (mod1)
(setq *mod2 '()) ;create global variable to store settings
(repeat (length mod1) ;find length of variable list and repeat
(setq *mod2 ;build *mod2 list
(append *mod2
(list (list (car mod1) (getvar (car mod1))))
)
)
(setq mod1 (cdr mod1)) ;go to next element in list
);end repeat
)
;function to restore system variable settings-------------------------------
(defun SETMODE (mod1)
(repeat (length mod1) ;find length of list and repeat
(setvar (caar mod1) (cadar mod1)) ;extract setting info and reset
(setq mod1 (cdr mod1)) ;go to next element in list
);end repeat
)
;function for error trap ---------------------------------------------------
(defun *error* (msg)
(setmode *mod2) ;reset system variables
(princ msg) ;print error message
(princ)
)
;CXY -- primary function--------------------------
(defun c:CX (/
Oblist ;list of objects
Y Z ;x & z coordinates for appending filter list
Ex-Xpt ;global variable for old elevation
;*New-Xpt global variable for new elevation
New-Xpt-Tmp ;temporary assingnment of *New-Xpt for selction
Ex-Xpt-Tmp ;temporary assingnment of Ex-Xpt for selction
Ex-X ;y component of Ex-Xpt
Ex-Y ;y component of Ex-Xpt
Ex-Z ;y component of Ex-Xpt
New-X ;y component of *New-Xpt
New-Y ;y component of *New-Xpt
New-Z ;y component of *New-Xpt
TstX
)
(getmode '("osmode" "orthomode" "cmdecho")) ;saves system var.
(mapcar 'setvar '("osmode" "orthomode" "cmdecho") ;set var for funct.
'(0 0 0 )
)
(princ "\nCopyX")
(setq ObList (ssget))
(setq Y (list 0))
(setq Z (list 0))
(setq Ex-Xpt (list 0))
(setq Ex-Xpt-Tmp (list 0))
(if (or (= *New-Xpt nil) (= (type *New-Xpt) 'STR))
(setq *New-Xpt (list 0))
)
(setq TstY nil)
(princ "\nBase X point of copy <")
(princ Ex-Xpt)
(princ "> ")
(initget 128)
(setq Ex-Xpt (getpoint))
(if (= Ex-Xpt nil)
(setq Ex-Xpt Ex-Xpt-Tmp)
)
(if (= (type Ex-Xpt) 'STR)
(setq Ex-X (distof (car Ex-Xpt) 4))
(progn
(setq Ex-X (car Ex-Xpt))
(setq Ex-Y (cadr Ex-Xpt))
(setq Ex-Z (caddr Ex-Xpt))
)
)
(if (= Ex-Y nil)
(setq TstY "Yes")
)
(if (= TstY "Yes")
(progn
(setq Ex-Xpt (list 0 0 0))
(setq New-Xpt-Tmp *New-Xpt)
(setq New-X (car *New-Xpt))
(princ "\nEnter new X component of displacement <")
(princ *New-Xpt)
(princ "> ")
(initget 128)
(setq *New-Xpt (getpoint))
(if (= (type *New-Xpt) 'STR)
(progn
(setq New-X (distof *New-Xpt 4))
(setq *New-Xpt (append (list New-X) Y Z))
)
)
(if (= *New-Xpt nil)
(setq *New-Xpt New-Xpt-Tmp)
)
(command "copy" ObList "" Ex-Xpt *New-Xpt)
) ;end progn
) ;end TstY if
(if (/= TstY "Yes")
(progn
(setq ent (entlast))
(command "copy" ObList "" Ex-Xpt pause)
(setq Tmp-Xpt (getvar "lastpoint"))
(setq New-X (car Tmp-Xpt))
(setq New-Y (cadr Tmp-Xpt))
(setq *New-Xpt (append (list New-X) (list Ex-Y) (list Ex-Z)))
(setvar "osmode" 0)
(setq Oblist (ssadd))
(while (setq ent (entnext ent))
(if ent
(setq Oblist (ssadd ent Oblist))
)
)
(command "move" ObList "" Tmp-Xpt *New-Xpt)
) ;end progn
) ;end TstY if
(setq *New-Xpt (append (list (- New-X Ex-X)) Y Z))
(princ "Copy done")
(setmode *mod2)
(princ)
) ; end CX.lsp