tricky autolisp copy rutine

tricky autolisp copy rutine

Anonymous
Not applicable
1,055 Views
5 Replies
Message 1 of 6

tricky autolisp copy rutine

Anonymous
Not applicable

Hello. I lost an old lisp database that a friend once gave me and I'm trying to reconstruct it.

The routine was something like this (I don't know how to write it properly, though):

(defun c:CII ()

(Prompt "Copy from intersection to intersection point");inform user

(princ "\nSelect objects to copy")

(setq copy_objects (ssget));;; (first question, if I press enter after not selecting anything, I want to select the previos selected set)

 

(command "copy" copy_objects "" "m" "int" pause (getvar "osmode") (setvar "osmode" 32);(here I don't want the command to execute if I don't hit the exact intersection point and prompt the error if it happens); (setvar "osmode"); this will set the osmode to its status before the command (after the routine it's actually ended).

I'm very confused to make this work, I have only made it by pieces and, when I do something right, it is only to mess up another part.

 

I hope somebody can help me.

 

Thank you so much

0 Likes
Accepted solutions (1)
1,056 Views
5 Replies
Replies (5)
Message 2 of 6

roland.r71
Collaborator
Collaborator

Something like this?

(defun c:CII ( / osmode pt ss)

   ; *copy_objects* : Global var to remember selected objects   
   (prompt "\nCopy from intersection to intersection point\n") ; inform user
(setq ss (ssget)) ; Select objects (setq *copy_objects* (cond (ss)(*copy_objects*))) ; if non use previous (if *copy_objects* ; check if anything selected
(progn
(if (not ss)(sssetfirst nil *copy_objects*)) ; Highlight (previous) selection (setq osmode (getvar "osmode")) ; Store osmode setting
(setvar "osmode" 32) (setq pt (getpoint "Select intersection point")) ; Get intersection point (if (not pt) (princ "\nNo point selected") ; Warn: no point ; else
(command "_.copy" *copy_objects* "" "m" "int" pt) ; Copy objects using point ) (setvar "osmode" osmode) ; Restore original osmode ) ) )
Message 3 of 6

ВeekeeCZ
Consultant
Consultant

Little different version from @roland.r71's, especially the copy part.

 

(defun c:CII ( / *error* osm ss)
  
  (defun *error* (errmsg) ;; just in case you hit ESC to exit the copy command to return origin osmode
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'osmode osm))  
  
  (prompt "\nCopy from intersection to intersection point")
  (princ "\nSelect objects <previous selection>: ")
  
  (setq osm (getvar 'osmode))
  (setvar 'osmode 32)
  
  (if (setq ss (cond ((ssget))
                     ((ssget "_p"))))
    (command-s "_.copy" ss "" "_m"))
  
  (setvar 'osmode osm)
  (princ)
  )
Message 4 of 6

roland.r71
Collaborator
Collaborator

The error trap is a must have adition in this case, which I forgot to add.  Smiley Sad

Messing up snap settings in case of ESC should of course be prevented

Message 5 of 6

Anonymous
Not applicable
Accepted solution

Thank you so much. I'll try it and let you know how it went

0 Likes
Message 6 of 6

Anonymous
Not applicable

Got it, you guys have been very helpful. Thanks

0 Likes