TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Joe Burke on July 11, 2010, 11:00:04 AM

Title: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 11, 2010, 11:00:04 AM
The following code is desigend to copy selected objects from an xref to the active file using the Xref Database object as the source. The copied objects are placed on the the active layer.

It works as expected in both 2008 and 2010, but when undo is called after the routine ends, 2010 reports a fatal crash with a "wrong database" error, which does not occur in 2008.

Code: [Select]
(defun c:WrongDatabase ( / *error* doc blocks layers mspace
                           curlay copyobj GetXref copylst)

  (vl-load-com)

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

  ;;; START SUB-FUNCTION ;;;

  ;; Argument: a list of block enames as returned by (last nentsel or nentselp).
  ;; Returns the fisrt vla-object block which is an xref.
  (defun GetXref (lst / o blkdef blkdeflst)
    (foreach x lst
      (setq o (vlax-ename->vla-object x))
      (setq blkdef (vla-item blocks (vlax-get o 'Name)))
      (setq blkdeflst (cons blkdef blkdeflst))
    )
    (setq blkdeflst (reverse blkdeflst))
    (while (eq acFalse (vlax-get (car blkdeflst) 'IsXref))
      (setq blkdeflst (cdr blkdeflst))
    )
    (car blkdeflst)
  ) ;end

  ;;; END SUB-FUNCTION ;;;

  ;;; START MAIN FUNCTION ;;;

  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
        blocks (vla-get-Blocks doc)
        layers (vla-get-Layers doc)
        mspace (vla-get-ModelSpace doc)
        curlay (getvar "clayer")
  )

  (while
    (and
      (setq elst (nentselp "\nSelect object nested in an xref: "))
      (= 4 (length elst))
      (setq obj (vlax-ename->vla-object (car elst)))
      (setq xref (GetXref (last elst)))
      (setq xdb (vlax-get xref 'XRefDatabase))
    ) ; and
    (setq copyobj (car (vlax-invoke xdb 'CopyObjects (list obj) mspace)))
    (vla-update copyobj)
    (vla-transformby copyobj (vlax-tmatrix (caddr elst)))
    ;; the following line is what's causing the undo crash in 2010
    (vlax-put copyobj 'Layer curlay)
  ) ; while
  (*error* nil)
) ;end WrongDatabase

;shortcut
(defun c:WDB () (c:WrongDatabase))
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Tharwat on July 11, 2010, 04:15:54 PM
I have tried your Lisp but it hasn't worked with me ... unfortunetly.

and I think it is a matter of multiple selection for ncopy command or so ...... Am I right ? :pissed:

If yes that would be what I am looking for....... and so interesting.

Regards

Tharwat
Title: Re: wrong database errror given undo in ACAD 2010
Post by: gile on July 12, 2010, 04:09:00 AM
Hi Joe,

I tried with 2007 and 2010 and it worked on both.
I also tried after having added a (vla-StartUndoMark doc) before the (while ...) and a (vla-EndUndoMark doc) in the *error* function and it worked fine too...
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 12, 2010, 07:47:31 AM
Hi Joe,

I tried with 2007 and 2010 and it worked on both.
I also tried after having added a (vla-StartUndoMark doc) before the (while ...) and a (vla-EndUndoMark doc) in the *error* function and it worked fine too...

Hi gile,

Thanks for testing.

The undo crash problem in 2010 was brought to my attention by Steve Doman. I'm at a loss at this point to understand why undo causes a crash for Steve and I, but not for you. Regardless, that's good news.

Regards
Joe
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 12, 2010, 07:54:49 AM
gile,

Also thanks for testing with (vla-StartUndoMark doc) and (vla-EndUndoMark doc) added. I intentionally left that stuff out so as not to confuse the issue.

Joe
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 12, 2010, 08:10:23 AM
I have tried your Lisp but it hasn't worked with me ... unfortunetly.

and I think it is a matter of multiple selection for ncopy command or so ...... Am I right ? :pissed:

If yes that would be what I am looking for....... and so interesting.

Regards

Tharwat

Tharwat,

The routine is similar to ncopy. It does not allow multiple selection.

The routine I posted is only a function designed to test the undo crash problem I see in 2010, but not in 2008.

The routine I'm working on allows copy in place or offset of objects in the active file, or objects contained in a block, or objects contained in an xref.
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Hangman on July 12, 2010, 11:03:48 AM
Joe,

I'm running 2010 Map3D.  Here's what I did.

I have a drawing with an xref.  Another block is xref'ed into that xref so I have a good nesting.
When I ran the 'WDB' command, it asked for the object, then asked again.  It copied the item to the main drawing.
I then zoomed out and panned around.  Then did the undo.

No error here.

Quote
Command:
Reload Xref "1400.10-X-432dgn"

Command: wdb

Select object nested in an xref:
Select object nested in an xref:
Command:
Command:

Command: u
INTELLIPAN
Command:

Command: u
WDB
Command:
Command: u
INTELLIPAN
Command:
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 13, 2010, 07:43:14 AM
Hangman,

Thanks for testing. That's encouraging, similar to gile's report.

I'll have to test the routine on a few other machines running vanilla 2010. Service packs installed or not may play a role.

Regards

Title: Re: wrong database errror given undo in ACAD 2010
Post by: Jeff_M on July 13, 2010, 11:33:19 AM
HI Joe,
I get the same results as you using Civil3D2010, SP2. Tried in both C3D mode and "As AutoCAD" mode which just doesn't load the C3D DLL's & ARX files.

Title: Re: wrong database errror given undo in ACAD 2010
Post by: gile on July 13, 2010, 11:57:10 AM
Hi Joe,

I tried again and was able too to have the fatal error when I selected more entities.
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 14, 2010, 06:14:19 AM
Jeff and gile,

Thanks for your reports. Oddly, that's actually good news. Others are seeing the same problem Steve Doman reported.

I suspect the undo "wrong database" crash in 2010 is somehow related to the fact when an object is copied from an XrefDatabse object to the active file its layer name is like this "xx|xx". Which of course is not a valid layer name within the active file.

The routine changes the "xx|xx" layer name to the layer name of the current layer in the active file. For some reason 2010 crashes when trying undo this process, while 2008 does not.

I'm thinking about a workaround...

Regards
Title: Re: wrong database errror given undo in ACAD 2010
Post by: ronjonp on July 14, 2010, 10:43:30 AM
Joe,

I had a similar issue with my COPYN routine (my error was "errors found when saving..."). FWIW ... this was the function I used to fix it  :-D:

Code: [Select]
 (defun fixeffeduplname (e / i l)
    (setq l (cdr (assoc 8 (entget e))))
    (if (setq i (vl-string-position 124 l 0 t))
      (setq l (substr l (+ 2 i)))
    )
    (entmod (subst (cons 8 l) (assoc 8 (entget e)) (entget e)))
  )
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Lee Mac on July 14, 2010, 10:46:36 AM
Code: [Select]
(defun fixeffeduplname

 :-D  :lmao:
Title: Re: wrong database errror given undo in ACAD 2010
Post by: ronjonp on July 14, 2010, 11:15:44 AM
Code: [Select]
(defun fixeffeduplname

 :-D  :lmao:

Thought someone might find that funny  :-)
Title: Re: wrong database errror given undo in ACAD 2010
Post by: Joe Burke on July 17, 2010, 08:07:05 AM
Joe,

I had a similar issue with my COPYN routine (my error was "errors found when saving..."). FWIW ... this was the function I used to fix it  :-D:

Code: [Select]
 (defun fixeffeduplname (e / i l)
    (setq l (cdr (assoc 8 (entget e))))
    (if (setq i (vl-string-position 124 l 0 t))
      (setq l (substr l (+ 2 i)))
    )
    (entmod (subst (cons 8 l) (assoc 8 (entget e)) (entget e)))
  )

Thanks for the idea. Unfortunately it doesn't help with the undo crash in 2010.