Request for AutoLISP Program for Automatic Loop Drawing Index Generation

Request for AutoLISP Program for Automatic Loop Drawing Index Generation

subashtamang05041988
Participant Participant
706 Views
17 Replies
Message 1 of 18

Request for AutoLISP Program for Automatic Loop Drawing Index Generation

subashtamang05041988
Participant
Participant

Dear Experts, Could you please assist in developing an AutoLISP program to automatically generate an index for multiple loop drawings? For your reference, I have attached a sample index drawing template along with several loop drawing files. The intention is for the AutoLISP program to extract the required information from the loop drawings and automatically populate the index in the provided template.I would greatly appreciate it if you could review the attached files and advise whether this can be achieved through AutoLISP. If there are any other improvements or automation possibilities that can be incorporated, your suggestions would also be highly appreciated.Thank you in advance for your support and assistance.

0 Likes
707 Views
17 Replies
Replies (17)
Message 2 of 18

Sea-Haven
Mentor
Mentor

 Yes can be done, as you want to read multiple dwgs that adds to the complexity so not a 5 minute coding task. I have a make a index of current dwg but it uses layouts. Very simply reads the title block attributes in each layout and makes a table. 

 

Looking at the sample dwgs is there any reason why those dwg's are not all in your master dwg "Sample layouts" and use layouts ? I had 88 layouts in one dwg. happy to provide code matching layouts. It would need a subtle change to allow for 2 columns.

 

There may also be more complications as you have "Sheet of 840" so 840 individual dwg's ?

0 Likes
Message 3 of 18

subashtamang05041988
Participant
Participant

Dear Sea-Haven,

Thank you for the explanation. Yes, the drawings will be individual DWG files, and all drawing information will be in Model Space only we will not be using layouts. What I need is for the LISP to read the required title block attributes from each DWG and populate the information into the provided sample index template The required information is Sheet No. Drawing Title to be taken from the 4th row Loop drawing Revision Date-0 Revision Date-1 Final Revision Date All these details need to be automatically filled into the corresponding fields/cells in the sample index template. There is also a limitation in the template: one index template can accommodate a maximum of 60 sheets. If there are more than 60 drawings/sheets, the LISP should automatically create/use another copy of the same template and continue populating the remaining sheets. For example, if there are 840 individual DWG files, the LISP should read all 840 drawings from the selected folder and automatically generate the required index pages/templates, with 60 sheets per template. So, the main requirement is to process multiple individual Model Space DWG files rather than multiple layouts within a single master DWG.

0 Likes
Message 4 of 18

pbejse
Mentor
Mentor

I'm not sure where this information is being sourced from. Are the sample drawings Loop-1 and Loop-2 related to the entries shown in the drawing index? If so, I can't see where the corresponding data is coming from.  If not, could you please show us the expected or correct data for Loop-1 and Loop-2 so we can better understand the intended output?

Loop No. and Dwg no. appears to be the same for both Loop-1 and Loop-2 drawing file. 
TITLE on the drawing index for 17 and 18 is the same as well.

 

pbejse_0-1789470047519.png

 



0 Likes
Message 5 of 18

subashtamang05041988
Participant
Participant

Dear pbese,

Please find below screen shot for your reference.

 

subashtamang05041988_0-1789471181162.png

Regards,

Subash

0 Likes
Message 6 of 18

Sea-Haven
Mentor
Mentor

Not sure how long it will take to read 840 dwgs using either OBDX or Aeccorconsole which look inside a dwg without opening it. Using OBDX can do all the work inside say a lisp, using Aeccoreconsole would write a csv file that is then read to make a index.

 

So before me or probably some one else does something are the 840 dwg's all in one directory or spread over multiple directories, the multiple directories requires more work making a big list to look into each dwg.

 

 

 

0 Likes
Message 7 of 18

Sea-Haven
Mentor
Mentor

Just another question to simplify the task. Can the Rev. date be a single cell so no horizontal line between them ? The image in yellow is a table, rather than lines and text. I see getting table correct as first task.

 

SeaHaven_0-1789530897164.png

SeaHaven_1-1789530983560.png

 

