Project data can be retrieved from the ProjectData class.
This walkthrough assumes you have an existing Advance Steel add-in project. See the Hello World Walkthrough for information on how to set up an Advance Steel add-in project.
The properties from the Project Info 1, Project Info 2 and User Attributes tabs in the Project Data dialog are accessible from the ProjectData class. The ProjectData is retrieved from the static method ProjectDataManager.GetProjectData(). Properties are returned as string values from the ProjectData.GetData() method which takes a ProjectData.eID enum value as a parameter. The following command method will display some of the project data from the current drawing in a message box.
|
Code Region: Reading ProjectData |
[CommandMethodAttribute("TEST_GROUP", "DisplayProjectData", "DisplayProjectData", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void DisplayProjectData()
{
StringBuilder projectInfo = new StringBuilder();
ProjectData projData = ProjectDataManager.GetProjectData();
projectInfo.AppendLine("Project: " + projData.GetData(ProjectData.eID.kProject));
projectInfo.AppendLine("Project No: " + projData.GetData(ProjectData.eID.kProject_Nr));
projectInfo.AppendLine("Client: " + projData.GetData(ProjectData.eID.kClient));
projectInfo.AppendLine("Contractor: " + projData.GetData(ProjectData.eID.kContractor));
projectInfo.AppendLine("Detailer: " + projData.GetData(ProjectData.eID.kDrawer));
projectInfo.AppendLine("Checked By: " + projData.GetData(ProjectData.eID.kTech_designer));
MessageBox.Show(projectInfo.ToString());
}
|
The project data is also writeable. Use the ProjectData.SetData() method to write new values to the project data properties. The following example demonstrates how to set values for some of the user attributes available for custom project data values.
|
Code Region: Update user attributes |
[CommandMethodAttribute("TEST_GROUP", "UpdateUserAttributes", "UpdateUserAttributes", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void UpdateUserAttributes()
{
//Lock dock and start transaction
DocumentManager.lockCurrentDocument();
TransactionManager.startTransaction();
ProjectData projData = ProjectDataManager.GetProjectData();
// specify project source
projData.SetData(ProjectData.eID.kUserAttr1, "Ifc Import");
// specify building type
projData.SetData(ProjectData.eID.kUserAttr2, "School");
// specify subcontractor
projData.SetData(ProjectData.eID.kUserAttr3, "ACME Designs");
//Unlock doc and end transaction
TransactionManager.endTransaction();
DocumentManager.unlockCurrentDocument();
}
|