Author Topic: Check drawing for dynamic Block?  (Read 4256 times)

0 Members and 1 Guest are viewing this topic.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Check drawing for dynamic Block?
« on: December 05, 2012, 02:55:44 AM »
Hi All

Is there a way to check a drawing, without open the file in AutoCAD, for 'is it dynamic block'?
Comparable with the reading of the drawing file version.
I Know, the other way is temporary add the Block file with ObjectDBX and read the flag but... :-(

Cheers
« Last Edit: December 05, 2012, 08:25:12 AM by Jürg Menzi »
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Check drawing for dynamic Block?
« Reply #1 on: December 05, 2012, 03:48:08 AM »
You don't need to insert the DWG to find out if it's a DB, but you do need ObjectDBX. Find the model-space block of the DWg and see if its DB setting is on E.g.
Code - Auto/Visual Lisp: [Select]
  1. (defun IsDWG-DB-p (filename / acver dbx blk db)
  2.                                              (if (< (setq acver (atoi (getvar "ACADVER"))) 16)
  3.                                                "ObjectDBX.AxDbDocument"
  4.                                                (strcat "ObjectDBX.AxDbDocument." (itoa acver)))))
  5.            (setq filename (findfile filename))
  6.            (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbx filename))))
  7.            (not (vl-catch-all-error-p (setq blk (vl-catch-all-apply 'vla-Item (list (vla-get-Blocks dbx) "*Model_Space"))))))
  8.     (setq db (= (vla-get-IsDynamicBlock blk) :vlax-true)))
  9.   (foreach obj '(dbx blk) (vl-catch-all-apply 'vlax-release-object (list (eval obj))))
  10.   db)
Unfortunately I don't know of a way to read the raw DWG and find this info. It depends on where in the file the MS block's definition is saved.
« Last Edit: December 05, 2012, 03:52:44 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check drawing for dynamic Block?
« Reply #2 on: December 05, 2012, 05:28:55 AM »
Here is another version:

Code - Auto/Visual Lisp: [Select]
  1. (defun _dynamicblockfile-p ( dwg / doc lst rtn )
  2.     (setq rtn
  3.         (and (setq dwg (findfile dwg))
  4.             (or
  5.                 (setq doc
  6.                     (cdr
  7.                         (assoc (strcase dwg)
  8.                             (vlax-for doc (vla-get-documents (vlax-get-acad-object))
  9.                                 (setq lst (cons (cons (strcase (vla-get-fullname doc)) doc) lst))
  10.                             )
  11.                         )
  12.                     )
  13.                 )
  14.                 (and
  15.                     (setq doc
  16.                         (vla-getinterfaceobject (vlax-get-acad-object)
  17.                             (if (< (atoi (getvar 'acadver)) 16)
  18.                                 "ObjectDBX.AxDbDocument"
  19.                                 (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'acadver))))
  20.                             )
  21.                         )
  22.                     )
  23.                     (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list doc dwg))))
  24.                 )
  25.             )
  26.             (= :vlax-true (vla-get-isdynamicblock (vla-get-modelspace doc)))
  27.         )
  28.     )
  29.     (if (= 'vla-object (type doc))
  30.         (vlax-release-object doc)
  31.     )
  32.     rtn
  33. )

pBe

  • Bull Frog
  • Posts: 402
Re: Check drawing for dynamic Block?
« Reply #3 on: December 05, 2012, 06:40:15 AM »

.
Code - Auto/Visual Lisp: [Select]
  1. (defun IsDWG-DB-p (filename / acver dbx blk db)
  2. ....)

Here is another version:

Code - Auto/Visual Lisp: [Select]
  1. (defun _dynamicblockfile-p ( dwg / doc lst rtn )
  2.    ........


Nice LM /Irné  8) 


I still have much to learn from you guys  :)

« Last Edit: December 05, 2012, 06:55:20 AM by pBe »

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check drawing for dynamic Block?
« Reply #4 on: December 05, 2012, 06:53:36 AM »

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Check drawing for dynamic Block?
« Reply #5 on: December 05, 2012, 06:59:23 AM »
Thank you both!

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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Check drawing for dynamic Block?
« Reply #6 on: December 05, 2012, 07:06:23 AM »
You're welcome. And thanks for the compliment.
 
Though I wish there was some raw thing to read like the file version inside the DWG file. That would mean this could work on Mac as well. As it is the ObjectDBX & ActiveX functions preclude any usuage on an "Apple-CAD"  ::) .
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Check drawing for dynamic Block?
« Reply #7 on: December 05, 2012, 07:52:35 AM »
Here is another version:

Code - Auto/Visual Lisp: [Select]
  1. ...
  2.                 (setq doc
  3.                     (cdr
  4.                         (assoc (strcase dwg)
  5.                             (vlax-for doc (vla-get-documents (vlax-get-acad-object))
  6.                                 (setq lst (cons (cons (strcase (vla-get-fullname doc)) doc) lst))
  7.                             )
  8.                         )
  9.                     )
  10.                 )
  11. ...
  12.  

Lee Mac, a last question:
The sense of the quoted part above is to check the current drawing for open documents they possibly are Dyn Blocks - correct?

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

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check drawing for dynamic Block?
« Reply #8 on: December 05, 2012, 08:07:31 AM »
Here is another version:

Code - Auto/Visual Lisp: [Select]
  1. ...
  2.                 (setq doc
  3.                     (cdr
  4.                         (assoc (strcase dwg)
  5.                             (vlax-for doc (vla-get-documents (vlax-get-acad-object))
  6.                                 (setq lst (cons (cons (strcase (vla-get-fullname doc)) doc) lst))
  7.                             )
  8.                         )
  9.                     )
  10.                 )
  11. ...
  12.  

Lee Mac, a last question:
The sense of the quoted part above is to check the current drawing for open documents they possibly are Dyn Blocks - correct?

Almost -
Assuming MDI mode, if the supplied drawing filename is already open in AutoCAD (and hence resides in the Documents Collection), the use of the Open method on the ObjectDBX Document will fail as the drawing will be read-only. My code is checking the Documents Collection for the drawing file and, if present, will use the Document Object of the open file before creating the ObjectDBX Document.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Check drawing for dynamic Block?
« Reply #9 on: December 05, 2012, 08:13:46 AM »
Perhaps then this code should suffice:
Code - Auto/Visual Lisp: [Select]
  1. (defun IsDWG-DB-p (filename / acver dbx blk db)
  2.                                              (if (< (setq acver (atoi (getvar "ACADVER"))) 16)
  3.                                                "ObjectDBX.AxDbDocument"
  4.                                                (strcat "ObjectDBX.AxDbDocument." (itoa acver)))))
  5.            (setq filename (findfile filename))
  6.            (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbx filename :vlax-true))))
  7.            (not (vl-catch-all-error-p (setq blk (vl-catch-all-apply 'vla-Item (list (vla-get-Blocks dbx) "*Model_Space"))))))
  8.     (setq db (= (vla-get-IsDynamicBlock blk) :vlax-true)))
  9.   (foreach obj '(dbx blk) (vl-catch-all-apply 'vlax-release-object (list (eval obj))))
  10.   db)
I.e. always open it in read-only mode. Especially since the defun is not supposed to modify anything inside the DWG file.
 
Sorry, haven't tested - but would a normal ObjectDBX open still work if another session / user has the file open?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Check drawing for dynamic Block?
« Reply #10 on: December 05, 2012, 08:23:15 AM »
@Lee Mac:
Aah, that's it. Thank you.

@irneb:
The open method fails in this case.

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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Check drawing for dynamic Block?
« Reply #11 on: December 06, 2012, 03:49:54 AM »
This is very strange ... one would expect opening the file as readonly through DBX would allow it to open even if someone else has it open already.
 
So what can one do in this case? Even Lee's code will fail if the DWG is opened in another session / by another user.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Check drawing for dynamic Block?
« Reply #12 on: December 06, 2012, 04:03:10 AM »
Quote
So what can one do in this case?
Because I use ObjectDBX mostly for unattended jobs, the program writes a log file. If the open method fails, an entry will be written with file name and error message.

Quote
Even Lee's code will fail if the DWG is opened in another session / by another user.
Yes, thats correct.

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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Check drawing for dynamic Block?
« Reply #13 on: December 06, 2012, 04:28:53 AM »
Sorry, yes I understand about logging errors and so. I'm just posting to see if someone else has an answer which would still open the file in read-only mode, since in my case there's lots of change that another user would have at least one of the DWGs open. Apparently ODBX just does not handle this.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check drawing for dynamic Block?
« Reply #14 on: December 06, 2012, 03:31:13 PM »
I don't think there is anything in Lisp alone that can open a drawing in read-only mode, without opening it in the Acad window session.  This is one reason why I went to .Net.  If someone wanted to they could write some .Net code for lisp to open a drawings database only in read-only mode.
Tim

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

Please think about donating if this post helped you.