Jump to content

How to Extract information from Autocad drawings quickly?


oldguy

Recommended Posts

I am currently working on autocad data extraction. I have several hundred drawings to extract information from, I tried to use Excel VBA Macro to open these drawing one by one then use the VBA to get information from them. It took me about 2 hours, which is way too long. Does anyone here have a better way to extract information more quickly?

 

Thanks a lot!

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • oldguy

    9

  • ASMI

    7

  • dbroada

    3

  • Issam Rasheed

    1

About what kind of the information there is a speech? It is the size of a file, date of creation and modification, the author, custom properties etc. either what or the information containing in the Block Attributes, the XData or Dictionaries? Many data of a file can be received without its opening.

Link to comment
Share on other sites

Unfortunately to get attributes of the block without opening drawing it is impossible. However to open drawing it is possible not by means of AutoCAD and by means of ObjectDBX - specialized library for access to drawings AutoCAD without use AutoCAD (in hidden mode). It works much more quickly than through AutoCAD. Here a short example with opening drawing and import Layouts: http://www.cadmin.com/VBA_for_ADT/ObjectDBX.htm . You can do it from your Excel VBA macros. If you have AutoCAD in your PC you also have this libruary, see Tools>References in VBA editor.

Link to comment
Share on other sites

do you have access to AutoCAD? I use the AutoCAD VBA interface to extract that sort of information. Do you know how the information is organised? If all your blocks have a similar format name in all cases and you will be extracting items with consistant tags it is relatively easy. If there is little similarity it becomes more tricky.

Link to comment
Share on other sites

I used a database to store all block configurations, and made a VB.net program to extract block definitions, define which attributes I need to extract where should I put in Excel etc. Then I use my Excel macro to read from this database and open drawings one by one then search for appropiate blocks and attributes, then put it in the spread sheet.

 

RealDWG/ObjectDBX™ is too expensive.

Initial license fee (1 year contract) $5,000 USD

Annual license fee $2,500 USD

 

well, maybe I am stucked with my snail VBA method.:cry:

Link to comment
Share on other sites

RealDWG/ObjectDBX™ is too expensive.

Initial license fee (1 year contract) $5,000 USD

Annual license fee $2,500 USD

 

Yes, it's developer kit for professional programers, for incorporating access to *.dwg - format from payment software without AutoCAD. Therefore if you have AutoCAD at your PC, and write programs in LISP or VBA for your own usage you can access to ObjectDBX. AutoCAD that application with which this library (not OpenDWG SDK, but ObjectDBX application for your sigle PC with AutoCAD) already is bought.

 

