Announcements

Announcement: We’re aware of an issue affecting starting a new topic from category pages and creating new blog posts. New topics can still be started directly from the relevant board. Learn more here.

Tool to extract PDF information from DWG title blocks

Tool to extract PDF information from DWG title blocks

JS808
Participant Participant
2,333 Views
25 Replies
Message 1 of 26

Tool to extract PDF information from DWG title blocks

JS808
Participant
Participant

Afternoon all,

 

We are looking for a way to extract information from a bulk lot of DWG files without opening each one individually and typing up. Namely, drawing number, title and revision number. 

 

Does anyone know of a way to do this other than pay for a very expensive subscription? 

 

Thanks

 

 

@JS808 - topic title has been adjusted for clarity. Original 'Tool to extract information from DWG title blocks'

0 Likes
2,334 Views
25 Replies
Replies (25)
Message 2 of 26

cadffm
Consultant
Consultant

Hi,

 

do you mean WITHOUT a installed AutoCAD?

If so, you need another program to do that, windows can't read dwg files.

 

I guess you will not find one for 0$

(Except by using a lot of free tools and a lot of knowledge about the skills you need).

Sebastian

0 Likes
Message 3 of 26

JS808
Participant
Participant

Hi, we do have Autocad available. 

 

Or if anyone knows the most cost effective way of doing this via a program that would also be helpful.

0 Likes
Message 4 of 26

cadffm
Consultant
Consultant

 

 

Hi,

I can't post a 100.0% perfect answer for you, because I would need some more informations, what I won't ask them all, so let's try without:

 

there are a lot of tools what can do that, if you are talking about Block-Attributs (your title is a block with attributes).

The best&fastest way, is to use a 3rd party tool, out there, there are a lot of such tools.

A challange to find the one what is best matching your needs.

 

And one commands ootb!

DATAEXTRACTION [F1]

 

Sample of one of a hundred 3rd party tools (tools to load & run inside Acad): Click!

 

Sebastian

0 Likes
Message 5 of 26

JS808
Participant
Participant

Thanks, am i correct in saying the dataextraction command needs to be run with Autocad open? 

 

I am looking for something that can look at a folder of say 300 DWG's (or PDF's if easier) and extract Drawing number, title and revision. 

0 Likes
Message 6 of 26

DGCSCAD
Advisor
Advisor

A few questions to help this along:

 

1. How are the Drawing Number, Title, and Revision stored within each .dwg?

  • Block with Attributes
  • MText or Text
  • Table

 

2. How is the above information organized?

  • Modelspace
  • Paperspace

 

3. Are all drawings consistent?

4. Are all drawings located in the same folder?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 7 of 26

JS808
Participant
Participant

Hi thanks for your reply,

 

1. This will either be Block with Attributes or MText/Text. This will be consistent though so it wont be a mix of the two, just may differ from project to project.

 

2. Paperspace

 

3. Yes, all drawings will use the same title block arrangement. 

0 Likes
Message 8 of 26

DGCSCAD
Advisor
Advisor

The differences between programmatically selecting Attributes with a consistent name and MText/Text objects with varying contents is significant.

 

If you upload a sample .dwg of each of those, that would allow for a clearer path to a solution.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 9 of 26

cadffm
Consultant
Consultant

"I am looking for something that can look at a folder of say 300 DWG's (or PDF's if easier) and extract Drawing number, title and revision. "

That's what I understood as task, yes.

 

"Block with Attributes or MText/Text. "

MText/Text is much harder and there is no "just 2 clicks" solutions.

First, lets talk about the blocks with attributs only!

 

 

Acad open or not doesn't matter for your Task! 

Yes, both working inside an open AutoCAD instance.

 

Now, test both

Test it with just few files in a folder.

 

You need to know blockname(s) 

The 3rd party tool ask for a folder,

the ootb Dataextraction for files - bu in autoCAD file selection dialog, you have extra-search option and you can search for all files in  a folder&subfolder

 

Goog luck

 

Sebastian

0 Likes
Message 10 of 26

JS808
Participant
Participant

Hi, please find attached examples. 

0 Likes
Message 11 of 26

DGCSCAD
Advisor
Advisor

For the TEXT example:

 

Will there be other size titleblocks?

 

If no, then as long as these A1 titleblocks are placed consistently in relation to 0,0, then a single predefined selection window would pick those up.

If yes, then multiple conditions would need to be addressed, being predefined selection windows for each titleblock size, but that also is dependent upon these titleblocks being consistently placed in relation to 0,0.

 

I'm just flushing out all the variables and constants to form a possible solution. I have an idea of how to approach this, and it's absolutely possible, but my time is limited. If someone else doesn't come along and pick this up from here, I'll post something up.

 

Edit: Since there is a block that the text resides within, the selection window for the text can be achieved regardless of where the titleblock resides in space.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 12 of 26

