Layers from csv

Hello,

is there a way to create serveral layers at once by importing a csv or something like that?

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • edited March 30

    AFAIK, if you have a template file with these Layers, you could open both files and select and drag multiple Layers over in Drawing Explorer. I do not know any other way to import Layers. Which doesn't necessarily mean that there is no way.

    If not, a workaround could be any other importable App file format, which may offer CSV imports or similar bulk editing. Like IFC (?)

    (As I experienced, it would not work from Vectorworks by exporting a DWG, as VW will only write Layers in use to DWG. You would need to add objects to any empty Class in VW before or similar)

  • Thank for your answer.

    I have no template file with the desired layers. I rather want to use excel to generate a list of layernames with counting numbers and after that, get these names into bricscad.

  • If you write a CSV file from Excel its a simple task to make the layer reading the csv file.

    Eg

    layername,color,linetype

    layername,color,linetype

    layername,color,linetype

    Do you know how to read a csv via lisp ?

  • you could use layerstate's import/export. the resulting .las file is just a text file. you can get insperation from that if you want to roll your own

  • edited March 31

    if you use lisp see attached lisp and xlsx file sample.

    (save the .xlsx file as csv, for some reason the forum don't allow share csv files)

    .

    aridzv.

  • Thanks a lot for all your answers.

    I have no experience with lisp, but I'm pretty interested in trying it.

    Unfortunately for the moment I have to concentrate on other tasks.

    I will give feedback, when I tryed your suggestions.

    off topic:

    the picture below shows a vaulted ceiling I had to deal with two years ago.

  • Hi aridzv,

    i tried your lisp and it will help me. Thank you.

  • just a comment you can read a Excel file direct so make your layers.


    Sounds like this scenario, for us we had a dwg template with all the correct layers set up around 200 +, we would open the other dwg, select all objects curl+c then go to dwg and paste to original coordinates, ready to go. Takes maybe 1 minute.

  • @Balu

    I wrote this thanks to PyRx in Python, since I am not clever enough to learn Lisp. Maybe it is of use to you:

    import traceback
    from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed, Cv
        
    import pandas as pd
        
    print("added command - py_layerimport")
    print("added command - py_layerexport")
        
    def updateLayers(db, layers):
        layerMap = {}
        clr = Db.Color()
        lt = Db.LayerTable(db.layerTableId())
        for layer in layers:
            if lt.has(layer[0]):
                ltrid = lt.getAt(layer[0])
                ltr = Db.LayerTableRecord(ltrid,Db.OpenMode.kForWrite)
                clr.setColorIndex(layer[1])
                ltr.setColor(clr)
            else:
                lt.upgradeOpen()
                ltr = Db.LayerTableRecord()
                ltr.setName(layer[0])
                clr.setColorIndex(layer[1])
                ltr.setColor(clr)
                layerMap[layer[0]] = lt.add(ltr)
                lt.downgradeOpen()
        return layerMap
        
    def PyRxCmd_py_layerexport() -> None:
        try:
            path = Ed.Core.getFileD("Enter file name for storing layer table", "mylayerfile.xlsx", "xlsx", 32)
            db = Db.curDb()
            lt = Db.LayerTable(db.layerTableId(), Db.OpenMode.kForRead)
            if not lt.hasFields:
                return
        
            layerTable = {
                "Name": [],
                "Color": [],
                "LineType": [],
                "LineWeight": [],
            }
        
            for record in lt.recordIds():
                ltr = Db.LayerTableRecord(record)
                layerTable["Name"].append(ltr.name())
                layerTable["Color"].append(ltr.color().colorIndex())
                layerTable["LineType"].append(ltr.linetypeObjectId().handle())
                layerTable["LineWeight"].append(ltr.lineWeight())
        
            df = pd.DataFrame(layerTable)
            with pd.ExcelWriter(path, engine="openpyxl") as writer:
                df.to_excel(writer, sheet_name="Layers", index=False)
        
        except Exception as err:
            traceback.print_exception(err)
        
    def PyRxCmd_py_layerimport() -> None:
        try:
            path = Ed.Core.getFileD("Enter file name for storing layer table", "mylayerfile.xlsx", "xlsx", 32)
            db = Db.curDb()
        
            try:
                df = pd.read_excel(path, sheet_name="Layers")
            except:
                print("\nCould not read source file")
                return
            layerMap = updateLayers(db, df.values.tolist())
        
        except Exception as err:
            traceback.print_exception(err)

  • Masterpiece !

  • edited April 4

    Here is an updated lisp and xlsx table (convert to csv after download).

    1. the table has an header row to make it more readble.
    2. The table must have at least one column for layer name
    3. the table has a column for color number - must be a valid number up to 255. if ommited, above 255, not an integer or text it will set to 7 (white)
    4. the table has a column for line type - must be a valid line type name. if ommited or has an invalid name the linetype will be set to "Continuous". it will set to "Continuous".

  • This will read an OPEN Excel sheet expects that it has a header and make a list of all the values in the spreadsheet. For lay.xlsx it wil find A1:C3 as the valid range. with no user input. I have not added the remainder of code to actually make the layers. Just an example of how to read directly from Excel.

  • edited April 5

    I took @ALANH challenge and completed the missing code to create the layers from the Excel file.

    Warning/comment:
    when all is done,the excel file and cad software are closed,
    the "Microsoft Excel" process still exists in the background processes (can be seen in task manager).
    I noticed this when I restarted my computer and got a message that Excel was running in the background.

    other then that the lisp works.
    aridzv.

  • Should have posted this line as well, do after making the list. Releases the link to Excel.

    (if (not (vlax-object-released-p myXL))(progn(vlax-release-object myXL)(setq myXL nil)))

    You can open the correct Excel file, but this has a couple of gotcha's if Excel is open then myxl is set to whatever Excel is open, but you can get what Workbooks are open so check, if the one you want is not open then do just that open it and set it "Active"

    There is lots of stuff in this it keeps growing. Just cut and copy a function. Last entry was reading merged cell values. You can insert an image of a block into a cell.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.