AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API: How to read (and change) drawing properties defined at the project

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
sbarlage
269 Views, 3 Replies

API: How to read (and change) drawing properties defined at the project

sbarlage
Enthusiast
Enthusiast

Hi,

 

I try to read out all defined drawing properties of the active drawing as shown in screenshot.

sbarlage_0-1721725692583.png

All this should be done inside of my addin. The properties should be read at DocumentSave event (Event is already implemented and working, I get "Autodesk.AutoCAD.ApplicationServices.Document" as parameter from Autocad at the OnSave event function.

Can someone points me to the how to read the informations shown at General and ErpData?

Regards

Stefan

0 Likes

API: How to read (and change) drawing properties defined at the project

Hi,

 

I try to read out all defined drawing properties of the active drawing as shown in screenshot.

sbarlage_0-1721725692583.png

All this should be done inside of my addin. The properties should be read at DocumentSave event (Event is already implemented and working, I get "Autodesk.AutoCAD.ApplicationServices.Document" as parameter from Autocad at the OnSave event function.

Can someone points me to the how to read the informations shown at General and ErpData?

Regards

Stefan

3 REPLIES 3
Message 2 of 4
sbarlage
in reply to: sbarlage

sbarlage
Enthusiast
Enthusiast

I forget to say, I'm using C# with Plant 3D 2024 and 2025.

0 Likes

I forget to say, I'm using C# with Plant 3D 2024 and 2025.

Message 3 of 4
sbarlage
in reply to: sbarlage

sbarlage
Enthusiast
Enthusiast
Accepted solution

I could solve it myself:

internal enum DrawingType
{
	Unknown=0,
	PID=1,
	P3D=2,
	Ortho=3,
	Iso=4
}

Autodesk.AutoCAD.ApplicationServices.Document activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Autodesk.AutoCAD.Interop.AcadDocument activeAcadDocument = Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(ActiveDocument) as Autodesk.AutoCAD.Interop.AcadDocument;
Autodesk.AutoCAD.DatabaseServices.Database activeDatabase = ActiveDocument.Database;
Autodesk.ProcessPower.ProjectManager.PlantProject plantProject = Autodesk.ProcessPower.PlantInstance.PlantApplication.CurrentProject;
Autodesk.ProcessPower.ProjectManager.ProjectUnitsType projectUnits = pipingProjectPart.ProjectUnitsType;
Autodesk.ProcessPower.ProjectManager.Project pnidProjectPart = plantProject.ProjectParts["PnID"];
Autodesk.ProcessPower.ProjectManager.Project pipingProjectPart = plantProject.ProjectParts["Piping"];
Autodesk.ProcessPower.ProjectManager.Project orthoProjectPart = plantProject.ProjectParts["Ortho"];
Autodesk.ProcessPower.ProjectManager.Project isometricProjectPart = plantProject.ProjectParts["Iso"];
Autodesk.ProcessPower.DataLinks.DataLinksManager pnidDataLinksManager = pnidProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager pipingDataLinksManager = pipingProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager orthoDataLinksManager = orthoProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager isometricDataLinksManager = isometricProjectPart.DataLinksManager;

if (pnidDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.PID;
}
else if (pipingDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.P3D;
}
else if (orthoDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.Ortho;
}
else if (isometricDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.Iso;
}
else
{
}

switch (drawingType)
{
	case DrawingType.PID:
		{
			// Get the piping drawing category names
			List<string> catNames = pnidProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = pnidProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.P3D:
		{
			// Get the piping drawing category names
			List<string> catNames = pipingProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = pipingProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.Ortho:
		{
			// Get the piping drawing category names
			List<string> catNames = orthoProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = orthoProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.Iso:
		{
			// Get the piping drawing category names
			List<string> catNames = isometricProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = isometricProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	default:
		break;
}

I could solve it myself:

internal enum DrawingType
{
	Unknown=0,
	PID=1,
	P3D=2,
	Ortho=3,
	Iso=4
}

Autodesk.AutoCAD.ApplicationServices.Document activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Autodesk.AutoCAD.Interop.AcadDocument activeAcadDocument = Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(ActiveDocument) as Autodesk.AutoCAD.Interop.AcadDocument;
Autodesk.AutoCAD.DatabaseServices.Database activeDatabase = ActiveDocument.Database;
Autodesk.ProcessPower.ProjectManager.PlantProject plantProject = Autodesk.ProcessPower.PlantInstance.PlantApplication.CurrentProject;
Autodesk.ProcessPower.ProjectManager.ProjectUnitsType projectUnits = pipingProjectPart.ProjectUnitsType;
Autodesk.ProcessPower.ProjectManager.Project pnidProjectPart = plantProject.ProjectParts["PnID"];
Autodesk.ProcessPower.ProjectManager.Project pipingProjectPart = plantProject.ProjectParts["Piping"];
Autodesk.ProcessPower.ProjectManager.Project orthoProjectPart = plantProject.ProjectParts["Ortho"];
Autodesk.ProcessPower.ProjectManager.Project isometricProjectPart = plantProject.ProjectParts["Iso"];
Autodesk.ProcessPower.DataLinks.DataLinksManager pnidDataLinksManager = pnidProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager pipingDataLinksManager = pipingProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager orthoDataLinksManager = orthoProjectPart.DataLinksManager;
Autodesk.ProcessPower.DataLinks.DataLinksManager isometricDataLinksManager = isometricProjectPart.DataLinksManager;

if (pnidDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.PID;
}
else if (pipingDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.P3D;
}
else if (orthoDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.Ortho;
}
else if (isometricDataLinksManager.GetDrawingId(db) != -1)
{
	drawingType = DrawingType.Iso;
}
else
{
}

switch (drawingType)
{
	case DrawingType.PID:
		{
			// Get the piping drawing category names
			List<string> catNames = pnidProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = pnidProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.P3D:
		{
			// Get the piping drawing category names
			List<string> catNames = pipingProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = pipingProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.Ortho:
		{
			// Get the piping drawing category names
			List<string> catNames = orthoProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = orthoProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	case DrawingType.Iso:
		{
			// Get the piping drawing category names
			List<string> catNames = isometricProjectPart.GetCategoryNames(CategoryType.eDrawing);

			foreach (string catName in catNames)
			{
				List<KeyValuePair<string, string>> props = isometricProjectPart.GetDrawingProperties(fileName, catName);
				foreach (KeyValuePair<string, string> prop in props)
				{
					System.Diagnostics.Debug.Print($"{catName}, {prop.Key}, {prop.Value}");
				}
			}
		}
		break;
	default:
		break;
}
Message 4 of 4
Michiel.Valcke
in reply to: sbarlage

Michiel.Valcke
Advisor
Advisor

You're welcome to mark your own post as a solution ^^

0 Likes

You're welcome to mark your own post as a solution ^^

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report