CAD Forums => Vertically Challenged => Architecturally Speaking => Topic started by: jbuzbee on July 22, 2007, 11:32:39 AM

Title: Importing AEC Styles
Post by: jbuzbee on July 22, 2007, 11:32:39 AM
I've never been able to figure out how to Import ADT Styles using ObjectDBX.  The problem is when a style has extended data attached in the form of Property Sets, Classifications or Materials.  This extended data, if present in the receiving drawing, won't be attached to the style being Imported: a new Property Set, if you will, is created: MyDoorScheduleData(2) - leaving MyDoorScheduleData thus creating multiple duplications: what a mess.

So here's my solution (I can't believe after all these years).  Open a drawing that has a style you want to import using ObjectDBX (an axdbDocument).  Create a block in the axdbdocument using activex.  Add an object of the type and style you want to import with (vla-AddCustomObject ...) to that block.  Use (vla-CopyObjects) to import the block into the active drawing.  Delete the block. 

Because ObjectDBX doesn't save the opened axdbDocument you don't have to worry about managing the temporary block  "jbTempBlock".


Classifications are the only remaining problem.  I can't understand why these don't update.  Materials, PropertySets, Profiles all update fine - just classifications.  Oh well, I guess I won't be using classifications any more.


Code: [Select]

;;;Use (jb:ImportADTStyle (getfiled "Select a file" (getvar "dwgprefix") "dwg" 0) "AECDOOR" "AL-2-AL")

(defun jb:ImportADTStyle  (file aecobjtype stylename / dbxDoc blocks block aecobj newblk localBlocks)
  (setq dbxDoc (jb:OpenDbxDocument file))
  (if dbxdoc
    (progn (setq localBlocks(vla-get-blocks(vla-get-ActiveDocument (vlax-get-acad-object)))
                 blocks (vla-get-blocks dbxDoc)
                 block  (vla-add blocks (vlax-3d-point 0 0) "jbTempBlock")
                 aecobj (vla-AddCustomObject block aecobjtype))
           (if aecobj
             (progn (vla-put-stylename aecobj stylename)
                    (setq newblk (vl-catch-all-apply
                                   (list dbxDoc
                                           (vlax-make-safearray vlax-vbObject '(0 . 0))
                                           (list (vla-item blocks "jbTempBlock")))
  (if (tblsearch "block" "jbTempBlock")(vla-delete (vla-item localBlocks "jbTempBlock")))
  (if dbxdoc
    (jb:closedbxdocument dbxDoc)))

;;;Support subs
;;;(setq dwgname(findfile "AecLayerStd.dwg"))
;;;   Open a dbxDoc      ;
;;;   use (setq dbxDocument(jb:OpenDbxDocument dwgname)) ;
(defun jb:OpenDbxDocument  (DwgName / app doc dbxopen dbxDoc)
  (setq app (vlax-get-acad-object)
        doc (vla-get-ActiveDocument app))
  (if (/= dwgname (vla-get-fullname doc))
    (progn (cond ((= (substr (getvar "ACADVER") 1 5) "15.06")
                  (setq dbxDoc  (vla-GetInterfaceObject app "ObjectDBX.AxDbDocument")
                        dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName))))
                  (setq dbxDoc  (vla-GetInterfaceObject
                                  (strcat "ObjectDBX.AxDbDocument." (substr (getvar "acadver") 1 2)))
                        dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName)))))
           (if (vl-catch-all-error-p dbxopen)
             (setq dbxDoc nil))))

;;; (vlax-dump-Object dbxDoc t)
;;; Close dbxDoc
;;; (jb:CloseDbxDocument dbxDocument)
(defun jb:CloseDbxDocument  (dbxdoc)
  (if (= (type dbxDoc) 'VLA-OBJECT)
    (progn (vlax-release-object dbxDoc) (setq dbxDoc nil))))

Title: Re: Importing AEC Styles
Post by: daron on July 23, 2007, 05:29:45 PM
That's very nice J. I'll have to load it and look into that.