TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Artisan on October 15, 2004, 01:44:16 PM

Title: Copy Rotate Lisp help.
Post by: Artisan on October 15, 2004, 01:44:16 PM
I am having trouble with my lisp routine for a copy then rotate command I use. When I select the object to copy, it copies the object, allows me to place the copy where I need it and then when it rotates, it will rotate the original object instead of the copy. Here's the routine:

(DEFUN C:cR (/ SS P1 P2)
(PRINC "\nSelect objects Rob :")
(setq ss (ssget))
(if ss (progn
(setq P1 (getpoint "Basepoint :"))
(setq P2 (getpoint "Destination :"))
(command "COPY" ss "" P1 P2 "")
(command "rotate" ss "" P2)
) )
)
Title: Copy Rotate Lisp help.
Post by: M-dub on October 15, 2004, 01:50:27 PM
Here's the one I use...

Code: [Select]
;;COPYROT.LSP Copyright 1998 HyperPics all rights reserved
;;
;;  Author:  Lee Ambrosius,
;;                HyperPics
;;              http://members.aol.com/HyperPics/Home.html          

;;COPYROT is a command to allow you to copy an object and then do
;;a rotate right after it. Once loaded just type in COPYROT to activate
;;the command.  

;;This is a great file to place inside of your ACAD.lsp file or use
;;it by itself.

;;  All documentation must stay with this Lips routine though.

;; Find and give me the Group nams in a lists
;; First string in list will be the last group created
(defun newgroups (/ GRPS OD GRP1 CHCKR GRPS GNAME)
  (setq OD (namedobjdict))
  (setq GRPS (dictnext OD "acad_group"))
  (while (/= CHCKR 3)
    (setq GRP1 (car GRPS))
    (setq GRPS (cdr GRPS))
    (setq chckr (car GRP1))
    (if (= chckr 3)
      (progn
        (setq NGROUPS (list (cdr GRP1)))
      )
    )
  )
  (while (/= GRPS nil)
    (setq GRP1 (car GRPS))
    (setq GRPS (cdr GRPS))
    (setq chckr (car GRP1))
    (if (= chckr 3)
      (progn
        (setq GNAME (cdr GRP1))
        (setq NGROUPS (cons GNAME NGROUPS))
      )
    )
  )
  (setq EXGNAME (car NGROUPS))
)

;;Error Tile
(defun MYERROR (S)
  (if (/= S "\nFunction cancelled" )
  (princ "\nEnding Copy Rotate..." ))  
  (command "-group" "e" "copier")
  (command "undo" "end")
  (command "u" "u")
  (setvar "CMDECHO" CMD)
  (setq *ERROR* OLDERR )
  (princ)
)

;; Main section of Copy Rotate
(defun c:COPYROT (/ SS1 PT1 PT2)
  (setq SS1 nil)
  (setq CMD (getvar "CMDECHO"))
  (setq OLDERR *ERROR*)
  (setq *ERROR* MYERROR)
  (command "undo" "begin")
  (setvar "CMDECHO" 0)
  (prompt "\nSelect Objects to Copy-Rotate: ")
  (setq SS1 (ssget))
  (command "-group" "" "copier" "" SS1 "")
  (setq PT1 (getpoint "\nFirst Point of displacement: "))
  (prompt "\Second Point of Displacment: ")
  (command "._copy" "g" "copier" "" PT1 pause)
  (setq PT2 (getvar "LASTPOINT"))
  (prompt "\nSelect Angle of Rotation: ")
  (command "._rotate" "last" "" PT2 pause)
  (command "-group" "e" "copier")
  (newgroups)
  (command "-group" "e" EXGNAME)
  (command "undo" "end")
  (setvar "CMDECHO" CMD)
  (redraw)
  (prompt "\nCopy Rotate complete....")
 (princ)
) ;; End of Copy Rotate
(c:COPYROT)
Title: Copy Rotate Lisp help.
Post by: ELOQUINTET on October 15, 2004, 01:57:59 PM
i got this one from someone here i think which contains both move and copy rotate

