Thanks @Jeff_M
Here's the code. I made a several attempts to get at the object properties. I could not even manipulate the Location Point3d object. I could turn it into a string and use that so that's what I did. My latest effort to get at the ProfileViewStyle is to assign it to pvStyObj. I commented that code out because it threw an exception I couldn't solve. The @_gile code steps through everything but I just cannot figure out how to code getting at the properties of the ProfileViewStyle as it passes by.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.DatabaseServices.Styles;
using System;
using System.Collections.Generic;
using System.Reflection;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(DumpEntityProperties.Commands))]
namespace DumpEntityProperties
{
public class Commands
{
private bool doDump;
[CommandMethod("PvUCS")]
public void SetUCS()
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
doDump = false;
var entRes = ed.GetEntity("\nSelect Profile View: ");
if (entRes.Status == PromptStatus.OK)
{
PrintDump(entRes.ObjectId, ed);
}
}
[CommandMethod("Dump")]
//Hacked from user _gile https://forums.autodesk.com/t5/net/how-to-find-the-displayed-properties-value-of-selected-object/td-p/7083701
public void Dump()
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
doDump = true;
var entRes = ed.GetEntity("\nSelect object: ");
if (entRes.Status == PromptStatus.OK)
{
PrintDump(entRes.ObjectId, ed);
AcAp.DisplayTextScreen = true;
}
}
private void PrintDump(ObjectId id, Editor ed)
{
var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.GetProperty;
using (var tr = id.Database.TransactionManager.StartTransaction())
{
var dbObj = tr.GetObject(id, OpenMode.ForRead);
var types = new List<Type>();
var profLocn = new Object();
var startSta = new Object();
var minElev = new Object();
var profStyl = new Object();
Object pvStyObj = new Object();
double vScale = 1;
double vExag = 1;
types.Add(dbObj.GetType());
while (true)
{
var type = types[0].BaseType;
types.Insert(0, type);
if (type == typeof(RXObject))
{
break;
}
else if (type == typeof(ProfileViewStyle))
{
pvStyObj = type;
}
}
foreach (Type t in types)
{
foreach (var prop in t.GetProperties(flags))
{
try
{
if (t.Name == "Entity" && prop.Name.ToString() == "StyleName")
{
//ed.WriteMessage("\nBegin Store Style Name! ");
//ProfileViewStyle style = pvStyObj as ProfileViewStyle;
//GraphStyle grStyl = style.GraphStyle;
//vScale = grStyl.VerticalScale;
//vExag = grStyl.VerticalExaggeration;
profStyl = prop.GetValue(dbObj, null).ToString();
//ed.WriteMessage("\nVertical Scale: " + vScale.ToString());
//ed.WriteMessage("\nVertical Exaggeration: " + vExag.ToString());
//ed.WriteMessage("\nEnd Store Style Name! ");
}
if (t.Name == "Graph" && prop.Name.ToString() == "Location")
{
profLocn = prop.GetValue(dbObj, null);
}
if (t.Name == "ProfileView" && prop.Name.ToString() == "StationStart")
{
startSta = prop.GetValue(dbObj, null);
}
if (t.Name == "ProfileView" && prop.Name.ToString() == "ElevationMin")
{
minElev = prop.GetValue(dbObj, null);
}
if (doDump != false)
{
ed.WriteMessage("\nReflected Type: {0}\n\t\tType: {1}\n\t\tValue: {2}", prop.ReflectedType.Name, prop.PropertyType.Name, prop.GetValue(dbObj, null));
ed.WriteMessage("\n\t\tprop Name: {0}\n\t\tprop Attributes: {1}", prop.Name, prop.Attributes.ToString());
ed.WriteMessage("\n\t\tCalling Convention: {0}", prop.GetMethod.CallingConvention.ToString());
ed.WriteMessage("\n\t\tMethod Implementation Flags: {0}", prop.GetMethod.MethodImplementationFlags.ToString());
ed.WriteMessage("\n\t\tReturn Parameter: {0}", prop.GetMethod.ReturnParameter.ToString());
ed.WriteMessage("\n\t\tReturn Type: {0}", prop.GetMethod.ReturnType.ToString());
ed.WriteMessage("\n\t\tAttributes: {0}\n", prop.GetMethod.Attributes.ToString(), prop.IsSpecialName.ToString());
}
}
catch (System.Exception e)
{
ed.WriteMessage("\n" + e.Message);
}
}
}
if (doDump == false)
{
try
{
string yoffSet = minElev.ToString();
string origPtx = profLocn.ToString();
string xoffSet = startSta.ToString();
var ThisDrawing = Application.DocumentManager.MdiActiveDocument;
string origPt = origPtx;
origPtx = origPtx.Replace("(", "(TRANS(LIST ").Replace(",", " ").Replace(")", ")0 1)");
ed.WriteMessage("\norigPt: {0}\norigPtx: {1}\nX-offset: {2}\nY-offset: {3}\nProfile Style: {4}\nVert. Scale: {5}\nVert.Exaggeration: {6}", origPt, origPtx, xoffSet, yoffSet, profStyl, vScale.ToString(), vExag.ToString());
ThisDrawing.SendStringToExecute("._ucs non", true, false, false);
ThisDrawing.SendStringToExecute(" (POLAR(POLAR" + origPtx + "(* PI 1.5)" + yoffSet + ")PI " + xoffSet + ")", true, false, false);
ThisDrawing.SendStringToExecute(" non @100<0", true, false, false);
ThisDrawing.SendStringToExecute(" non @100<90 ", true, false, false);
}
catch (System.Exception ex)
{
ed.WriteMessage("\n" + ex.Message);
}
}
tr.Commit();
}
}
}
}
Henry C. Francis
Authorized Autodesk Developer
Civil Design Specialist – Water & Wastewater Infrastructure