top of page

Bulk Creating Sheets in AutoCAD-Part 1

Updated: Jan 3, 2022

AutoCAD is one of the most used drafting and design tools out there. However, most users that utilize the software, create sheets the same way as they did more than 20 years ago. In the mid-2000s, Autodesk introduced Sheet Set Manager within AutoCAD. This tool allows for easier management of files throughout a project life cycle. Sheet set manager incorporates a database of sorts that allows users to set values across multiple documents without the need to open documents by the use of Fields.

One of the beneficial features of Sheet Set Manager is that it allows you to set a drawing template(.dwt) that includes the titleblock and text/attributes linked to fields already set up to be linked back to the Sheet Set. This template can be set for the overall Sheet Set or can be limited to subset(s) within the Sheet Set. This flexibility can be used differently on different projects. For example in my company, we use a standard 30"x42"(ARCH E1) template for the overall project but then have an 11"x17" sketch template for the sketch subset only. In this case, whichever subset we add a sheet to will define how the new sheet/file is created.


Sheet set Manager lends to a lot of benefits but the creation of sheets within is still a task that you have to do one sheet at a time by right-clicking on the subset and 'New Sheet' to add sheets to the Sheet Set Manager. So as a way to work around how the features are available, I was able to create a lisp function through .NET that could allow you to bulk create sheets.


Here is the .NET that would create the lisp function

using ACSMCOMPONENTS24Lib;//This is driven by your version of AutoCAD
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
using Document = Autodesk.AutoCAD.ApplicationServices.Document;
using Editor = Autodesk.AutoCAD.EditorInput.Editor;

namespace MYCAD
{
    public class mySheetSet
    {
        [LispFunction("SSMCreateSheet")]
        public static void SSMCreateSheet(ResultBuffer rbArgs)
        {
            string Discipline="";
            string SheetNumber="";
            string SheetName = "";
            string ProjectNumber = "";
            if (rbArgs != null)
            {
                int nCnt = 0;
                foreach (var typedValue in rbArgs)
                {
                    if (typedValue.TypeCode == (int)LispDataType.Text)
                    {
                        switch (nCnt)
                        {
                            case 0:
                                Discipline = typedValue.Value.ToString();
                                break;
                            case 1:
                                SheetNumber = typedValue.Value.ToString();
                                break;
                            case 2:
                                SheetName = typedValue.Value.ToString();
                                break;
                        }

                        nCnt += 1;
                    }
                }
                Document ACadDocument = 
                Application.DocumentManager.MdiActiveDocument;
                Editor CommandLine = ACadDocument.Editor;
                bool sheetFound = false;
                AcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();
                IAcSmEnumDatabase databaseEnum = 
                sheetSetManager.GetDatabaseEnumerator();
                AcSmDatabase database = databaseEnum.Next();

                AcSmSheetSet sheetSet = database.GetSheetSet();
                if (sheetSet is IAcSmSheetSet2 acSmSheetSet2)
                {
                    ProjectNumber = acSmSheetSet2.GetProjectNumber();
                }
                IAcSmEnumComponent sheetEnumerator = 
                sheetSet.GetSheetEnumerator();

                var component = sheetEnumerator.Next();
                while (component != null && sheetFound != true)
                {
                    if (component.GetTypeName() == "AcSmSubset")
                    {
                        var subset = component as AcSmSubset;
                        if (subset.GetName() == Discipline.ToUpper())
                        {
                            if (LockDatabase(ref database, true))
                            {
                                try
                                {
                                    IAcSmSheet newSheet = 
                                    subset.AddNewSheet(ProjectNumber + 
                                    SheetNumber.ToUpper(), "");
                              newSheet.SetNumber(SheetNumber.ToUpper());
                                   newSheet.SetTitle(SheetName.ToUpper());
                                    subset.InsertComponent(newSheet,null);
                                }
                                catch (System.Exception ex)
                                {
                                  CommandLine.WriteMessage(ex.ToString());
                                }
                            }
                            LockDatabase(ref database, false);
                        }
                    }
                    component = sheetEnumerator.Next();
                }
            }
        }
        public static bool LockDatabase(ref AcSmDatabase database, 
        bool lockFlag)
        {
            bool dbLock;

            if (lockFlag & database.GetLockStatus() == 
            AcSmLockStatus.AcSmLockStatus_UnLocked)
            {
                database.LockDb(database);
                dbLock = true;
            }

            else if (!lockFlag & database.GetLockStatus() == 
            AcSmLockStatus.AcSmLockStatus_Locked_Local)
            {
                database.UnlockDb(database);
                dbLock = true;
            }
            else
            {
                dbLock = false;
            }
            return dbLock;
        }
    }
}

The above code once compiled and using NETLOAD to import the dll into AutoCAD will allow the following lisp function that could be typed directly into the command line.

(ssmcreateSheet "<Subset Name>" "<Sheet Number>" "<Sheet Name>")

This will create a new sheet in the specified subset with the sheet Number and sheet Name values added appropriately. The flaw to using this method is that it will automatically add this sheet to the first sheet set that you have open. It does not matter whether that is the one that is active within the sheet set. The best workflow would be to close all other sheet sets so that you are sure that you are creating the file(s) where you intended.


Now the title for this article is about the bulk creation of sheets in AutoCAD and I have only given examples of typing directly into the command line. There are 2 ways that we can incorporate it into bulk methods.


It opens the door to allowing you to create sheets in bulk from a standard AutoCAD Script.

(ssmcreateSheet "MECHANICAL" "M001" "COVERSHEET")
(ssmcreateSheet "MECHANICAL" "M101" "FIRST FLOOR DUCTWORK PLAN")
(ssmcreateSheet "MECHANICAL" "M201" "FIRST FLOOR PIPING PLAN")
(ssmcreateSheet "MECHANICAL" "M701" "SCHEDULES")
(ssmcreateSheet "MECHANICAL" "M801" "DETAILS")

This can be placed in a text file with a .scr file that you can drag and drop into an open AutoCAD file.


And depending on how standardized your sheet numbering system is, you could repetitively use this on every project. Then maybe a lisp would be more beneficial for this task.


(defun c:CreateSheet()
 (ssmcreateSheet "MECHANICAL" "M001" "COVERSHEET")
 (ssmcreateSheet "MECHANICAL" "M101" "FIRST FLOOR DUCTWORK PLAN")
 (ssmcreateSheet "MECHANICAL" "M201" "FIRST FLOOR PIPING PLAN")
 (ssmcreateSheet "MECHANICAL" "M701" "SCHEDULES")
 (ssmcreateSheet "MECHANICAL" "M801" "DETAILS")
 (princ)
)

Either bulk method will automatically place the newly created sheet at the top of the list

within the list in the subset. Either of the routines that I have created will show the reverse order of how you wrote it so either make the list in the reverse order or shift the list after creation. No matter the order it will still create the files as you identified to be created.





239 views0 comments

Recent Posts

See All
bottom of page