Programatically SAVE File with concatenated Property Set data

Programatically SAVE File with concatenated Property Set data

neilyj666
Mentor Mentor
1,642 Views
6 Replies
Message 1 of 7

Programatically SAVE File with concatenated Property Set data

neilyj666
Mentor
Mentor

I have created Property Set data to add my files as metadata as below

 

2018-10-30 07_41_59-Autodesk Civil 3D 2019 - [Drawing1.dwg].jpg

 

As I progress my design I type SAVE on the command line and append the name with _SuitabilityCode_RevisionCode as shown below. The "live" drawing will always end with a 4 digit number so as per screenshot my current file will next be SAVEd as P01.04 and I manually increment the Revision on my 0001 drawing to P01.05.

 

2018-10-30 07_59_19-CHD_Crane Hardstands.jpg

I would like to automate this such that the Suitability code and Revision get added as part of the SAVE but I have no idea if this is possible or indeed how to achieve it. I have done a similar thing for Excel files via VBA which works fairly well but AutoCAD programming is a mysterious art...!!!!

 

Can anyone advise and hopefully post up some code to do this?

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2026 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760
0 Likes
Accepted solutions (1)
1,643 Views
6 Replies
Replies (6)
Message 2 of 7

deepak.a.s.nadig
Alumni
Alumni

One idea is to create a simple .NET project with a command having following workflow:


1) Read the required custom property value of current active drawing( to which custom properites are already set)
2) 'SAVEAS' the current drawing, appending the custom property values to the current drawing name.

 

Here is a sample code that can be helpful to implement the workflow:

[CommandMethod("saveDwgWithNewName")]
public static void saveDwgWithNewName()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    Document doc = ed.Document;
    Database db = doc.Database;
    // get the name of the current drawing without extension
    string curDwgName = Path.GetFileNameWithoutExtension(doc.Name);
    try
    {
        DatabaseSummaryInfoBuilder sumInfo = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
        IDictionary custProps = sumInfo.CustomPropertyTable;
        // get the custom property value  
        string custProp = (string)custProps["SuitabilityCode"];
        if (custProp != null)
        {
            //append custom property name to current drawing name  
            string newDwgName = curDwgName + "_" + custProp;
            // save current drawing with new name 
            doc.Database.SaveAs(newDwgName, true, DwgVersion.Current, doc.Database.SecurityParameters);
        }
    }
    catch (System.Exception ex)
    {
        ed.WriteMessage(ex.ToString());
    }
}


Setting up a .NET Project for Autodesk Civil 3D can be helpful reference to use the above code :
https://help.autodesk.com/view/CIV3D/2019/ENU/?guid=GUID-DE3A46DA-508E-43A0-8538-C77D978D06B2

Message 3 of 7

norman.yuan
Mentor
Mentor

Firstly, since you are post in Civil3D forum, "Property Set" has its own meanings in Civil3D/AutoCAD Arch, while your question is about drawing custom properties, which is applicable to all AutoCAD based products.

 

Your issue is to synchronize the custom properties and file name. The way to do it depends on the work flow: change the custom property first, and then make sure the file name is changed accordingly with "SaveAs"; or user simply save the file to whatever name needed, and the custom properties in drawing is automatically updated accordingly.

 

Both AutoCAD VBA and AutoCAD .NET API can be used to do it fairly easy.

 

The code provided by @deepak.a.s.nadig uses the first approach, where user has to change the custom property, and use the custom command to save the file (user has to remember no use built-in SaveAs command.

 

It might be more natural just allow user to "SaveAs" the drawing as needed/required and the custom property in drawing gets updated automatically when SaveAs occurs. You only need to write code to catch the event when saving is to begin. At that moment, the code would compare the file name to be saved with the custom property and update the custom property when necessary. The actual saving would happen after the code done its work.

 

Well, you need to be able to write code in VBA, or preferably, in .NET API.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 7

neilyj666
Mentor
Mentor

@norman.yuan - you are correct; it is the custom property that I have created rather than Property Set data. I do a Save (rather than a Save As) so that I can keep working on the original drawing whilst the ones with an _S0_PXX.XX suffix are archive copies.

@deepak.a.s.nadig as I have no skill with either VBA or .NET it looks like I'll just continue to do this manually.

 

Regards

 

Neil

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2026 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760
0 Likes
Message 5 of 7

Jowennl
Advisor
Advisor
Message 7 of 7

neilyj666
Mentor
Mentor

Thanks @Jowennl this works exactly as I hoped it would and automates a tedious process and it should hopefully eliminate manual errors...!!!!

 

I went a step further and added a right click command for BUSAVE....:)

 

2019-03-04 19_15_04-Autodesk Civil 3D 2019 - RtClick.jpg

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2026 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760