<?xml encoding=”UTF-8″>By Madhukar Moogala
This is a common request from our developers: how to retrieve the properties of an AutoCAD entity that are
displayed in the OPM (Object Property Manager), also known as the Property Palette.
Generally, properties can be retrieved using the get/set methods of a specific entity. However, not all
properties are exposed in .NET, especially dynamic properties that implement OPM’s IDynamicProperty.
Every entity in AutoCAD integrates with the Properties Palette API, which is a combination of ObjectARX and COM
APIs. Custom entities can also define their own properties and participate in the Property Inspector system.
//Autodesk.AutoCAD.Internal.PropertyInspector - Internal namespace - //acmgd.dll
public static IDictionary GetOPMProperties(ObjectId id)
{
Dictionary map = new Dictionary();
IntPtr pUnk = ObjectPropertyManagerPropertyUtility.GetIUnknownFromObjectId(id);
if (pUnk != IntPtr.Zero)
{
try
{
using (CollectionVector properties = ObjectPropertyManagerProperties.GetProperties(id, false, false))
{
int cnt = properties.Count();
if (cnt != 0)
{
using (CategoryCollectable category = properties.Item(0) as CategoryCollectable)
{
CollectionVector props = category.Properties;
int propCount = props.Count();
for (int j = 0; j < propCount; j++)
{
using (PropertyCollectable prop = props.Item(j) as PropertyCollectable)
{
if (prop == null)
continue;
object value = null;
if (prop.GetValue(pUnk, ref value) && value != null)
{
if (!map.ContainsKey(prop.Name))
map[prop.Name] = value;
}
}
}
}
}
}
}
finally
{
Marshal.Release(pUnk);
}
}
return map;
}
A test method, to extract Properties of a Solid entity
[CommandMethod("GETSOLIDPROPS")]
public static void GetSolidProps()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions entopts = new PromptEntityOptions("nPick a solid entity from the drawing");
entopts.SetRejectMessage("nOnly Solid3d entities are allowed.");
entopts.AddAllowedClass(typeof(Solid3d), false); // Ensure only Solid3d is selectable
PromptEntityResult entityResult = ed.GetEntity(entopts);
if (entityResult.Status != PromptStatus.OK) // Handle user cancel or error
{
ed.WriteMessage("nOperation canceled or invalid selection.");
return;
}
ObjectId entid = entityResult.ObjectId;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction t = db.TransactionManager.StartOpenCloseTransaction())
{
try
{
Solid3d solid = t.GetObject(entid, OpenMode.ForRead) as Solid3d;
if (solid == null)
{
ed.WriteMessage("nSelected entity is not a valid 3D solid.");
return;
}
var props = GetOPMProperties(entid);
foreach (var prop in props)
{
ed.WriteMessage($"n{prop.Key} : {prop.Value}");
}
t.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage($"nError: {ex.Message}");
}
}
}


Leave a Reply to caddzooksCancel reply