Automate naming of Sheets in SSM from Excel Table

Automate naming of Sheets in SSM from Excel Table

DaftDrafter624641
Observer Observer
227 Views
2 Replies
Message 1 of 3

Automate naming of Sheets in SSM from Excel Table

DaftDrafter624641
Observer
Observer

Hi all,

 

I am new to working with CADLisp, however I am looking for ways to save time, and automate some of the longer more tedious tasks.

 

At present we use SSM to manage and arrange all our layouts, and all the Sheet Numbers, and Sheet Titles are pulled from an Excel Table and copy/pasted into the dialogue box.

 

I was wondering if there was any insight to having that be automated by Lisp.

 

Thanks in Advance.

0 Likes
228 Views
2 Replies
Replies (2)
Message 2 of 3

Sea-Haven
Mentor
Mentor

Where I have worked no need for SSM but I have seen somewhere how to write a SSM data file I would start by googling that. Hopefully some one will provide a link.

0 Likes
Message 3 of 3

daniel_cadext
Advisor
Advisor

You can do this in .NET or Python

 

I have wrapped Sheet sets in Python https://github.com/CEXT-Dan/PyRx  Or https://pypi.org/project/cad-pyrx/

If you are able to run this project in your version of AutoCAD, then you can use openpyxl to read and write excel

 

There may be dragons!  I only wrapped Sheet sets and have written a few tests based off

https://adndevblog.typepad.com/autocad/2013/09/using-sheetset-manager-api-in-vbnet.html

 

I don’t know how to use the Sheet set API beyond the blog sample, so using this will require you to grind through crumbs of samples you find on the internet.

 

 Here is a proof of concept

 

 

import traceback
from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed, Ax, Sm
import openpyxl
from pathlib import Path


@Ap.Command()
def doit():
    try:
        # open xl
        xlwb = openpyxl.load_workbook("E:\\SheetSet.xlsx")
        xlsheet = xlwb.active
        name = xlsheet.cell(row=1, column=1).value
        descrption = xlsheet.cell(row=1, column=2).value
        title = xlsheet.cell(row=1, column=3).value
        number = xlsheet.cell(row=1, column=4).value

        # sheetset
        path = "E:\\temp"
        fullpath = "E:\\temp\\CP318-5.dst"
        dwtfullpath = "E:\\temp\\CP318-5.dwt"
        mgr = Sm.SheetSetMgr()
        ssdb = mgr.createDatabase(fullpath)
        ssdb.lockDb()
        setSheetSetDefaults(ssdb, "CP318-5", "Demo", path, dwtfullpath, "Sheet", False)
        addSheet(ssdb, name, descrption, title, number)

    except Exception as err:
        traceback.print_exception(err)
    finally:
        ssdb.unlockDb(True)


def setSheetSetDefaults(
    sheetSetDatabase: Sm.SmDatabase,
    name: str,
    description: str,
    newSheetLocation: str,
    newSheetDWTLocation: str,
    newSheetDWTLayout: str,
    promptForDWT: bool,
):
    sheetSet = sheetSetDatabase.getSheetSet()
    sheetSet.setName(name)
    sheetSet.setDesc(description)

    if len(newSheetLocation) == 0:
        newSheetLocation = str(Path(sheetSetDatabase.getFileName()).parent)

    fileReference = sheetSet.getNewSheetLocation()
    fileReference.setFileName(newSheetLocation)
    sheetSet.setNewSheetLocation(fileReference)

    if len(newSheetDWTLocation) != 0:
        layoutReference = sheetSet.getDefDwtLayout()
        layoutReference.setFileName(newSheetDWTLocation)
        layoutReference.setName(newSheetDWTLayout)
        sheetSet.setDefDwtLayout(layoutReference)
    sheetSet.setPromptForDwt(promptForDWT)


def addSheet(component: Sm.Component, name: str, description: str, title: str, number: str):
    sheet = None
    if component.getTypeName() == Sm.Subset.className():
        subset = Sm.Subset.cast(component)
        sheet = subset.addNewSheet(name, description)
    else:
        smdb = component.getDatabase()
        ss = smdb.getSheetSet()
        sheet = ss.addNewSheet(name, description)
    ss.insertComponentFirst(sheet)
    sheet.setNumber(number)
    sheet.setTitle(title)

 

 

sheetset.png

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