TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Matt__W on August 01, 2008, 12:04:19 PM

Title: NCOPY entire layer
Post by: Matt__W on August 01, 2008, 12:04:19 PM
Anyone got a way of copying all nested objects on a user-defined/selected layer?  That they'd like to share?
Title: Re: NCOPY entire layer
Post by: T.Willey on August 01, 2008, 12:29:44 PM
Here is one I wrote with the help of gile, and then the copy xref layer ( CopyNestedLayer ) was an idea I got from Joe Burke.  Here are some subs that are needed for the file.  Let me know if I missed anything.

Code: [Select]
(defun GetCurrentSpace (Doc / BlkCol SpaceList CurSpace ActSpace temp1)
; Returns the "block object" for the active space
; Thanks to Jeff Mishler

(if (= (getvar "cvport") 1)
(vla-get-PaperSpace Doc)
(vla-get-ModelSpace Doc)
)
)
Code: [Select]
(defun SingleSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)

(setq DiaLoad (load_dialog "MyDialogs.dcl"))
(if (new_dialog "SingleSelect" DiaLOad)
(progn
(start_list "listbox" 3)
(mapcar 'add_list Listof)
(end_list)
(if Message
(set_tile "text1" Message)
)
(if (not Toggle)
(mode_tile "toggle1" 1)
)
(action_tile "listbox"
"(if (= $reason 4)
(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)
)"
)     
(action_tile "accept"
"(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (= (start_dialog) 1)
(progn
(setq tmpList (read (strcat "(" tmpStr ")")))
(if (= tmpTog "1")
(cons T tmpList)
tmpList
)
)
)
)
)
)
Title: Re: NCOPY entire layer
Post by: Matt__W on August 01, 2008, 12:40:47 PM
Thanks.

Didn't forget anything.  It doesn't like undo'ing that though.  Just got a fatal error regarding the acxrefservice....arx.   :|
Title: Re: NCOPY entire layer
Post by: T.Willey on August 01, 2008, 01:04:21 PM
Thanks.

Didn't forget anything.  It doesn't like undo'ing that though.  Just got a fatal error regarding the acxrefservice....arx.   :|
I don't know that one.  I don't see it in my arx list, and I was able to undo with no problem.  Sorry to hear that.

You're welcome.

Quote
Command: copynestedlayer

Initializing...
 Select object of nested layer to copy:
    Copied layer: E-GRIDLINE, Object count: 45
 Select object of nested layer to copy:


Command:
Command: u GROUP
Command: u LAYOUT_CONTROL Regenerating layout.
Title: Re: NCOPY entire layer
Post by: xshrimp on August 04, 2008, 08:27:14 AM
 :-
Code: [Select]
;;;Dhttp://www.xdcad.net/forum/showthread.php?s=&postid=2278035#post2278035
(defun c:bcopy (/ e el)
  (while (and
   (setq e (nentselp "\n选择块内实体: "))
   (= (length e) 4)
)
    (setq el (entget (car e)))
    (entmake el)
    (vla-transformby (vlax-ename->vla-object (entlast))
     (vlax-tmatrix (caddr e))
    )   
  )
  (princ)
)
Title: Re: NCOPY entire layer
Post by: Joe Burke on August 04, 2008, 09:44:08 AM
Thanks.

Didn't forget anything.  It doesn't like undo'ing that though.  Just got a fatal error regarding the acxrefservice....arx.   :|

Matt,

When undo causes a fatal error immediatly after running a lisp routine, it usually means a StartUndoMark was set without a corresponding EndUndoMark called.

This has been a long standing issue. Code must ensure this does not happen, typically by calling EndUndoMark in an error handler.
Title: Re: NCOPY entire layer
Post by: T.Willey on August 04, 2008, 11:48:20 AM
Thanks.

Didn't forget anything.  It doesn't like undo'ing that though.  Just got a fatal error regarding the acxrefservice....arx.   :|

Matt,

When undo causes a fatal error immediatly after running a lisp routine, it usually means a StartUndoMark was set without a corresponding EndUndoMark called.

This has been a long standing issue. Code must ensure this does not happen, typically by calling EndUndoMark in an error handler.

Matt,

  If this is the case, then my is the opposite, but may cause the same error.  I call EndUndoMark twice, and that might cause the error, so to fix that comment out the call in the main function, as it will be called when the error routine is called without an argument ( when call with a nil argument ).

  Thanks for the heads up Joe.
Title: Re: NCOPY entire layer
Post by: Joe Burke on August 05, 2008, 08:01:05 AM
Quote
Matt,

  If this is the case, then my is the opposite, but may cause the same error.  I call  EndUndoMark  twice, and that might cause the error, so to fix that comment out the call in the main function, as it will be called when the error routine is called without an argument ( when call with a nil argument ).

  Thanks for the heads up Joe.

Hi Tim,