In your example you have a Rev/ Date, but there is no date in the title block, where is it ?

 

I realise may need two versions of this task, "does the details already exist so update the index", else "add the current dwg details in correct order by sheet number". Also can not use fields. Maybe even a 3rd option Excel link.

 

SeaHaven_0-1789533924942.png

 

 

 

0 Likes
Message 8 of 18

subashtamang05041988
Participant
Participant

Dear Sea-Haven, The table format should remain exactly the same as the sample index template I provided instead of creating a new template. The Revision and Date shall be taken from the Revision History in the Index Sheet There should not be separate Revision and Date fields for each individual loop drawing, even when multiple loop drawings are included. Loop Drawings only the Sheet Number and Title/Name should be extracted and populated in the index. Please follow the same format and structure as the sample index template provided.

0 Likes
Message 9 of 18

Sea-Haven
Mentor
Mentor

 You missed the question in your sample dwg you have the Revision and date separated by a horizontal line. I am asking do we need the line rather than this in the box, it makes the whole idea of using a Table as a result with an extra complication. Lots of merged cells.

 

"A"

16/09/26

 

This is a big task given the number of separate dwg's involved in future projects. Its not a 5 minute answer iI think it borders on a paid for solution maybe a .NET solution to get the speed of an answer.

 

Again "In your example you have a Rev/ Date, but there is no date in the title block, where is it ?"

 

 

 

 

 

0 Likes
Message 10 of 18

Sea-Haven
Mentor
Mentor

Ok reread the posts understand you will fill in Rev and date into index. Will try to do something.

This is a 1st attempt and uses OBDX to read the other dwg's. Limited testing. At the moment it will only work for up to 20 dwg's but that should be ok for a couple of tests and comments. Its not super fast doing 840 in one go no idea how long it will take. Maybe Aeccoreconsole is the way to go.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/request-for-autolisp-program-for-automatic-loop-drawing-index/td-p/14264973

; do index of multiple dwg's
; By AlanH Sept 2026

(defun doindex (lst2 row / )
  (foreach val lst2
    (vla-settext objtable row 0 (nth 1 val))
    (vla-settext objtable row 1 (nth 0 val))
    (vla-settext objtable row 2 (nth 2 val))
    (setq row (1+ row))
  )
  (princ)
)

(defun ahmktable ( / colwidth numcolumns numrows rowheight sp vgad vgao vgms)
  (setq sp (vlax-3d-point (getpoint "select point for table")))
  (setq curspc (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (setq numrows 21)
  (setq numcolumns 15)
  (setq rowheight 10)
  (setq colwidth 50)
  (setq objtable (vla-addtable curspc sp numrows numcolumns rowheight colwidth))
  (vla-put-TitleSuppressed Objtable :vlax-true)
  (vla-put-HeaderSuppressed Objtable :vlax-true)
  (vla-UnmergeCells Objtable 0 0 0 8)
  (vla-SetTextHeight Objtable acDataRow  3.0)
  (vla-SetAlignment Objtable acDataRow acMiddleCenter)
  (vla-Setcolumnwidth Objtable  0 18)
  (vla-Setcolumnwidth Objtable  1 65)
  (vla-Setcolumnwidth Objtable  2 18)
  (vla-Setcolumnwidth Objtable  3 18)
  (vla-Setcolumnwidth Objtable  4 18)
  (vla-Setcolumnwidth Objtable  5 18)
  (vla-Setcolumnwidth Objtable  6 65)
  (vla-Setcolumnwidth Objtable  7 18)
  (vla-Setcolumnwidth Objtable  8 18)
  (vla-Setcolumnwidth Objtable  9 18)
  (vla-Setcolumnwidth Objtable  10 18)
  (vla-Setcolumnwidth Objtable  11 64 )
  (vla-Setcolumnwidth Objtable  12 18)
  (vla-Setcolumnwidth Objtable  13 18)
  (vla-Setcolumnwidth Objtable  14 18)
  (vla-settext objtable 0 0 "SHEET\nNo.")
  (vla-settext objtable 0 1 "TITLE")
  (vla-settext objtable 0 2 "REV.\nDATE")
  (vla-settext objtable 0 3 "REV.\nDATE")
  (vla-settext objtable 0 4 "REV.\nDATE")
  (vla-settext objtable 0 5 "SHEET\nNo.")
  (vla-settext objtable 0 6 "TITLE")
  (vla-settext objtable 0 7 "REV.\nDATE")
  (vla-settext objtable 0 8 "RE.\nDATE")
  (vla-settext objtable 0 9 "REV.\nDATE")
  (vla-settext objtable 0 10 "SHEET\nNo.")
  (vla-settext objtable 0 11 "TITLE")
  (vla-settext objtable 0 12 "REV.\nDATE")
  (vla-settext objtable 0 13 "REV.\nDATE")
  (vla-settext objtable 0 14 "REV.\nDATE")
  (princ)
)

;; Directory Files  -  Lee Mac
;; Retrieves all files of a specified filetype residing in a directory (and subdirectories)
;; dir - [str] Root directory for which to return filenames
;; typ - [str] Optional filetype filter (DOS pattern)
;; sub - [bol] If T, subdirectories of the root directory are included
;; Returns: [lst] List of files matching the filetype criteria, else nil if none are found

(defun LM:directoryfiles ( dir typ sub )
    (setq dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)))
    (append (mapcar '(lambda ( x ) (strcat dir "\\" x)) (vl-directory-files dir typ 1))
        (if sub
            (apply 'append
                (mapcar
                   '(lambda ( x )
                        (if (not (wcmatch x "`.,`.`."))
                            (LM:directoryfiles (strcat dir "\\" x) typ sub)
                        )
                    )
                    (vl-directory-files dir nil -1)
                )
            )
        )
    )
)

