Jump to content
florida35

LISP Code to Complete NCOPY Command

Recommended Posts

florida35

Hi all,

 

Like my previous post, I am new to lisp routines. I am looking for a command that copies an object from an xref into a current drawing in the exact same location. I know that NCOPY already does this but requires you to answer several prompts before working. I am hoping to find a routine that allows me to just click on a polyline, circle, etc and have it automatically come into my current drawing in the exact same spot as the xref. Thanks.

 

 

 

Jim

Share this post


Link to post
Share on other sites
Lee Mac

The easiest way (without re-inventing the wheel) would be to automate the prompts for the NCOPY command, e.g.:

(defun c:nc nil
   (command "_.ncopy" "\\" "" "_non" '(0 0) "_non" '(0 0))
   (princ)
)

Share this post


Link to post
Share on other sites
Grrr

I've modified Lee's quick code, to be more friendly :)

(defun c:nc nil
  (while
   (setvar 'errno 0) 
   (command "_.ncopy" "\\" "" "_non" '(0 0) "_non" '(0 0))
     (cond
      ((= (getvar 'errno) 7) (progn (prompt "\nMissed.. Try again!")(c:nc)))
     );cond
  );while
 (princ)
)

Share this post


Link to post
Share on other sites
Lee Mac

(setvar 'errno 0) will always return a non-nil value, therefore there is no exit condition for the while loop (resulting in an infinite loop).

 

progn is not required to enable multiple expressions to be evaluated within a cond statement.

 

Since you are evaluating the c:nc function recursively, the while loop is redundant, as you will enter a new [infinitely-looping] while loop for every recursive call.

 

The code is not testing the value of the ERRNO system variable until the NCOPY command has completed, therefore, the NCOPY command will still be evaluated regardless of whether the user has made a valid selection.

Share this post


Link to post
Share on other sites
Grrr

Thank you Lee for the information, I wasn't quite sure how to handle with this "Missed try again"

I did this for a 2nd try and got different result for NCOPY:

 

(defun c:nc ( / ent)

   (setvar 'errno 0) 
   (setq ent (entsel "\nPick object for NCOPY"))
     (cond
      ((= (getvar 'errno) 7) (prompt "\nMissed.. Try again!")(c:nc))
      (T  (command "_.ncopy" ent "" "_non" '(0 0) "_non" '(0 0)))
     );cond

 (princ)
)

Maybe it needs entsel for the picked object inside block or xref (this is way outta my knowledge).

Share this post


Link to post
Share on other sites
guran

Use NCOPY, click on the object and then press Esc, and you have it in the exact same position.

Share this post


Link to post
Share on other sites
Grrr

Well figured this out, from guran's post, and Lee Mac's help:

(defun c:nc ( / nc-cmd )
   (setq nc-cmd (command "_.ncopy" "\\" (command) ))
     (cond
      ((= nc-cmd nil) (prompt "\nMissed.. Try again!\n")(c:nc))
     );cond
   (princ)
)

Share this post


Link to post
Share on other sites
nod684
Well figured this out, from guran's post, and Lee Mac's help:

(defun c:nc ( / nc-cmd )
   (setq nc-cmd (command "_.ncopy" "\\" (command) ))
     (cond
      ((= nc-cmd nil) (prompt "\nMissed.. Try again!\n")(c:nc))
     );cond
   (princ)
)

 

 

tried this one out. It lets you select objects that you want to "ncopy" simultaneously..

but how do i end/exit the routine?

i tried ENTER but i cannot end the routine unless i press escape.

maybe can further be develop or am i missing something?

Share this post


Link to post
Share on other sites
Lee Mac

The command function will always return nil, therefore the cond expression will cause the function to be evaluated recursively regardless of the user input - the only way to exit would be to force an error using Esc.

Share this post


Link to post
Share on other sites
rkmcswain
Use NCOPY, click on the object and then press Esc, and you have it in the exact same position.

 

THIS ^^^^^^^^^^^ is the answer :)

Share this post


Link to post
Share on other sites
broncos15

Does ncopy act differently than other commands? I have tried passing selections to it and I cannot get it to work properly.

(defun c:ncopy2 (/ *error* whilestop ent oldecho)
 (defun *error* (msg)
   (if oldecho
     (setvar 'cmdecho oldecho)
   )
   (if (not
         (member msg '("Function cancelled" "quit / exit abort"))
       )
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )
 (setq oldecho (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (setq whilestop t)
 (while whilestop
   (setvar 'errno 0)
   (setq ent (entsel "\nSelect nested objects to copy: "))
   (cond
     ((= 52 (getvar 'errno))
      (setq whilestop nil)
     )
     ((null ent)
      (princ "\nYou missed. Try again.")
     )
     ((not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent)))))
                    "INSERT"
           )
      )
      (princ "\nNot a valid object, try again.")
     )
     ;| ((/= (vla-get-IsXref (vlax-ename->vla-object (car ent))))
      (princ "\nNot a valid object, try again.")
     )|;
     (t
      (command "_.ncopy" ent "" "_non" '(0 0) "_non" '(0 0))
      (princ)
     )
   )
 )
 (setvar 'cmdecho oldecho)
 (princ)
)

Share this post


Link to post
Share on other sites
Lee Mac

Yes, NCOPY uses a nested selection, similar to that which may be obtained using nentsel/nentselp.

Share this post


Link to post
Share on other sites
Hippe013

I recently worked on some code that worked similar to NCOPY but would grab all objects on the same layer as of the nested object that was selected using objectDBX and a temp copy of the xref. I spent many hours writing code and testing. I was successful in accomplishing this, though in continuing my testing, trying cover any all possible scenarios, I came to the conclusion that the code would be dangerous in the hands of those not understanding what the code was doing. Especially when it came to Civil 3D objects, which can copy over dependant objects as well as the selected object. I finally came to realization that it was best just to scrap the idea. I too, do not like how NCOPY works and wanted a better solution. I know this may not help you in your endeavor, but take it from me that it can be a complicated process which the results may or may not be what was initially wanted.

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...