DGCSCAD
Advisor
Advisor

Also, where will this extracted information end up?

 

Do you simply need a list in a text file?

Excel spreadsheet?

AutoCad Table?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 13 of 26

daniel_cadext
Advisor
Advisor

You will need an instance of CAD open regardless if you choose data extraction or lisp.

If you have PDFs, you can do this outside of CAD using Python, PyPdf, and Pandas (to filter the data)

Any AI can generate this code for you

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 14 of 26

daniel_cadext
Advisor
Advisor

Since I wrote this without fully reading the requirements. Here’s a sample pattern to extract attributes with Python. Again, using pandas for data analysis.

 

from pyrx import Ap, Db
from collections import defaultdict
import traceback
import pandas as pd
# requires pandas and openpyxl 

# provides a scope
def process_database(db: Db.Database,name: str, data : dict[str,list[str]] ):
    for k, v in db.getBlocks().items():
        if name.casefold() != k.casefold():
            continue
        btr = Db.BlockTableRecord(v)
        refs = [Db.BlockReference(id) for id in btr.getBlockReferenceIds()]
        atts = [Db.AttributeReference(id) for ref in refs for id in ref.attributeIds()]
        for att in atts:
            data[att.tag()].append(att.textString())
        
# provides a scope, you don't want 300 drawings loaded into memory 
def open_database(_path : str, name: str, data : dict[str,list[str]]):
    sdb = Db.Database(False,True)
    sdb.readDwgFile(_path)
    sdb.closeInput(True)
    process_database(sdb, name, data)
  
# adds a new autocad command 'doit'  
@Ap.Command()
def doit():
    try:
        #use listFilesInPathRecursive for nested folders of drawings
        data = defaultdict(list)
        for _path in Ap.Application.listFilesInPath("E:\\FloorPlans", '.dwg'):
            open_database(_path,"RMNUM", data)
            
        df = pd.DataFrame.from_dict(data)
        with pd.ExcelWriter("E:\\FloorPlans\\my_data.xlsx") as writer:
            df.to_excel(writer, sheet_name='Sheet1') 
    except Exception:
        print(traceback.format_exc())

 

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 15 of 26

Sea-Haven
Mentor
Mentor

Like others if its a block with attributes then no problems you can have different title blocks, they can be in Model or in layouts. Getting the answer for mtext I can see real problems. You can use a XY for each mtext position, you have a block so can get insert position of that block and adjust all XY of attributes if the block is not at 0,0. 

 

Because you want to do 300 dwg's three choices a script, OBDX or use Accoreconsole, writing a csv would be easiest, as write-file supports the "Append" option.

 

Looks like maybe result to Excel. Again can write direct to Excel but need to keep track of row number, or insert a row and add details, you can insert a row via lisp in Excel. Please confirm Excel is desired result.

 

I think a script would be simplest do a few at a time. 

 

Only one more question does the dwg have more than one layout, its not a problem to look in all layouts.

0 Likes
Message 16 of 26

JS808
Participant
Participant

Hi there, turns out i have misunderstood what was being asked and the vast majority of this will be done using PDF's rather than DWG's. 

 

I am getting this info second hand but apparently we have tried using Python and it has struggled to extract only the text needed. 

 

The extracted data would ideally go straight to an Excel spreadsheet. 

 

edit:  also there will most likely be a mix of A1, A0, A2 title blocks.

0 Likes
Message 17 of 26

DGCSCAD
Advisor
Advisor

A non-programmatical solution for PDF's:

 

  • Open Windows Snipping Tool
  • Window the Portion of text you need
  • Upload that image to Copilot/AI with instructions to extract text in a list
  • Copy/Paste

 

Not very practical for 300 PDF's, but I figured I'd mention it as a control group of sorts. In the name of science. 🙂

 

Edit: This method is for PDF's saved as raster (worst case scenario).

AutoCad 2018 (full)
Win 11 Pro
Message 18 of 26

Sea-Haven
Mentor
Mentor

My $0.05 if PDF's then hire someone to sit there and copy and paste between pdf and Excel. At worst type in.

 

Where are original Dwg's ? Do you not have access to them.

Message 19 of 26

pendean
Community Legend
Community Legend

@JS808 wrote:........vast majority of this will be done using PDF's rather than DWG's. 

You're going to need to purchase a PDF to DXF/DWG 3rd party converter tool then you can use the DWG tools everyone here is proposing.

Whip out a credit card and remember to try before you buy.

 

OR... this would be a great task for Interns to tackle the long free way as explained by others.

0 Likes
Message 20 of 26

Sea-Haven
Mentor
Mentor

Have you tried the inbuilt pdf import, what does it produce ? If it looks like it is useful ie makes text then post a sample dwg, so people can have a look at it to see what can be done. Only need the relevant part of a dwg.

0 Likes