Author Topic: Automation Error with ObectDBX  (Read 3570 times)

0 Members and 1 Guest are viewing this topic.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Automation Error with ObectDBX
« on: May 17, 2005, 12:12:25 PM »
Hi all

This function works w/o problems in A2k/2k2/2k4/2k5/2k6. In Map i get an
error 'Automation Error. Key not found' (see code)... :x
Has someone of you an idea what happens?
Code: [Select]
;
; -- MeCloneLayout
; Clones the specified Layout to a new name.
; Copyright:
;   ©2003 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
;   Src = Source Layout name [STR]
;   Tar = Target Layout name [STR]
; Return [Typ]:
;   > New Layout object [VLA_OBJECT]
;   > nil if surce name not exists, target name exists or ObjectDBX error
; Notes:
;   - You can't use 'Model' as target name
;   - Credits to Tony Tanzillo
;
(defun MeCloneLayout (Src Tar / AcaDoc AcaObj DbxDoc ObjStr SrcObj SrcCol
                                TarObj TarCol)
 (setq AcaObj (vlax-get-acad-object)
       AcaDoc (vla-get-ActiveDocument AcaObj)
       ObjStr (if (< (atof (getvar "ACADVER")) 16.0)
               "ObjectDBX.AxDbDocument"
               "ObjectDBX.AxDbDocument.16"
              )
 )
 (if (and
      (not (eq (strcase Tar) "MODEL"))
      (vl-catch-all-error-p
       (vl-catch-all-apply 'vla-Item (list (vla-get-Layouts AcaDoc) Tar))
      )
      (not
       (vl-catch-all-error-p
        (setq SrcObj (vl-catch-all-apply
                     'vla-Item (list (vla-get-Layouts AcaDoc) Src)
                     )
        )
       )
      )
      (not
       (vl-catch-all-error-p
        (setq DbxDoc (vl-catch-all-apply
                      'vla-GetInterfaceObject (list AcaObj ObjStr)
                     )
        )
       )
      )
     )
  (progn
   (setq SrcCol (vla-get-Layouts AcaDoc)
         TarCol (vla-get-Layouts DbxDoc)
   )
   (vlax-Invoke AcaDoc 'CopyObjects (list SrcObj) TarCol)
   (setq TarObj (vla-Item TarCol Src)) ;Error on this line!!!
   (vla-put-Name TarObj Tar)
   (vlax-Invoke DbxDoc 'CopyObjects (list TarObj) SrcCol)
   (vlax-release-object DbxDoc)
   (vla-Item (vla-get-Layouts AcaDoc) Tar)
  )
 )
)

TIA

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

whdjr

  • Guest
Automation Error with ObectDBX
« Reply #1 on: May 17, 2005, 12:31:19 PM »
I would think the error would probably be this area:
Code: [Select]
(setq AcaObj (vlax-get-acad-object)
       AcaDoc (vla-get-ActiveDocument AcaObj)
       ObjStr (if (< (atof (getvar "ACADVER")) 16.0)
               "ObjectDBX.AxDbDocument"
               "ObjectDBX.AxDbDocument.16"
              )
 )


Since you are using Map and not Vanilla AutoCAD.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Automation Error with ObectDBX
« Reply #2 on: May 17, 2005, 12:39:34 PM »
Hi Will

Quote from: whdjr
Since you are using Map and not Vanilla AutoCAD.

Thx for the reply. I'm not familiar with MAP and I've actually no installation.
The error occurs by a customer. Do you have any idea what's to do?

TIA

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Automation Error with ObectDBX
« Reply #3 on: May 17, 2005, 12:42:16 PM »
Interesting.......I'm using LDD3 which is built on Map5, which is built on Acad2002.

1_$ (vlax-for x tarcol (princ (vla-get-name x)))
testLayout1Layout2Model"Model"
_1_$ (vla-item tarcol "test")
; error: Automation Error. Key not found
_1_$ (vla-get-name (vla-item tarcol 0))
"test"
_1_$

So it's recognized as being there when referencing the index counter, but not by name. Another one of Adesk's quirks that makes you go "Huh?"  :shock:

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Automation Error with ObectDBX
« Reply #4 on: May 17, 2005, 12:44:56 PM »
And the code that Will pointed out, does work fine with Map.....I've been using an almost identical function for quite some time in routines that run in LDD3 & Land2004

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Automation Error with ObectDBX
« Reply #5 on: May 17, 2005, 12:54:23 PM »
Works here!!

Code: [Select]

(MECLONELAYOUT "Layout1" "layout_new")
#<VLA-OBJECT IAcadLayout 0c372244>


LDT 2005, includes Map 3D.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Automation Error with ObectDBX
« Reply #6 on: May 17, 2005, 01:00:45 PM »
Perhaps you can use something like this when a collection won't yield an item via a named key (string) --

Code: [Select]
(defun GetItem ( collection key / item )
    (setq key (strcase key))
    (vl-catch-all-apply
       '(lambda ()
            (vlax-for object collection
                (cond
                    (   (eq key (strcase (vla-get-name object)))
                        (setq item object)
                        (exit)
                    )    
                )
            )
        )
    )
    item    
)

Caller is responsible for passing a valid collection and key (string).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Automation Error with ObectDBX
« Reply #7 on: May 17, 2005, 01:46:58 PM »
Thx to all

Seems that Jeff has found a new @#!~Q%&¦ of Adesk... :roll:
Will report the result tomorrow.

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Automation Error with ObectDBX
« Reply #8 on: May 18, 2005, 04:10:51 PM »
Hi all

No luck to find a solution... :(
Seems that the CopyObjects method fails in this environment.

Anyway, thanks for your efforts.
Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Automation Error with ObectDBX
« Reply #9 on: May 18, 2005, 05:59:34 PM »
Jürg,
I'm slowly recalling some things I worked on with regard to Layouts. It seems to me I could never get a Layout to be correctly created in the  Target drawing. About the only success I had at copying Layouts was to use the Add method of the Layouts collection, get the 2 blocks for the 2 layouts, use copyobjects on the ents in the Source layout, and get/put each property and method that needs to be set......It was slow to run....I finally gave up, since copying & renaming a layout by selection is very fast....

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Automation Error with ObectDBX
« Reply #10 on: May 19, 2005, 02:39:47 AM »
Hi Jeff
Quote from: Jeff_M
It was slow to run....I finally gave up, since copying & renaming a layout by selection is very fast....
There is only one problem, the customer wants create >100!!! Layouts automatically...
And, in standard AutoCAD environment I never had problems with the CopyObjects method from A2k to A2k6...

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18