Jump to content

Recommended Posts

Posted (edited)

Hi all, good day.

 

I have this script below which copies along the x and y axis with two separate commands. CX and CY.

 

2 issues.

 

 

  1. I need it to regen every time I copy (There's a bug when I copy leaders at the moment) (command ".regen") has no effect.
  2. Copy multiple, After first copy the restraint no longer take effect.

 

Thanks for any help.

 

;;----------------------------------------------------------------------;;

(defun c:CX ()
   (setq ss (ssget))
   (command "._copy" ss "" "M" pause ".yz" "@" pause)
   (command ".regen")
   (setq ss nil);; add this line to clean the selection
   (princ)

)

(defun c:CY ()
   (setq ss (ssget))
   (command "._copy" ss "" "M" pause ".xz" "@" pause)
   (command ".regen")
   (setq ss nil);; add this line to clean the selection
   (princ)
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
   (strcat
       "\n:: Lock_Copy_X&Y.lsp loaded ::"
       "\n:: Invoke by typing 'CX' (Copy on X-axis) or 'CY' (Copy on Y-axis) ::"
   )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

 

GOT IT ANSWERED HERE (POST NO.4) by Roy_043:

http://www.cadtutor.net/forum/showthread.php?94798-Copy-on-X-axis-only-and-Y-axis-only&p=699099&viewfull=1#post699099

Edited by 3dwannab
  • 2 years later...
Posted

Just giving this a little bump :) Thanks.

Posted

Hit you in the face message

 

(Alert  ":: Lock_Copy_X&Y.lsp loaded ::\n\n\n:: Invoke by typing 'CX' (Copy on X-axis) or 'CY' (Copy on Y-axis) ::" )

 

2nd suggestion

(defun c:CX ( / ss) this localises ss so no need for set nil

 

If this is something your doing a lot you could use a smart reactor I would just type x100 it would then ask for objects and move accordingly type any number after the X x234 x45-6 there is a reason for 45-6 as the period causes an error in the routine.

 

; Enter the filet radius as part of a command line entry f100 offset O234 circle c123-45 
; note - is used for decimal point
; original code and methology by Alan H
; assistance and code that worked by Lee-Mac
; OCT 2015

( (lambda nil
(vl-load-com)
(foreach obj (cdar (vlr-reactors :vlr-command-reactor))
(if (= "fillet-reactor" (vlr-data obj))
(vlr-remove obj)
)
)
(vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
)
)
(defun filletrad ( / rad)
(setq rad (distof (substr com 2) 2))
(if (<= 0.0 rad)
(progn 
(setvar 'filletrad rad)
(vla-sendcommand fillet-reactor-acdoc "_.fillet ")
)
) 
)
(defun makecirc ( / rad radd)
(setq rad (distof (substr com 2) 2))
(if (<= 0.0 rad)
(progn 
(setvar 'circlerad rad)
(setq pt (getpoint "Pick centre pt")) 
(vla-sendcommand fillet-reactor-acdoc "_.Circle !pt ") 
)
)
)
(defun offdist ( / dist)
(setq dist (distof (substr com 2) 2))
(if (<= 0.0 dist)
(progn 
(setvar 'offsetdist dist)
(vla-sendcommand fillet-reactor-acdoc "_.Offset ")
)
)
)
(defun pipeoff ( / dist)
(setq dist (distof (substr com 2) 2))
(if (<= 0.0 dist)
(progn
(setq poff (strcat "P" (rtos dist 2 0)))
(if (not poff)(load "Pipe offsets"))
(vla-sendcommand fillet-reactor-acdoc poff)
)
)
)
(defun projopen ( / Proj year)
(setq year (atoi (substr com 2 4)))
(if (< year 2014) 
(setq projno (strcat "EXPLORER \\\\cogg.local\\fs\\LCFC3\\DESIGN\\DATA\\" (substr com 2 4) " Projects\\" (substr com 2) "[url="file://\\Design\\"]\\Design\\[/url]"))
(setq projno (strcat "EXPLORER P:\\" (rtos year 2 0) " Projects\\" (substr com 2) "[url="file://\\Design\\"]\\Design\\[/url]")) 
)
(vla-sendcommand fillet-reactor-acdoc (STARTAPP projno)) 
)

(defun fillet-reactor-callback ( obj com )
(setq com (vl-string-translate "-" "." (strcase (car com))))
(cond 
( (and
(wcmatch com "~*[~F.0-9]*")
(wcmatch com "F*")
(wcmatch com "~F*F*")
(wcmatch com "~*.*.*")
) ; and
(filletrad) 
) 
( (and
(wcmatch com "~*[~C.0-9]*")
(wcmatch com "C*")
(wcmatch com "~C*C*")
(wcmatch com "~*.*.*")
) ;and
(makecirc) 
)
( (and
(wcmatch com "~*[~O.0-9]*")
(wcmatch com "O*")
(wcmatch com "~O*O*")
(wcmatch com "~*.*.*")
) ; and
(offdist) 
)
( (and
(wcmatch com "~*[~D.0-9]*")
(wcmatch com "D*")
(wcmatch com "~D*D*")
(wcmatch com "~*.*.*")
) ; and
(projopen) 
)
( (and
(wcmatch com "~*[~P.0-9]*")
(wcmatch com "P*")
(wcmatch com "~P*P*")
(wcmatch com "~*.*.*")
) ; and
(pipeoff) 
)
) ; master cond
) ; defun
(or fillet-reactor-acdoc
(setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)

Posted

When using the _Multiple option of the _Copy command you obviously cannot rely on a fixed number of arguments for the command function.

(defun c:test ( / ss)
 (setq ss (ssget))
 (command "._copy" ss "" "_multiple" pause)
 (while (/= 0 (getvar 'cmdactive))
   (command ".yz" "@" pause)
 )
 (princ)
)

Posted

why not use the copy command normally with ortho mode on?

Posted
why not use the copy command normally with ortho mode on?

Because see this. I have so many uses for it. Try snapping perpendicular to a point in x or y.

 

Why did AD add-in a point filters for x, y & z if they didn't want us to use it?

 

This is why.gif

 

When using the _Multiple option of the _Copy command you obviously cannot rely on a fixed number of arguments for the command function.

(defun c:test ( / ss)
 (setq ss (ssget))
 (command "._copy" ss "" "_multiple" pause)
 (while (/= 0 (getvar 'cmdactive))
   (command ".yz" "@" pause)
 )
 (princ)
)

 

This worked absolutly perfect. Thank you. Neat trick with the while. I'll keep this in mind.

 

Hit you in the face message

 

(Alert  ":: Lock_Copy_X&Y.lsp loaded ::\n\n\n:: Invoke by typing 'CX' (Copy on X-axis) or 'CY' (Copy on Y-axis) ::" )

 

2nd suggestion

(defun c:CX ( / ss) this localises ss so no need for set nil

 

If this is something your doing a lot you could use a smart reactor I would just type x100 it would then ask for objects and move accordingly type any number after the X x234 x45-6 there is a reason for 45-6 as the period causes an error in the routine.

 

; Enter the filet radius as part of a command line entry f100 offset O234 circle c123-45 
; note - is used for decimal point
; original code and methology by Alan H
; assistance and code that worked by Lee-Mac
; OCT 2015

( (lambda nil
(vl-load-com)
(foreach obj (cdar (vlr-reactors :vlr-command-reactor))
(if (= "fillet-reactor" (vlr-data obj))
(vlr-remove obj)
)
)
(vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
)
)
(defun filletrad ( / rad)
(setq rad (distof (substr com 2) 2))
(if (<= 0.0 rad)
(progn 
(setvar 'filletrad rad)
(vla-sendcommand fillet-reactor-acdoc "_.fillet ")
)
) 
)
(defun makecirc ( / rad radd)
(setq rad (distof (substr com 2) 2))
(if (<= 0.0 rad)
(progn 
(setvar 'circlerad rad)
(setq pt (getpoint "Pick centre pt")) 
(vla-sendcommand fillet-reactor-acdoc "_.Circle !pt ") 
)
)
)
(defun offdist ( / dist)
(setq dist (distof (substr com 2) 2))
(if (<= 0.0 dist)
(progn 
(setvar 'offsetdist dist)
(vla-sendcommand fillet-reactor-acdoc "_.Offset ")
)
)
)
(defun pipeoff ( / dist)
(setq dist (distof (substr com 2) 2))
(if (<= 0.0 dist)
(progn
(setq poff (strcat "P" (rtos dist 2 0)))
(if (not poff)(load "Pipe offsets"))
(vla-sendcommand fillet-reactor-acdoc poff)
)
)
)
(defun projopen ( / Proj year)
(setq year (atoi (substr com 2 4)))
(if (< year 2014) 
(setq projno (strcat "EXPLORER \\\\cogg.local\\fs\\LCFC3\\DESIGN\\DATA\\" (substr com 2 4) " Projects\\" (substr com 2) "[url="file://\\Design\\"]\\Design\\[/url]"))
(setq projno (strcat "EXPLORER P:\\" (rtos year 2 0) " Projects\\" (substr com 2) "[url="file://\\Design\\"]\\Design\\[/url]")) 
)
(vla-sendcommand fillet-reactor-acdoc (STARTAPP projno)) 
)

(defun fillet-reactor-callback ( obj com )
(setq com (vl-string-translate "-" "." (strcase (car com))))
(cond 
( (and
(wcmatch com "~*[~F.0-9]*")
(wcmatch com "F*")
(wcmatch com "~F*F*")
(wcmatch com "~*.*.*")
) ; and
(filletrad) 
) 
( (and
(wcmatch com "~*[~C.0-9]*")
(wcmatch com "C*")
(wcmatch com "~C*C*")
(wcmatch com "~*.*.*")
) ;and
(makecirc) 
)
( (and
(wcmatch com "~*[~O.0-9]*")
(wcmatch com "O*")
(wcmatch com "~O*O*")
(wcmatch com "~*.*.*")
) ; and
(offdist) 
)
( (and
(wcmatch com "~*[~D.0-9]*")
(wcmatch com "D*")
(wcmatch com "~D*D*")
(wcmatch com "~*.*.*")
) ; and
(projopen) 
)
( (and
(wcmatch com "~*[~P.0-9]*")
(wcmatch com "P*")
(wcmatch com "~P*P*")
(wcmatch com "~*.*.*")
) ; and
(pipeoff) 
)
) ; master cond
) ; defun
(or fillet-reactor-acdoc
(setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)

Thanks. I didn't look into reactor as Roy_043 anwswered. Thanks :)

 

Here's my CX and CY command. Thanks again Roy_043.

;;----------------------------------------------------------------------;;

; Answer on how to fix multiple copy by Roy_043 14.03.2018: http://www.cadtutor.net/forum/showthread.php?94798-Copy-on-X-axis-only-and-Y-axis-only&p=699099&viewfull=1#post699099
; Credit to Roy_043

(defun c:CX ( / ss)
 (setq ss (ssget))
 (command "._copy" ss "" "_multiple" pause)
 (while (/= 0 (getvar 'cmdactive))
   (command ".yz" "@" pause)
 )
 (princ)
)

(defun c:CY ( / ss)
 (setq ss (ssget))
 (command "._copy" ss "" "_multiple" pause)
 (while (/= 0 (getvar 'cmdactive))
   (command ".xz" "@" pause)
 )
 (princ)
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
   (strcat
       "\n:: Lock_Copy_X&Y.lsp loaded ::"
       "\n:: Invoke by typing 'CX' (Copy on X-axis) or 'CY' (Copy on Y-axis) ::"
   )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

  • 4 weeks later...
Posted

Great Lisp!

 

I just started to started studying autolisp programming, I'll try to modify including "CZ" function and "CXY", "CXZ", "CYZ".

Do you think that it'll work also for the move just replacing the _copy with _move?

 

Thanks a lot!

Posted

Here's my move LISP.

 

;;----------------------------------------------------------------------;;

(defun c:MX ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(setq ss (ssget))
(command "._move" ss "" pause ".yz" "@" pause)
(setq ss nil)

(*error* nil)
(princ)
)
(defun c:MY ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(setq ss (ssget))
(command "._move" ss "" pause ".xz" "@" pause)
(setq ss nil)

(*error* nil)
(princ)
)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
	(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
	(princ (strcat "\n<< Error: " errmsg " >>"))
	)
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

(defun SS:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
)

(vl-load-com)

(princ
(strcat
	"\nLock_Move_X&Y.lsp loaded"
	"\nInvoke by typing 'MX' (Move on X-axis) or 'MY' (Move on Y-axis)"
	)
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

Posted (edited)

Here's my stretch one with other goodies in there.

; Stretch All X
(defun c:SX ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget))
		)
	(if ss
		(progn
			(command "._stretch" ss "" PAUSE ".yz" "@")
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)
)

; Stretch All Y
(defun c:SY ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget))
		)
	(if ss
		(progn
			(command "._stretch" ss "" PAUSE ".xz" "@")
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

; Stretch All MLeaders
(defun c:SL ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget '((0 . "MULTILEADER"))))
		)
	(if ss
		(progn
			(command "_.stretch" ss "" "_non" PAUSE "_non" PAUSE)
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

; Stretch All Leaders X
(defun c:SLX ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget '((0 . "MULTILEADER"))))
		)
	(if ss
		(progn
			(command "._stretch" ss "" PAUSE ".yz" "@")
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

; Stretch All Leaders Y
(defun c:SLY ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget '((0 . "MULTILEADER"))))
		)
	(if ss
		(progn
			(command "._stretch" ss "" PAUSE ".xz" "@")
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

; Stretch Important
(defun c:SIM ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget '((0 . "~HATCH") (0 . "~TEXT") (0 . "~MTEXT") (8 . "~*text") (8 . "~*note") (8 . "~*dim"))))
		)
	(if ss
		(progn
			(command "_.stretch" ss "" PAUSE PAUSE)
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

; Stretch dims only
(defun c:SD ( / ss)

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss (last (ssgetfirst)))
	(if (not ss)
		(setq ss (ssget '((0 . "DIMENSION"))))
		)
	(if ss
		(progn
			(command "_.stretch" ss "" PAUSE PAUSE)
			(setq ss nil)
			)
		(princ "\nUser Cancelled Command")
		)
	)

(*error* nil)
(princ)

)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
	(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
	(princ (strcat "\n<< Error: " errmsg " >>"))
	)
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

(defun SS:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
)

(vl-load-com)

(princ
(strcat
	"\n3dwannab_Stretch_Commands.lsp Loaded"
	"\nInvoke by typing 'S*'"
	)
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

Edited by 3dwannab

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...