Beginner Question - "command"
Hello,At this point, I'm just trying to automate some routine tasks for reliability, so mostly using the "command" function in AutoLISP.This routine is just intended to shift/rotate/scale from UTM to a local plant grid (a simple three-parameter conversion).
My confusion is that the lines of code work fine individually, but not within the program itself (it creates the selection set just fine, but crashes on the 'move' line).Am I missing something basic and obvious?Or is the entire approach, mimicking a manual conversion, flawed?
Thank you for your help & insight!
(defun c:UTM2KFS()(setq sel1 (ssget "P"))(command "move" "!sel1" "" "357351.181,5957636.884" "5000,1000")(command "rotate" "P" "" "5000,1000" "-3d24'54"")(command "scale" "P" "" "5000,1000" "1.00024606053") (princ)) I don't know what you are after but try this modification on the code and let me know .
(defun c:UTM2KFS (/ ss i) (if (setq ss (ssget "P")) (repeat (setq i (sslength ss)) (command "_.move" (ssname ss (setq i (1- i))) "" "357351.181,5957636.884" "5000,1000" ) (command "_.rotate" "P" "" "5000,1000" "-3d24'54") (command "_.scale" "P" "" "5000,1000" "1.00024606053") ) ) (princ)) I hope the following comments help:
(defun c:UTM2KFS ( / sel1 ) ;; Define function, declare local variables. ;; To understand why variable localisation is important, see http://bit.ly/15Qw104 (if ;; If the following expression returns a non-nil value (setq sel1 (ssget "_P")) ;; Attempt to retrieve the Previous selection set and ;; assign the selection set to the local variable 'sel1' ;; For a full ssget function reference, see http://bit.ly/137NmOJ ;; The following command expression is the THEN argument for the IF function: (command ;; Issue the following to the AutoCAD command-line "_.move" ;; Start the Move command. ;; See http://bit.ly/18cyqA3 for the meaning of the command prefixes sel1 ;; Supply the move command with the selection set assigned to local variable sel1 ;; The variable symbol will be evaluated as an argument for the command function, ;; yielding the selection set value. "" ;; Accept the selection (ENTER) "_non" ;; Ignore Object Snap for the next prompt (_non = None) '(357351.181 5957636.884) ;; Pass the base point "_non" ;; Ignore Object Snap '(5000 1000) ;; Pass the displacement point "_.rotate" ;; Start the Rotate command. ;; (There is no need for a separate command expression) sel1 ;; Pass the same selection set of objects "" ;; Accept the selection "_non" ;; Ignore Object Snap '(5000 1000) ;; Pass the base point 3.415 ;; Pass the rotation angle (in degrees) "_.scale" ;; Start the Scale command ;; (Again, no need for a separate command expression) sel1 ;; Pass the same selection set of objects "" ;; Accept the selection "_non" ;; Ignore Object Snap '(5000 1000) ;; Pass the base point 1.00024606053 ;; Pass the scale factor ) ;; end COMMAND ;; The following expression is the ELSE argument for the IF function: (princ "\nNo previous selection.") ;; Notify the user that no previous selection set is available ) ;; end IF (princ) ;; Suppress the return of the last evaluated expression ) ;; end DEFUN Ah if only we could give kudos on this forum, I would have given them in this one.
Commenting like this is so helpful for more than just the one user who is attempting the now-commented routine, I personally enjoy and spend more time with any lisp that is commented like this just in order to see how the functions work together in their lisp-required manner. There will be no Lee Mac "Code Commenting Routine" as I'm pretty sure that real time is spent on any of these commented-on lisps and just wanted to throw my appreciation out there because these are at the top of the useful-to-learning lisp routines that I can find...
In a nutshell, thanks for this helpful lisp........useful, not by application, but by thoroughness of design. What catches my eye here is that you referred to the selection using an exclamation point (!) prefix.The exclamation point prefix is used at the command line in AutoCAD when you want to retrieve the value of a variable, but it is not used within AutoLISP, not even in the command function. Plus the two strings' marks all around Lee Mac, you're a god!It worked!I'll study up to understand all the details.THANK YOU, THANK YOU, THANK YOU!!! :D:D(Have actually been banging my head against very similar problem off-and-on for more than a year - celebration!I think that'll clear up, too!)THANK YOU! You're very welcome -
I'm glad that the comments help with your understanding and that my time was well invested.
页:
[1]