Code: [Select]
(defun c:mr  () (b-cmr "M")(princ))
(defun c:cr  () (b-cmr "C")(princ))
;***************************************************************************
; File         : mcr.lsp
; Date         : 20-9-03
; Function     : (B-CMR <MODE>)
; Purpose      : Copy+Rotate or Move+Rotate
; Arguments    : <MODE> = "C" -> Copy-rotate
;                       = "M" -> Move-rotate
; Written by   : J.J.Damstra
;***************************************************************************
(defun b-cmr (typ / ss1 temp p0 p1)
   (setq ss1 (ssget "I"))

   (command ".undo" "begin")
   (setq temp (getvar "CMDECHO"))(setvar "CMDECHO" 0)

   (if (not ss1)(setq ss1 (ssget)))
   (if ss1
      (progn
         (initget 1)
         (setq p0 (getpoint "\nBasepoint : "))
         
         (if (= typ "C")
            (progn
               (setq p1 (getpoint "\nTranslation or <ENTER>: " p0))
               (if (not p1)(setq p1 p0))
               (command ".copy" ss1 "" "0,0" "0,0")
            )
            (while (not p1)(setq p1 (getpoint "\nTranslation : " p0)))
         )

         (command ".move" ss1 "" p0 p1)
         (command ".rotate" ss1 "" p1 pause)
      )
      (princ "\nMsg> Nothing selected! ")
   )

   (command ".undo" "end")
   (setvar "CMDECHO" temp)
   (princ)
)
Title: Copy Rotate Lisp help.
Post by: Artisan on October 18, 2004, 08:16:44 AM
Ok fellows, I have used the the following routine and I have one problem with it. Now when I open a drawing, the Copy-Rotate command starts as soon as the drawing opens.


(defun c:CR (/ SS1 PT1 PT2)
  (setq SS1 nil)
  (setq CMD (getvar "CMDECHO"))
  (setq OLDERR *ERROR*)
  (setq *ERROR* MYERROR)
  (command "undo" "begin")
  (setvar "CMDECHO" 0)
  (prompt "\nSelect Objects to Copy-Rotate: ")
  (setq SS1 (ssget))
  (command "-group" "" "copier" "" SS1 "")
  (setq PT1 (getpoint "\nFirst Point of displacement: "))
  (prompt "\Second Point of Displacment: ")
  (command "._copy" "g" "copier" "" PT1 pause)
  (setq PT2 (getvar "LASTPOINT"))
  (prompt "\nSelect Angle of Rotation: ")
  (command "._rotate" "last" "" PT2 pause)
  (command "-group" "e" "copier")
  (newgroups)
  (command "-group" "e" EXGNAME)
  (command "undo" "end")
  (setvar "CMDECHO" CMD)
  (redraw)
  (prompt "\nCopy Rotate complete....")
 (princ)
) ;; End of Copy Rotate
(c:Cr)
Title: Copy Rotate Lisp help.
Post by: daron on October 18, 2004, 08:18:46 AM
I believe it's because of (c:Cr) at the end of your code. Remove it or comment it out. ;;;
Title: Copy Rotate Lisp help.
Post by: SMadsen on October 18, 2004, 08:20:07 AM
If the problem is that it runs upon loading then remove the line that invokes the command; the last line (c:CR)
Title: Copy Rotate Lisp help.
Post by: SMadsen on October 18, 2004, 08:20:46 AM
Oh, hi Daron :)
Title: Copy Rotate Lisp help.
Post by: daron on October 18, 2004, 08:21:47 AM
Hey, Stig.
Title: Copy Rotate Lisp help.
Post by: Artisan on October 18, 2004, 11:01:08 AM
Good Deal, that worked. Thanks
Title: Copy Rotate Lisp help.
Post by: Artisan on October 19, 2004, 02:21:10 PM
Ok, new problem now. I am using the lisp routine and all of a sudden I am getting this error:

Command: CR
Select Objects to Copy-Rotate:
Select objects: 1 found

Select objects:
<Selection set: 6>
; error: Function cancelled

Anyone seen this?
Title: Copy Rotate Lisp help.
Post by: CAB on October 19, 2004, 03:01:16 PM
How about this?
Code: [Select]
;;  Copy Rotate a selection set
(defun c:cr (/ usercmd ss1 pt1)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "undo" "begin")
  (prompt "\nSelect Objects to Copy-Rotate: ")
  (if (and (setq ss1 (ssget))
           (> (sslength ss1) 0)
           (setq pt1 (getpoint "\nFirst Point of displacement: "))
      )
    (progn
      (prompt "\Second Point of Displacment: ")
      (command "._copybase" pt1 ss1 "")
      (command "._pasteclip" pt1); replace originals
      (command "._move" ss1 "" pt1 pause)
      (prompt "\nSelect Angle of Rotation: ")
      (command "._rotate" ss1 "" (getvar "LASTPOINT") pause)
      (prompt "\nCopy Rotate complete....")
    )
    (prompt "\nUser Quit....")
  )
  (command "undo" "end")
  (setvar "CMDECHO" usercmd)
  (princ)
)
Title: Copy Rotate Lisp help.
Post by: Artisan on October 19, 2004, 03:26:31 PM
Good deal, it works for the time being. Thanks