Author Topic: wrong database errror given undo in ACAD 2010  (Read 2715 times)

0 Members and 1 Guest are viewing this topic.

Joe Burke

  • Guest
wrong database errror given undo in ACAD 2010
« 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))
« Last Edit: July 11, 2010, 11:09:45 AM by Joe Burke »

Tharwat

  • Swamp Rat
  • Posts: 611
  • Hypersensitive
Re: wrong database errror given undo in ACAD 2010
« Reply #1 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

gile

  • Water Moccasin
  • Posts: 2275
  • Marseille, France
Re: wrong database errror given undo in ACAD 2010
« Reply #2 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...
Speaking English as a French Frog

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #3 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

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #4 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

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #5 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.

Hangman

  • Swamp Rat
  • Posts: 563
Re: wrong database errror given undo in ACAD 2010
« Reply #6 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:
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #7 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


Jeff_M

  • King Gator
  • Posts: 4005
  • C3D user & customizer
Re: wrong database errror given undo in ACAD 2010
« Reply #8 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.


gile

  • Water Moccasin
  • Posts: 2275
  • Marseille, France
Re: wrong database errror given undo in ACAD 2010
« Reply #9 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.
Speaking English as a French Frog

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #10 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

ronjonp

  • Needs a day job
  • Posts: 7281
Re: wrong database errror given undo in ACAD 2010
« Reply #11 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)))
  )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: wrong database errror given undo in ACAD 2010
« Reply #12 on: July 14, 2010, 10:46:36 AM »

ronjonp

  • Needs a day job
  • Posts: 7281
Re: wrong database errror given undo in ACAD 2010
« Reply #13 on: July 14, 2010, 11:15:44 AM »
Code: [Select]
(defun fixeffeduplname

 :-D  :lmao:

Thought someone might find that funny  :-)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Joe Burke

  • Guest
Re: wrong database errror given undo in ACAD 2010
« Reply #14 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.