I'm interested in pulling some information from a plant 3d drawing with python. So far I've been able to extract a few properties.
I'm really interested in the position x, y, z coordinates and center of gravity but cannot seem to get that information. I've tried a bunch of property names but they aren't working.
Is there a way to find out the property names available in Plant3D itself? I've checked the usual property menu when selecting a pipe but that didn't work.
Is this a restriction of Python not being .NET - if so is there a workaround for this with still using Python if possible?
It seems like it's so close because its picking up some properties but not all.
from pyautocad import Autocad
import comtypes.client
def get_all_properties(obj):
return [prop for prop in dir(obj) if not prop.startswith('__')]
def safe_get_property(obj, prop_name):
try:
value = getattr(obj, prop_name)
if isinstance(value, (tuple, list)) and len(value) == 3:
return f"({value[0]}, {value[1]}, {value[2]})"
return str(value)
except Exception as e:
return None
def explore_pipe_properties(pipe):
properties = {}
prop_list = [
'ObjectName', 'Layer', 'Length', 'NominalDiameter', 'Material', 'LineNumber',
'Service', 'InsulationType', 'InsulationThickness',
'Position', 'EndPosition', 'CenterOfGravity',
'Specification', 'Rating', 'OutsideDiameter', 'InsideDiameter', 'FlowDirection',
'Temperature', 'Pressure', 'PaintColor', 'Slope', 'NB', 'PnPClassName', 'Position_X', 'PipeSpec'
]
for prop in prop_list:
value = safe_get_property(pipe, prop)
if value is not None:
properties[prop] = value
return properties
# Connect to the running instance of AutoCAD
acad = Autocad()
if acad.doc:
print(f"Connected to: {acad.doc.Name}")
try:
model_space = acad.model
pipes = []
for obj in model_space:
obj_name = safe_get_property(obj, 'ObjectName')
if obj_name == 'AcPpDb3dPipe':
pipes.append(explore_pipe_properties(obj))
if len(pipes) >= 100:
break
print(f"\nTotal AcPpDb3dPipe objects found: {len(pipes)}")
if pipes:
print("\nProperties found on AcPpDb3dPipe objects:")
for prop, value in pipes[0].items():
print(f" {prop}: {value}")
print("\nSample data for first 5 pipes:")
for i, pipe in enumerate(pipes[:5], 1):
print(f"\nPipe {i}:")
for prop, value in pipe.items():
print(f" {prop}: {value}")
else:
print("No AcPpDb3dPipe objects found in the drawing.")
except Exception as e:
print(f"An error occurred: {str(e)}")
print("If the error persists, you may need to check your AutoCAD Plant 3D settings.")
else:
print("Failed to connect to AutoCAD")
Dear @Paul.Carson4JXY2 ,
Python is only very rudimentarily supported in AutoCAD Plant 3D .
Therefore there is the SDK for AutoCAD Plant 3D
https://aps.autodesk.com/developer/overview/autocad-plant-3d-and-pid
Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn
Ok thanks for the resource. Is that all in C# or is there VB or other languages to implement as well?
The end goal would be to have a button within Plant 3D preferably that would run a script and maybe connect to a sharepoint file to compare data.
@Paul.Carson4JXY2 wrote:
Ok thanks for the resource. Is that all in C# or is there VB or other languages to implement as well?
The .NET API can use C# or VB.net languages. You'll find much more help and sample code with C#.
@Paul.Carson4JXY2 wrote:The end goal would be to have a button within Plant 3D preferably that would run a script and maybe connect to a sharepoint file to compare data.
.NET would likely be the best tool for this. A little outside of the box, but if you really wanted to use Python, you could probably get the info you want from the SQL database.
Can't find what you're looking for? Ask the community or share your knowledge.