Author Topic: Open Drawing in the Background???  (Read 5439 times)

0 Members and 1 Guest are viewing this topic.

mgreven

  • Guest
Open Drawing in the Background???
« on: February 07, 2012, 10:06:56 AM »
When i open a drawing with vla-open (without activate), the screen shows the drawing for a short time.
Is there a way to open the drawing without the screen "flipping"?


 

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Open Drawing in the Background???
« Reply #1 on: February 07, 2012, 10:10:44 AM »
I'm not sure what your task entails, but you may want to look into ObjectDBX if you are looking to interface with a drawing without actually opening it.

mgreven

  • Guest
Re: Open Drawing in the Background???
« Reply #2 on: February 07, 2012, 10:17:33 AM »
I want to open a drawing in the background to get some attributes from some blocks in the drawing to use in the current drawing.

It is a long time ago that i used Lisp. ObjectDBX is unknown to me.
Where can i find out more about it?

Regards,

Marco

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Open Drawing in the Background???
« Reply #3 on: February 07, 2012, 10:20:52 AM »
I keep reading your name as mrgreen. lol

Search on here, there's TONS of ODBX examples.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Open Drawing in the Background???
« Reply #4 on: February 07, 2012, 10:24:35 AM »
Yep: just look through those posts linked to in CAB's post #2 here: http://www.theswamp.org/index.php?topic=40810.0
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

mgreven

  • Guest
Re: Open Drawing in the Background???
« Reply #5 on: February 07, 2012, 12:33:14 PM »
There are different examples which differ for the AutoCAD version.

I use AutoCAD 2012 and trying the following code, but it is not working:

(Defun c:test ()
  (setq *acad* (vlax-get-acad-object))
  (setq oDBX (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.18"))
  (Setq FullDwgName "c:\\test.dwg")
  (setq SourceDwg (vla-open odbx FullRefDwgName))
)

In some posts on the autodesk forum they say that it is not necessary to register the dll anymore?
What am i doing wrong?





mgreven

  • Guest
Re: Open Drawing in the Background???
« Reply #6 on: February 07, 2012, 03:51:12 PM »
ok... i have it figured out...

For anyone who wants to use ObjectDBX with AutoCAD 2012:

;; Calls REGSVR32 to Register a DLL silently via the /S option
(defun DLLRegister (dll)
   (startapp "regsvr32.exe" (strcat "/s \"" dll "\""))
)

;; Calls REGSVR32 to Un-Register a DLL silently via the /U /S option
(defun DLLRegister (dll)
   (startapp "regsvr32.exe" (strcat "/u /s \"" dll "\""))
)

;; Returns the ProgID for a given ClassID if found in registry
(defun ProgID->ClassID (ProgID)
   (vl-registry-read
      (strcat "HKEY_CLASSES_ROOT\\" progid "\\CLSID")
   )
)

;; Registers ObjectDBX(if not already), Returns ProgID if succesful
(defun DBX-Register ( / classname)
   (setq classname "ObjectDBX.AxDbDocument.18")
   (cond
      ( (ProgID->ClassID classname) )
      ( (and
            (setq server (findfile "AxDb.dll"))
            (DLLRegister server)
            (ProgID->ClassID classname)
         )
        (ProgID->ClassID classname)
      )
      ( (not (setq server (findfile "AxDb.dll")))
          (alert "Error: Cannot locate ObjectDBX Type Library (AxDb.dll)...")
      )
      ( T
          (DLLRegister "ObjectDBX.AxDbDocument")
          (or
            (ProgID->ClassID "ObjectDBX.AxDbDocument.18")
            (alert "Error: Failed to register ObjectDBX ActiveX services...")
         )
      )
   )
)

;; Function opens a remote drawing document and returns the DBX document
;; if succesful, otherwise returns NIL
(Defun DBX-doc-open (filename / dbxdoc)
  (cond
    ((findfile filename)
     (if (not (DBX-Register))
       (exit)
     )
     (setq dbxdoc
       (vla-getinterfaceobject
         (vlax-get-acad-object)
         "ObjectDBX.AxDbDocument.18"
       )
     )
     (cond
       ((vl-catch-all-error-p
     (vl-catch-all-apply
       'vla-Open
       (list dbxdoc (findfile filename))
     )
   )
   (Princ "\nUnable to open drawing.")
   (exit)
       )
       (T dbxdoc)
     )
    )
  )
)

Thanks guys... for putting me on the right track...


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Open Drawing in the Background???
« Reply #7 on: February 08, 2012, 02:49:33 AM »
Here's my version, most of those regsvr stuff is the same. But mine works for any acad version (i.e. 18, 17, 16, etc.):
Code: [Select]
(vl-load-com)

;;; Calls REGSVR32 to Register a DLL silently
(defun DLLRegister (dll) (startapp "regsvr32.exe" (strcat "/s \"" dll "\"")))

;;; Returns the ProgID for a given ClassID if found in registry
(defun ProgID->ClassID (ProgID) (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\" progid "\\CLSID")))

;;; Try to Register ObjectDBX if not done so already
;;; Returns the Class Name if already registered / sucessfully registered
;;; Else returns nil if failure
(defun DBX-Register (classname filename / server acver)
  (cond
    ((not (and classname filename))
     (DBX-Register
       (strcat "ObjectDBX.AxDbDocument." (itoa (setq acver (atoi (getvar 'ACadVer)))))
       (strcat "AxDb" (itoa acver) ".dll")
     )
    )
    ((ProgID->ClassID classname) classname)
    ((setq server (findfile filename))
     (cond
       ((and (DLLRegister server) (ProgID->ClassID classname)) classname)
       (t nil)
     )
    )
    (t (DBX-Register "ObjectDBX.AxDbDocument" "AxDb.dll"))
  )
)

;;; Try to reference ObjectDBX - returns the ActiveX object if sucessful
;;; Else returns nil if failure
(defun Get-ObjectDBX (/ classname)
  (if (setq classname (DBX-Register nil nil))
    (vla-getinterfaceobject (vlax-get-acad-object) classname)
  )
)

;;; Try to open an ObjectDBX document. Returns ActiveX object if sucessful, else nil
(defun Open-DBXdoc (filename / dbx)
  (if (and (setq dbx (findfile filename))
           (setq dbx (Get-ObjectDBX))
           (not
             (vl-catch-all-error-p (setq dbx (vl-catch-all-apply 'vla-Open (list dbx (findfile filename)))))
           )
      )
    dbx
  )
)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

mgreven

  • Guest
Re: Open Drawing in the Background???
« Reply #8 on: February 08, 2012, 04:11:33 AM »
Thanks for your reply...

I use AutoCAD 2012, but it is usefull to have the code version independent...

Regards,

Marco