AFAIK two EndUndoMarks in succession at the end of a routine do not cause a crash problem when the routine is undone. I have a few routines which call StartUndoMark and EndUndoMark in a loop so each loop can be undone. Those routines also call EndUndoMark in the error handler which is called at the end with (*error* nil).

BTW, the crash problem with an "open" StartUndoMark may only occur when undo is called multiple times immediately after the routine ends. That's my recollection anyway. One undo probably won't crash. Another one will probably cause a fatal error. I haven't checked this in recent versions.
Title: Re: NCOPY entire layer
Post by: dannypd on May 06, 2009, 11:53:28 AM
it gives an error while selecting nested object:
 Error-->: no function definition: GETCURRENTSPACE
Title: Re: NCOPY entire layer
Post by: T.Willey on May 06, 2009, 12:26:18 PM
it gives an error while selecting nested object:
 Error-->: no function definition: GETCURRENTSPACE

That sub, and the other one you would need, is in the post where the code is at ( the second post in this thread ).
Title: Re: NCOPY entire layer
Post by: sifntsifnt on March 02, 2010, 06:39:33 PM
hi there. This lisp is what ive been looking for. Looks great.. but unfortunately i do not understand how the subs and the .dcl are meant to work. Where do i places them and how do i get the subs to work?

sorry to ask such a beginner question. Also is there a condensed version of this LISP around now days? or a simply way of doing this?

I am running Autocad full 2010. Cheers pete
Title: Re: NCOPY entire layer
Post by: T.Willey on March 02, 2010, 06:54:52 PM
Welcome to the swamp.

Take the lisp file ( *.lsp ).  Copy the two codes, within the second post in this thread, into the lisp file.  Save that.  Take the dialog file ( *.dcl ), and place that within a folder that is within the support paths.  Then you load the lisp.  ' Appload ' or ' ap ' should show the dialog box to load the lisp file.  Then select the *.lsp file.  Once it's loaded you can use the commands that it defines, which is called out in the second post also.

If that doesn't help, tell us what you have tried, and what error messages are shown.

I don't think there is another version of the code ( unless Joe has posted his, but that would most likely be the same complexity ), and I have not rewritten it in lisp.
Title: Re: NCOPY entire layer
Post by: sifntsifnt on March 03, 2010, 01:03:41 AM
thanks for the reply. Your a gentleman. unfortunately i know very little.

I added the subs into the lisp... at the top. put those break thingies between (hehehe... sorry at my little knowledge.. but try to explain)

i added the .DCL file to a folder in autocad support folder... and then added that to the autocad support list.

When i run 'copynested' or copynestedlayer' i get the same error.

Command: copynestedlayer
; error: An error has occurred inside the *error* functionno function
definition: VLA-ENDUNDOMARK

which would show to me its firing up the lisp... but an error is occuring inside?

    (defun *error* (msg)
       
        (vla-EndUndoMark ActDoc)
        (if dbxApp (vl-catch-all-apply 'vlax-release-object (list dbxApp)))
        (setq dbxApp nil)
        (prompt (strcat "\n Error-->: " msg))
    )

not sure what. No hassles its it too hard to trouble shot from a distance.
Title: Re: NCOPY entire layer
Post by: Joe Burke on March 03, 2010, 10:30:24 AM
I suspect you need to revise the error handler with this added cond statement:

  (defun *error* (msg)
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )

Title: Re: NCOPY entire layer
Post by: T.Willey on March 03, 2010, 10:59:04 AM
Are you using Lt with a Lisp enabler?  Or are you suing Briscad?  Or what version of Acad you using?

The error should not happen in the later versions of Acad, as it is saying that a built in function is not there.
Title: Re: NCOPY entire layer
Post by: danglar on December 16, 2015, 01:47:30 AM
Thank you  T.Willey for your program.
It works good even very good, but when you copy items to current drawing you have a problem to move it to another place..
Is it possible to involve a "move" command to selection set of items "transferred" to current drawing from nested one, like in a one of previous posts?


Code - Auto/Visual Lisp: [Select]
  1. (command "_.move" p "" pause)  ; HIGHLIGHT IT AND BEGIN A MOVE ACTION
  2.  
Title: Re: NCOPY entire layer
Post by: T.Willey on December 16, 2015, 08:19:02 AM
I would believe that it would not be a problem.  I have not looked at the code since I posted it, so if you want to add that line of code it should work.

It looks like you would need to create a new variable for the selection set, then after all the new items are created in the drawing (variable NewObj), add that object to the selection set.  Then you can just pass the selection set to the move command.  Sorry I do not have time right now to add this.  Hope this explains it clear enough that you can add the bit of code you want.
Title: Re: NCOPY entire layer
Post by: danglar on December 17, 2015, 01:53:29 AM
It seems, I find another way to solve a problem.
I did a little modification of routine from here:

http://www.theswamp.org/index.php?topic=27354.msg329179#msg329179

Now you can copy nested blocks and/or other entities and move it in a same time (see attached lisp)

Remain a "little" issue: Routine explode blocks in current drawing...
Is it  possible to fix it?