Since the advent of AutoCAD®, scripting has been an integral part of this very powerful program. It started with simple macro creation and automation of multiple commands using DIESEL and AutoLISP to what is now known as ‘BIM object manipulation’ using APIs, .NET, and other scripting languages.
Our BIM department, specifically BIMTech—our firm’s BIM Department’s Research and Development group—uses the third-party software previously known as CADMech that now became part of the Autodesk Fabrication Suite and is known as CADmep. Writing scripts to automate redundant and tedious tasks for the BIM designer has been a challenge in and of itself for us due to the fact that Fabrication uses its own VB-esque language that needed to be read by AutoCAD right off the bat. With that being said, we had to come up with clever ways to combine multiple scripting languages into a single container that can be then accepted as AutoCAD commands—all without having the user search through jungles of folders and select respective scripts to do its task(s).
Below is a simple utility program we created for one of our flagship BIM projects that combines multiple scripting languages.
The ‘Select Drawing to Scrub’ section cleans up 2D and 3D backgrounds using normal Visual LISP and AutoLISP routines.
The ‘Select drawing for Uploading’ Section uploads AutoCAD drawing file(s) and uses the DOS batch script that was utilized from AutoLISP using: (StartApp "c:/UploadArch.bat")
Then there are ways to get the Fabrication item information by using COD script and retrieving the information required to a TXT file and accessing them through LISP and DCL as shown in the screenshot of the script shown below.
For example, the following line of script selects an item to get the information needed to display in the Value text box and exports that info into a file:
(setq Script (“c:/FabScript.cod") ; Creates the Fabrication COD file
ObjectsSelected (ssget “X” ‘((0 . “MAP_SOLID”))) ; Create selection set
FileToWrite (open scr "w"))
(Write-line "dim var = item.path" fil) ; Writes the information needed to a variable
(Write-line "object outfile = new file(\"C:debug.dat\", foroutput+istext)"FileToWrite)
(Write-line "if outfile.isopen then" FileToWrite)
(Write-line "outfile.writeline(var)" FileToWrite)
(Write-line "outfile.close()" FileToWrite)
(Write-line "endif" FileToWrite)
(Close FileToWrite) ; Closes the file
(ExecuteScript Script ObjectsSelected) ; invokes the executescript command within AutoCAD without forcing the user to navigate through folders where the COD resides
Then the line:
(setq FileToOpen (open "C:/debug.dat" "r")) ; Opens the file created and reads it
(setq ReadTxt (Read-line FileToOpen))
The above code would access data written to external DAT file and then can be reported on a dialog box value either as a string or as an integer.
With the above-mentioned method we were able to achieve automatic calculation such as piping weld lengths using different criteria. The script enables our shop fabrication personnel and spooler to reduce or eliminate tedious manual calculations. The time and cost savings of this are very high, and are more and more quantifiable the more we utilize these.
The following dialog box is the end product of the scripting method described above where the Weld length value was calculated from an array of objects output to a data file as DAT generated through scripting.
We then incorporate that value into our Spool Titleblock using Field information, reducing time spent on manual calculation as well as typing information.
Reysteve Garcia currently works for ACCO Engineered Systems in San Leandro, CA. He is a Developer for ACCO’s BIMTech, BIM R&D group, within their 63-employee BIM & CAD Division. He has been using Autodesk products since 1994 and been exposed to the CAD environment and scripting sector ever since. He enjoys fishing, skiing and hiking.