(defun makeindex ( / )
  (vlax-for dbobj (vla-get-ModelSpace dbx)
  (if (and (= (vla-get-ObjectName dbobj) "AcDbBlockReference" )(= (vlax-get dbobj 'name) "A3LM"))
  (progn
    (setq atts (vlax-invoke dbobj 'Getattributes))
    (setq desc (vlax-get (nth 5 atts) 'textstring))
    (setq shtno (vlax-get (nth 7 atts) 'textstring))
    (setq rev (strcat (vlax-get (nth 10 atts) 'textstring) "\n-"))
    (setq lst (cons (list desc shtno rev) lst))
  )
  )
  )
  (princ)
)


;;;;;;;;;;;;; starts here ;;;;;;;;;;;

(defun c:index1 ( / dbx direc filelst file)

(setq dbx
  (vl-catch-all-apply 'vla-getinterfaceobject
      (list (setq app (vlax-get-acad-object))
          (if (< (setq vrs (atoi (getvar 'acadver))) 16)
              "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
          )
      )
  )
)

(setq direc (VL-FILENAME-DIRECTORY (getfiled "Select dwg File for top directory " "" "dwg" 16)))
(setq filelst (LM:directoryfiles direc "*.dwg" T))

(setq lst '())

(foreach file filelst
  (vla-open dbx file)
  (makeindex)
)
(setq lst (vl-sort lst '(lambda (x y) (< (cadr x)(cadr y)))))

(ahmktable)
(if (= row nil) (setq row 1))
(doindex lst row)

(vlax-release-object dbx)
(princ)

)

(c:index1)

SeaHaven_0-1789618139393.png

Still makes sense to me to have date in the dwg. Yes needs way more work but one step at a time.

 

What happens when you get to Rev 4 ? Needs a shuffle yes can be done.

0 Likes
Message 11 of 18

lauri_barnhart
Autodesk
Autodesk

Welcome to the community, @subashtamang05041988.

 

Hope you are well. Following up to see if the information provided by Sea-Haven clarified your question. If it did, please consider clicking on the 'Accept Solution' button.

 

Thanks,


Lauri | Community Manager
0 Likes
Message 12 of 18

walikhanofficial055
Observer
Observer

The step-by-step approach makes sense, especially testing with a smaller number of DWGs before scaling it up to hundreds.

0 Likes
Message 13 of 18

subashtamang05041988
Participant
Participant

Hello Sea-Haven,

Sorry for the delayed response. I tried to use it, but unfortunately, I was unable to get it working. Could you please guide me through the procedure step by step? This would help me understand the process more clearly and ensure that I am following the correct procedure. Thank you for your support.

 

Ref. screen shot below.

subashtamang05041988_0-1789995960540.png

subashtamang05041988_1-1789996048512.png

 

0 Likes
Message 14 of 18

Sea-Haven
Mentor
Mentor

 I think the issue is in the choose dwg names, I will see if can do it in a better way. I used Lee-mac's get all dwgs in a directory. That may be where the issue is, you may have to run the code with no dwgs open from within the chosen directory. When asked to pick a dwg you only need to pick one this returns the directory name where the dwg's are, then the Lee-mac code selects all dwgs in that directory.

SeaHaven_0-1790039838948.png

It currently does not have any error handling for if an incorrect dwg is in that directory ie Title block not found.

I used this for testing with a hard coded list. 

(setq direc (VL-FILENAME-DIRECTORY (getfiled "Select dwg File for top directory " "" "dwg" 16)))
; (setq filelst (LM:directoryfiles direc "*.dwg" T))
(setq filelst (list "D:\\temp\\loop-1.dwg" "d:\\temp\\loop-2.dwg"))

If the index dwg is the current dwg can remove that from the OBDX list and update separately. Will add that after getting to work in a simple way. 

 

Try with a hard coded list. The variable "filelst" don't forget to use double slashes. Then can try to improve on user interface. Don't forget I have only allowed for 1st 20 dwgs at this stage for testing, just try a few gradually increasing the number of dwg's. I am not sure about speed.

 

Given the number of dwgs involved you may be better looking for a "Project drawing management" program that updates indexes and say links to Excel etc. We had a system but it was only at top level using an Access database. Could look up dwg's since 1999.

0 Likes
Message 15 of 18

subashtamang05041988
Participant
Participant

Dear Sea-Haven,

Thank you very much for your effort and support. Unfortunately, I’m sorry to say that I’m unable to accept the proposed solution.

0 Likes
Message 16 of 18

Sea-Haven
Mentor
Mentor

Thinking more about this task it may be that using Datalink to link a Excel file with multiple Index Dwg's may be the way to go. You can write to an Excel file from CAD. Then  update an index in certain dwg's. The big issue I see is when you do not know how many index dwg's you need so the complete set has the sheet number and total changing.

0 Likes
Message 17 of 18

subashtamang05041988
Participant
Participant

Dear Sea-Haven,

I am also looking into how we can address this issue. One possible approach could be to use attribute blocks linked to an excel file, allowing the required information to be populated and updated automatically across multiple Index DWGs.

Regarding the total number of sheets, I don't think this will be a major issue, as we can verify the required number of sheets from the cable Schedule or I/O Schedule. This approach could also help us mange multiple Index DWGs while maintaining consistent sheet numbering and total sheet information.

I hope someone with expertise in this area can help us find a practical and efficient solution. I believe many engineering design teams are facing a similar requirement. If we can develop a reliable solution, it would significantly simplify the generation, updating, and management of Index drawings, particularly when dealing with a large number of sheets.

0 Likes
Message 18 of 18

Sea-Haven
Mentor
Mentor

Using Excel would certainly help. As you could set up a sheet with say 1-> 1000 as sheet numbers, you can easily insert a CAD title details and then renumber the dwg's in Excel. A script could be made then to update all dwg's with the new sheet number and sheet total. The list of dwg names coming from Excel. The only issue being need to update all 840 dwg's, you may need a CAD manager to ensure control of the dwg's particularly when adding or inserting a new DWG.

 

Aecoreconsole is very fast and works on the dwg without graphically opening it, not sure how fast it will do 840. May get some conflicts with dwg names not sure about that.

 

If you can provide a Excel sample of what may be useful, then may be able to do some updating of the DWG to and from the Excel.

 

Just a Ps using Bricscad at moment so no Aecoreconsole access. Testing using OBDX. There is a method will look into that.

 

Others may have some ideas.

0 Likes