Jump to content

ObjectDBX: Vla-AttachExternalReference


BlackBox

Recommended Posts

Using ObjectDBX, I am having difficulty accomplishing both the attachment of an XREF (in MS), and insertion of a Title Block (in PS).

 

Specifically, when using dbx to open the pre-setup title block drawing (saved in PaperSpace), attempts to attach my XREF are successful, but only to the current space (PS), and not to ModelSpace (MS) where it belongs.

 

This is despite my efforts of either using (vla-get-modelspace dbx) for the Object parameter of Vla-AttachExternalReference, or stepping through the tabs in order to get the Layout's Block Object, like so:

 

(defun c:FOO ( / dbx master)
 (vl-load-com)
 (if (setq dbx (vla-GetInterfaceObject
                        (vlax-Get-Acad-Object)
                        (strcat "ObjectDBX.AxDbDocument."
                                (substr (getvar 'acadver) 1 2))))
   (progn
     (vl-catch-all-apply 'vla-open (list dbx "C:\\my_titleblock.dwt"))
     (vlax-for lay  (vla-get-layouts dbx)
       (if (= "MODEL" (strcase (vla-get-name lay)))
         (progn
           (vla-attachexternalreference
             (vla-get-block lay)
             (setq master "C:\\my_xref.dwg")
             (vl-filename-base master)
             (vlax-3d-point '(0 0 0))
             1
             1
             1
             0
             :vlax-true))))
     (vl-catch-all-apply 'vla-saveas (list dbx "C:\\my_sheet.dwg"))
     (setq dbx (vl-catch-all-apply 'vlax-Release-Object (list dbx)))))
 (princ))

 

Any help would be much appreciated!

Link to comment
Share on other sites

Hi Renderman,

 

This works fine for me:

 

(defun c:test ( / dbx title master ) (vl-load-com)

 (setq title  "C:\\my_titleblock.dwt"
       master "C:\\my_xref.dwg"
 )
 
 (if
   (and
     (setq dbx    (LM:GetDocumentObject title))
     (setq master (findfile master))
   )
   (progn
     (vla-attachexternalreference (vla-get-modelspace dbx) master
       (vl-filename-base master) (vlax-3d-point '(0 0 0)) 1. 1. 1. 0. :vlax-true
     )
     (vl-catch-all-apply 'vla-saveas (list dbx "C:\\my_sheet.dwg"))
     (vl-catch-all-apply 'vlax-Release-Object (list dbx))
   )
 )
 
 (princ)
)

;;-----------------=={ Get Document Object }==----------------;;
;;                                                            ;;
;;  Retrieves a the VLA Document Object for the specified     ;;
;;  filename. Document Object may be present in the Documents ;;
;;  collection, or obtained through ObjectDBX                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  filename - filename for which to retrieve document object ;;
;;------------------------------------------------------------;;
;;  Returns:  VLA Document Object, else nil                   ;;
;;------------------------------------------------------------;;

(defun LM:GetDocumentObject ( filename / docs dbx ) (vl-load-com)
 
 (vlax-map-collection (vla-get-Documents (vlax-get-acad-object))
   (function
     (lambda ( doc )
       (setq docs
         (cons
           (cons (strcase (vla-get-fullname doc)) doc) docs
         )
       )
     )
   )
 )

 (cond
   ( (not (setq filename (findfile filename))) )
   ( (cdr (assoc (strcase filename) docs)) )
   ( (not
       (vl-catch-all-error-p
         (vl-catch-all-apply 'vla-open
           (list (setq dbx (LM:ObjectDBXDocument)) filename)
         )
       )
     )
     dbx
   )
 )
)

;;-----------------=={ ObjectDBX Document }==-----------------;;
;;                                                            ;;
;;  Retrieves a version specific ObjectDBX Document object    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments: - None -                                       ;;
;;------------------------------------------------------------;;
;;  Returns:  VLA ObjectDBX Document object, else nil         ;;
;;------------------------------------------------------------;;

(defun LM:ObjectDBXDocument ( / acVer )
 (vla-GetInterfaceObject (vlax-get-acad-object)
   (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
     "ObjectDBX.AxDbDocument"
     (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
   )
 )
)

 

Be sure that you have the permissions to write directly to the C drive.

Link to comment
Share on other sites

Thanks for the attempt Lee, but it yeilds the same result... the XREF is attached to PaperSpace with the Title Block, instead of ModelSpace where the XREF belongs.

 

The behavior seems to demonstrate that whatever tab the source drawing/template is saved in, determines the space an XREF is attached, regardless of how one specified the ModelSpace Object during Vla-AttachExternalReference.

 

I have tried using a source drawing/template which has been saved in the Model tab, and the XREF is correctly attached to MS.

Link to comment
Share on other sites

IIRC my testing involved a drawing saved to the MS tab

 

No worries, I *thought* I was saving a step by using a source drawing saved to PS, as the sheets created would be saved to PS.

 

I've since changed to using our standard template for the source (saved in MS), and I'll have to find a way of using Vla-InsertBlock to add the title block to PS.

 

Cheers!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...