Author Topic: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX  (Read 4716 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« on: October 21, 2008, 11:53:56 AM »
The following routine fails on the call to vla-getboundingbox when the document is an objectdbx doc.  It works fine on the activedocument.

Suggestions are appreciated.

Mike
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Routine: GetXRefExtents ;;;
;;;  Purpose: Get all xrefs references with names matching a wcmatch mask ;;;
;;;  Arguments: Doc - document object, may e an objectdbx document.  If doc is nil, the active ;;;
;;; document is used. ;;;
;;; NameMask - string, a wcmatch wildcard match to limit the blockrefs returned. ;;;
;;;  Returns: A nested list where each sub-list consists of the following: car is the name of ;;;
;;; the blockref, cadr xref path, caddr is the lowerleft point of the blockref ;;;
;;; bounding box and cadddr is the upper right of the blockref bounding box.  Points;;;
;;; returned are in the world coordinate system. ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  This routine does not work on objectdbx documents:-(  the call to vla-getboundingbox ;;;
;;;  returns "Automation Error. Null extents". ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetXRefExtents (doc NameMask / rtlist blocks bname ll objblock ur)
  (if doc
    nil
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (vlax-for blk (setq blocks (vla-get-blocks doc))
    (vlax-for obj blk
      (if (and (= "AcDbBlockReference" (vla-get-objectname obj))
       (= :vlax-true
  (vla-get-isxref
    (setq objBlock (vla-item blocks (setq bname (vla-get-name obj))))
  )
       )
       (wcmatch (strcase bname) NameMask)
       (not[color=red]
(vl-catch-all-error-p
   (vl-catch-all-apply 'vla-getboundingbox (list obj 'LL 'UR))
)[/color]
       )
  )
(setq
  rtlist (cons
   (list
     (vla-get-name obj)
     (vla-get-path objblock)
     (vlax-safearray->list LL)
     (vlax-safearray->list UR)
     )
   rtlist
   )
  )
      )
    )
  )
  rtlist
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #1 on: October 21, 2008, 11:58:15 AM »
I thought xrefs were not loaded in an odbx session?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mkweaver

  • Bull Frog
  • Posts: 352
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #2 on: October 21, 2008, 12:08:01 PM »
I thought xrefs were not loaded in an odbx session?

<Slaps forehead!> You are absolutely right!  Argh!

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #3 on: October 21, 2008, 12:12:38 PM »
I thought xrefs were not loaded in an odbx session?

<Slaps forehead!> You are absolutely right!  Argh!
:-)

I think Tim W. did a bunch of work with ODBX and xrefs...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #4 on: October 21, 2008, 01:08:47 PM »
If you don't mind a work around, you could insert the xref as a block, and then get the bounding box of it.  You would get the xref definition, then rename it, and then insert it at the same place, then use GetBoundingBox on the insert.  I just tested it and it worked.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mkweaver

  • Bull Frog
  • Posts: 352
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #5 on: October 21, 2008, 07:34:49 PM »
If you don't mind a work around, you could insert the xref as a block, and then get the bounding box of it.  You would get the xref definition, then rename it, and then insert it at the same place, then use GetBoundingBox on the insert.  I just tested it and it worked.

Now, that's an approach I hadn't considered, and I bet it would work.

A little background:  My detail sheets have a 4x4 grid of details set up.  Each detail slot has a corresponding xref (BLANK01, BLANK02... BLANK16) in the template.  When I add a detail to the sheet I create the detail as a separate drawing and re-path one of the xrefs to point to the new detail drawing.  Now, with 20 or 30 of these detail sheets created over a matter of years (I'm doing sustaining engineering for a manufacturing facility) I often need to find a detail sheet with an empty detail slot to which I can add a new detail.  In the past this has involved opening each of the detail sheets until I find one with an empty slot.  I intended to write a routine that would open each of these sheets through objectdbx and tell me what sheets had open detail slots.  I was trying to get the xref bounding box to identify viewports that have no detail visible.  It looks like I'm not going to be able to use this approach.  Your work-around would work, but, I'm concerned about the performance impact of attaching each detail to find the extents.

I guess I'll have to find another approach.

Thanks for the help.

Mike

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #6 on: October 22, 2008, 10:57:53 AM »
You can get the insertion point, would that help?  Also you can get the number of xrefs within a drawing, would that help?  If the details are not to intense, then there shouldn't be that much of a hit, also you can set it up so that if it only finds a certain number of xrefs, then try and insert them as blocks and get the bounding box.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Automation Error. Null extents - vla-GetBoundingBox w/ObjectDBX
« Reply #7 on: October 22, 2008, 12:02:03 PM »
This didn't take too long.  See if it gets you going in the right direction.

Code: [Select]
(defun c:dbxInsertTest (/ AtchType DwgFile dbxApp oVer tempInfoList tempList InfoList *error*)
   
    (defun *error* (msg)
       
        (if dbxApp (vlax-release-object dbxApp))
        (setq dbxApp nil)
        (if msg (vl-bt))
    )
    ;--------------------------------------
    (if
        (and
            (setq DwgFile (getfiled "Select drawing with xrefs to get information from." "" "dwg" 4))
            (setq dbxApp
                (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
                    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
                    (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
                )
            )
            (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbxApp DwgFile))))
        )
        (progn
            (foreach xr (GetAllXrefs dbxApp)
                (if (setq tempInfoList (InsertAsBlock dbxApp xr))
                    (if (setq tempList (assoc (car tempInfoList) InfoList))
                        (setq InfoList (subst (list (car tempInfoList) (cadr tempInfoList) (cons (cddr tempList) (cddr tempInfoList))) tempList InfoList))
                        (setq InfoList (cons tempInfoList InfoList))
                    )
                )
            )
        )
    )
    (foreach i InfoList
        (prompt
            (strcat
                "\nXref name: " (car i)
                "\n  Xref path: " (cadr i)
                "\n  Bounding box(es): "
            )
        )
        (foreach j (cddr i)
            (prompt (strcat "\n    " (vl-princ-to-string (car j)) " - " (vl-princ-to-string (cadr j))))
        )
    )
    (*error* nil)
    (princ)
)
(defun GetAllXrefs (doc / XrList)
   
    (vlax-for i (vla-get-Blocks doc)
        (if (equal (vla-get-IsXref i) :vlax-true)
            (setq XrList (cons i XrList))
        )
    )
    XrList
)
(defun GetSpatialFilter (ename / Data Dict tempDict)
    ; Get the xclip boundry
   
    (if
        (and
            (setq Data (entget ename))
            (setq Dict (cdr (assoc 360 Data)))
            (setq tempDict (dictsearch Dict "ACAD_FILTER"))
            (setq tempDict (dictsearch (cdr (assoc -1 tempDict)) "SPATIAL"))
        )
        (cons '(0 . "SPATIAL_FILTER") (member (assoc 100 tempDict) tempDict))
    )
)
(defun SetSpatialFilter (ename fltData / Data Dict tempDict tempList)
    ; Set the xclip boundry
   
    (if
        (and
            (setq Data (entget ename))
            (setq Dict
                (if (setq tempList (assoc 360 Data))
                    (cdr tempList)
                    (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))
                )
            )
            (setq tempDict
                (if (setq tempList (dictsearch Dict "ACAD_FILTER"))
                    (cdr (assoc -1 tempList))
                    (dictadd Dict "ACAD_FILTER" (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary"))))
                )
            )
        )
        (progn
            (dictremove tempDict "SPATIAL")
            (dictadd tempDict "SPATIAL" (entmakex fltData))
            (entmod
                (if (setq tempList (assoc 360 Data))
                    (subst (cons 360 Dict) tempList Data)
                    (progn
                        (setq tempList (member (assoc 5 Data) (reverse Data)))
                        (append
                            (reverse tempList)
                            (append
                                (list
                                    '(102 . "{ACAD_XDICTIONARY")
                                    (cons 360 Dict)
                                    '(102 . "}")
                                )
                                (member (assoc 5 Data) Data)
                            )
                        )
                    )
                )
            )
        )
    )
)
(defun InsertAsBlock (doc xrObj / tempEnt tempData InsList XrName XrPath tempXrObj tempXrEnt tempList BlkCol NewXrObj DidSwitch tempPath)
   
    (if
        (and
            (setq BlkCol (vla-get-Blocks doc))
            (setq tempEnt (vlax-vla-object->ename xrObj))
            (setq tempData (entget tempEnt))
            (setq InsList (member (assoc 331 tempData) tempData))
            (setq InsList (cdr (member '(102 . "}") (reverse InsList))))
            (setq tempData (entget (cdr (assoc 360 tempData))))
            (setq XrName (cdr (assoc 2 tempData)))
            (setq XrPath (cdr (assoc 1 tempData)))
            (or
                (findfile Xrpath)
                (and
                    (setq tempPath (strcat (vl-filename-directory (vla-get-Name doc)) "\\" (vl-filename-base XrPath) ".dwg"))
                    (findfile tempPath)
                    (setq XrPath tempPath)
                )
                (and
                    (setq tempXrefPath XrPath)
                    (setq XrPath (GetCurrentXrefPath doc (strcat (vl-filename-base XrPath) (vl-filename-extension XrPath))))
                )
            )
        )
        (progn
            (vla-put-Name xrObj (strcat "TempXref-" XrName))
            (foreach i InsList
                (setq tempData (entget (cdr i)))
                (setq tempXrObj
                    (vlax-invoke
                        (vlax-ename->vla-object (cdr (assoc 330 tempData)))
                        'InsertBlock
                        (trans (cdr (assoc 10 tempData)) (cdr (assoc 210 tempData)) 0)
                        XrPath
                        (cdr (assoc 41 tempData))
                        (cdr (assoc 42 tempData))
                        (cdr (assoc 43 tempData))
                        (cdr (assoc 50 tempData))
                    )
                )
                (vlax-put tempXrObj 'Normal (cdr (assoc 210 tempData)))
                (setq tempXrEnt (vlax-vla-object->ename tempXrObj))
                (if (setq tempList (GetSpatialFilter (cdr i)))
                    (SetSpatialFilter tempXrEnt tempList)
                )
                (vla-GetBoundingBox tempXrObj 'll 'ur)
                (setq tempList (list XrName XrPath (list (safearray-value ll) (safearray-value ur))))
            )
        )
    )
    tempList
)
Printed on the command line like
Quote
Xref name: S929-02
  Xref path: W:\Jim\TDD-Project\S929-02.dwg
  Bounding box(es):
    (20.7758 18.9764 -1.0e-008) - (39.4835 27.5319 1.0e-008)
Xref name: S929-03
  Xref path: W:\Jim\TDD-Project\S929-03.dwg
  Bounding box(es):
    (11.422 18.9764 -8.33333e-010) - (20.7759 27.5319 8.33333e-010)
Xref name: S929-04
  Xref path: W:\Jim\TDD-Project\S929-04.dwg
  Bounding box(es):
    (2.06815 18.9764 -8.33333e-010) - (11.422 27.5319 8.33333e-010)
Xref name: S929-05
  Xref path: W:\Jim\TDD-Project\S929-05.dwg
  Bounding box(es):
    (30.1297 10.4209 -8.33333e-010) - (39.4835 18.9764 8.33333e-010)
Xref name: S929-10
  Xref path: W:\Jim\TDD-Project\S929-10.dwg
  Bounding box(es):
    (20.7759 1.86545 -1.0e-008) - (30.1297 18.9764 1.0e-008)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.