Accessing and Manipulating Multiple DWG Files Simultaneously

Accessing and Manipulating Multiple DWG Files Simultaneously

bahayalnizhotmail_com
Participant Participant
573 Views
4 Replies
Message 1 of 5

Accessing and Manipulating Multiple DWG Files Simultaneously

bahayalnizhotmail_com
Participant
Participant

Hi everyone,

 

I'm a civil engineering student working in a construction company as an intern. I want to automate some of the jobs here and one of them is the one that I'm about to explain.


Actually the subject of the question is as simple as it looks in the title.

But let me explain in more detail:

 

Preliminary information:

  • We have hundreds of project files.
  • The project letterhead is located in a block in the right corner of the project files. (figure 1).
  • The main goal is to change these current letterhead designs for each project with the reference one (figure 2).
  • After changing the letterhead designs, some values on the letterhead should also change (possibly the values based on the filename such as "project_no", "project_code" etc.).
  • I usually program with Python and am quite familiar and have some experience with the Revit API and pyRevit. But I started learning VLISP for this project. Then I realized that VLISP might not be the best way to do this task as there are multiple files involved.
  • I am totally open to learn new stuff and I'm not looking for an exact solution. All I need is guidance.

 

 

resim_2023-06-01_105311181.png

 

Figure 1 - The current letterhead design

 

 

bahayalniz_0-1685606154109.png

Figure 2 - Reference letterhead to replace original letterheads

 

 

flowchart_V2.png

Figure 3 - The workflow in my mind

 

Questions:

  1. Which workflow should I follow to make this task done considering the content of the work? VLISP, ObjectARX, Managed.Net or VBA?
  2. Is it logical to use VLISP to manage multiple files simultaneously? If so, what path should I follow to do this?
  3. Is it logical to use RealDWG for such a job?

 

Note: It's not possible for me to share the project files for privacy reasons.

0 Likes
Accepted solutions (1)
574 Views
4 Replies
Replies (4)
Message 2 of 5

daniel_cadext
Advisor
Advisor

Definitely need something more powerful than lisp.  I’d recommend .net,  where you can open side databases

Not really trivial, no matter what API you choose

 

Google C# readDwgFile

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

daniel_cadext
Advisor
Advisor

Didn’t want to mention this, but. If you still want to use python, I’ve been working on an open-source project wrapping a few ARX functions

 

https://github.com/CEXT-Dan/PyRx , I’m only about 20% done and there’s probably bugs. But I probably have enough done to work on side databases.

 

import PyRxApp
import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed

import traceback

def PyRxCmd_test1():
    try:
        db = Db.Database(False,True)
        db.readDwgFile("path to drawing")
        db.closeInput(True)
        blockTable = Db.BlockTable(db.blockTableId(), Db.OpenMode.ForRead)
        blockIds = blockTable.recordIds()
        for id in blockIds:
            record = Db.BlockTableRecord(id,Db.OpenMode.ForRead)
            if record.getName() == "myBlock name":
                entids = record.objectIds()
                for eid in entids:
                    if Db.objectClass().isDerivedFrom(Db.AttributeDefinition.desc()):
                        att = Db.AttributeDefinition(eid,Db.OpenMode.ForWrite)
                        textval = att.textString()
                        if textval == "valtobechanged":
                            att.setTextString("new value")
                            
    except Exception as err:
        print(traceback.format_exc())
        
                            
def PyRxCmd_test2():
    try:
        
        db = Db.HostApplicationServices().workingDatabase()
        
        blockdb = Db.Database(False,True)
        blockdb.readDwgFile("M:\\Dev\\Projects\\PyRxGit\\PySamples\\dwg\\18X36RP.dwg")
        blockdb.closeInput(True)
        
        blockid = Db.ObjectId()
        db.insert(blockid, "block",blockdb, True)
        
    except Exception as err:
        print(traceback.format_exc())
        
        

 

 

BTW, you can find me at the swamp https://www.theswamp.org/

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 4 of 5

paullimapa
Mentor
Mentor

If you can code this using Visual Lisp, you'll just have to learn how to create Script files then there are options for you to run the code on multiple drawings using one of the following additional free tools:

1. ACCoreConsole.exe which comes with AutoCAD and allows you to run a script file on all drawings under a specific folder without even opening AutoCAD. You can read up more about it here.

2. ScriptPro (originally developed by Autodesk but has since dropped further development) offers the option to run a script file on multiple selected drawings. You can download the installer here.

3. AutoScript (similar to ScriptPro) which is a free add-on that gives you the capability of selecting multiple drawings to run a script file 

4. Script Writer another free add-on written as lisp code to run a single line of commands on multiple dwgs

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 5

bahayalnizhotmail_com
Participant
Participant
Accepted solution

@daniel_cadext , I also believe that the .NET framework is a superior way to automate work in a more efficient and powerful manner. Unfortunately, I was unaware of this when I initially began my project. Currently, I have a solution in VLISP for this specific project, which I will discuss further in my reply.

 

I would prefer to utilize and contribute to Python development if I had more time for this project. Unfortunately, it doesn't seem feasible at the moment due to my limited time constraints. However, I have saved your repository for future reference, and I will examine it more closely at a later time.

 

@paullimapa, thank you for your suggestions. I have gathered numerous LISP code snippets and merged them as shown below


To get files:
http://lee-mac.com/getfilesdialog.html

 

To remove blocks:
http://lee-mac.com/deleteblocks.html

To navigate around the files
http://lee-mac.com/odbxbase.html

This is the code that I used to combine all:

 

(defun c:remove_it (/ lst) 
  (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")) 
    (LM:odbx '(lambda (doc) (LM:deleteblocks doc '("BLOCK NAME"))) lst t)
    (princ "\n*Cancel*")
  )
  (princ)
)

 

 

After using this code, I used the following to insert the new letterhead:
http://www.lee-mac.com/copytodrawing.html

Thanks for your valuable time and attention.
Baha




0 Likes