Certainly if you write the commercial program by means of .NET you should buy it :(

 

I had access to ObjectDBX from only my LISP programs from AutoCAD and I do not know lawfully to do such access from VBA programs in Excel for the own purposes.

Link to comment
Share on other sites

Oh... seems like I miss understood you guys. I just found out the AutoCAD/ObjectDBX libarary in EXCEL.

Everybody in our company has AutoCAD, so they should all have the AXDBLib. I will try to use that to open the drawings and see.

 

Thanks a lot! :D

Link to comment
Share on other sites

Yes you have ObjectDBX in every PC with AutoCAD and it already registred. OpenDWG SDK certainly gives greater opportunities for access to a database *.dwg, however in your case it is not necessary.

Link to comment
Share on other sites

When I use it, it gives me this error:

Automation error

The specified module could not be found.

 

Here is my code:

Dim CADDoc As New AXDBLib.AxDbDocument
CADDoc.Open tmpFile

I have added a reference to my Excel VBA,do you know what happened?

 

Thanks!

Link to comment
Share on other sites

I tested it out, seems like AutoCAD will NOT allow people to use ObjectDBX outside of AutoCAD...:(

 

When I use a AutoCAD VBA macro to extract those several hundred drawings, it only took about 5 minutes, which is way faster than 2 hours. But........I need it in Excel....:cry:

 

By the way, do you know a way to run AutoCAD VBA macro using the Excel macro?:?

 

Or, do you know a way to make the AutoCAD macro to become a menu item? So user can click on that menu and run the macro.

Link to comment
Share on other sites

ASMI obviously knows his stuff more than me but what format do you need in excel? I export my border information into a csv file and open that with excel. Is that an option for you?

Link to comment
Share on other sites

I tested it out, seems like AutoCAD will NOT allow people to use ObjectDBX outside of AutoCAD...

 

It seems that...:( Notwithstanding what all properties and methods are visible the program gives out an error.

 

However Excel it is good accessible from Autocad. Set reference to Excel and try:

 

Function GetExcelObject() As Object
Set GetExcelObject = CreateObject("Excel.Application")
End Function

 

Or, do you know a way to make the AutoCAD macro to become a menu item? So user can click on that menu and run the macro.

 

It is very simple, I tomorrow shall show you. Excuse I again up to sat till 1:45 AM. Tomorrow (today) I shoud stand up for work at 6:00 AM. Sleep...

Link to comment
Share on other sites

Thanks for you reply, here is what I used to access Excel:

apExcel=getObject(,"Excel.Application")
apExcel.ActiveSheet.Cells(1,1)="xxxx"

it will try to control the currently openned Excel file then change it. What I am thinking is, use Excel Macro to open AutoCAD, then load the AutoCAD VBA Macro automatically and run it.

I know it is bad to jump back and forth between two applications, but seems like that is the only choice for me.

 

What I am trying to do is:

try to update an Excel File which lists the drawing No., description, revision No. revision date etc. for several hundred drawings.

Link to comment
Share on other sites

it will try to control the currently openned Excel file then change it. What I am thinking is, use Excel Macro to open AutoCAD, then load the AutoCAD VBA Macro automatically and run it.

I know it is bad to jump back and forth between two applications, but seems like that is the only choice for me.

 

I think run AutoCAD Macro>open drawings with ObjectDBX and find attributes (fast and good works in AutoCAD)>open Excel from AutoCAD and fill cells with data (also work well).

 

>dbroada

I export my border information into a csv file and open that with excel. Is that an option for you?

 

Too a good way. However oldguy wants full automation and speed. And to us it is interesting not only result but also process of programming, we learn a lot of new :)

Link to comment
Share on other sites

>dbroada

 

 

Too a good way. However oldguy wants full automation and speed. And to us it is interesting not only result but also process of programming, we learn a lot of new :)

which is why I asked for a clarification of his use. :D

 

I could see that you are giving him good advice but if he only wanted a list of file name against title (or similar) he didn't need to complicate it so much.

Link to comment
Share on other sites

I don't want to complicate things that much, but I want to make things as user friendly as possible. So... Do you know a way, In Excel Macro, run AutoCAD Macro automatically? like... send the VBALoad command and load specific Macro, then somehow run it?

 

Because when people want to update that spread sheet, they will open that spread sheet first.

 

Thanks!

Link to comment
Share on other sites

Well, I found out the way, just embed the AutoCAD macro in a blank drawing, then automatically run the macro when this blank drawing is opened. ugly, but working. :twisted: :halloween:

 

ASMI, Could you tell me how to make a customized autocad menu Item which links to a AutoCAD VBA macro?

Thanks!

Link to comment
Share on other sites

ASMI, Could you tell me how to make a customized autocad menu Item which links to a AutoCAD VBA macro?

Thanks!

 

Ok.

 

The most of people uses (command "_vbaload"... for loading VBA projects and (command "_vbarun"... for run of procedures. However it is not pleasant to me because these commands not returns value about successful end and at repeated attempt of loading of the project there is alert window 'Project Xxxx.vdb already loaded'. I use own VisualLISP function free from these lacks. It has following syntax:

 

(asmi_RunMacro "ProjectName.vdb" "!Module.Macro" Out)

 

If the argument ' Out ' is equal T (True) function returns T at successful start macro and NIL (False) at failure. If the argument ' Out ' is equal NIL that function does not return any value, only the message about errors in the command line.

 

For button (or PopUp Menu) macro you shood write short *.lsp file for example:

 

(defun c:numb()
 (asmi_RunMacro "AsmiTools.dvb" "!Numerator.Numerator_Show" nil)
 ); end c:numb

 

In this case macro for the button should be following:

 

^C^Cnumb

 

Or 'numb' in command line.

 

File with short lisp and file with folowing code should be added to 'Tools>Load Applications... Startup Suite'

 

 

(defun asmi_GetVBEObject(errMess / vbeObj)
 (if
   (vl-catch-all-error-p
     (setq vbeObj
     (vl-catch-all-apply
       'vla-get-VBE
       (list(vlax-get-acad-object))
       ); end vl-catch-all-apply
    ); end setq
     ); end vl-catch-all-error-p
   (progn
     (if errMes
(alert errMess)
); end if
     nil
     ); end progn
   vbeObj
   ); end if
 ); end of asmi_GetVBEObject



(defun asmi_GetVBAProjectsList(/ vbeObj vbaProj pCount
		       projLst curProj prName)
 (if
   (setq vbeObj
   (asmi_GetVBEObject ">>> ERROR. Can't get VBE object! <<<"))
   (progn
  (setq vbaProj
	 (vlax-get-property vbeObj 'VBProjects)
	pCount
	 (vlax-get-property vbaProj 'Count)
	projLst '()
	); end setq
     (while(/= pCount 0)
(if
  (and
   (not
    (vl-catch-all-error-p
      (setq curProj
	     (vl-catch-all-apply
	       'vlax-invoke-method 
	       (list vbaProj 'Item pCount)
	       ); end vl-catch-all-apply
	    ); end setq
      ); end vl-catch-all-error-p
    ); end not
  (not
    (vl-catch-all-error-p
      (setq prName
	     (vl-catch-all-apply
	       'vlax-get-property
	       (list curProj 'FileName)
	       ); end vl-catch-all-apply
	    ); end setq
      ); end vl-catch-all-error-p
    ); end not
   ); end and
   (setq projLst
       (append projLst
	       (list prName)
	       ); end append
      ); end setq
  ); end if
(setq pCount(1- pCount))
); end while
     ); end progn
   ); end if
 projLst
 ); end of asmi-GetVBAProjectsList


(defun asmi_RunMacro(Project Macro Out / acApp dvbPath
	     actDoc errMes outVal lFlag )
 (setq acApp
 (vlax-get-acad-object))
 (if
   (not
     (member Project
      (asmi_GetVBAProjectsList)))
  (if
    (setq dvbPath
	   (findfile Project))
      (if
	 (vl-catch-all-error-p
		 (vl-catch-all-apply
		   'vla-loaddvb
		   (list acApp dvbPath)
		   ); end vl-catch-all-apply
		 ); end vl-catch-all-error-message
	      (princ
		(strcat "\n>>> ERROR. Can't load VBA project \""
			Project "\" >>> ")
		); end princ
	(setq lFlag T)
	); end if
    (princ
      (strcat "\n>>> ERROR. VBA project \""
	      Project "\" not found! <<< "); end strcat
      ); end princ
    ); end if
   (setq lFlag T)
   ); end if
 (if lFlag
   (if
      (vl-catch-all-error-p
   (vl-catch-all-apply
     'vla-runmacro
	(list acApp
		(strcat Project Macro)
		); end list
	   ); end vl-catch-all-apply
	); end vl-catch-all-error-message
	(princ
	  (strcat "\n>>> ERROR. Can't run VBA macro \""
		  Macro "\" >>> ")
	); end princ
	(setq outVal T)
); end if
   ); end if
   (if Out outVal(princ))
 ); end of asmi_RunMacro

(vl-load-com)

Link to comment
Share on other sites

  • 6 months later...

I am also trying to do the same for some drawings converted from tif format to autocad ? How can this be done ? Please advise.

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...