We recently received a question from a customer asking how to programmatically access an ISO Arrow entity
and its direction within AutoCAD Plant 3D. Since detailed documentation on this specific task can be hard to find, I decided to share the code I developed to achieve this.
The C# snippet below demonstrates how to retrieve an ISO Arrow entity and its direction from a selected Pipe component in an AutoCAD Plant 3D environment. It leverages the Plant 3D API to access the Pipe object, its ports, and connections, then checks if these ports are linked to an ISO Arrow symbol.
public static void GetIsoArrowEntity()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityResult per = ed.GetEntity("\nSelect a Pipe component:");
if (per.Status != PromptStatus.OK)
{
ed.WriteMessage("\nCommand cancelled.");
return;
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId pipeId = per.ObjectId;
if (pipeId.IsNull)
{
ed.WriteMessage("\nPipe object not found.");
return;
}
Pipe pipeObj = tr.GetObject(pipeId, OpenMode.ForRead) as Pipe;
if (pipeObj == null)
{
ed.WriteMessage("\nObject is not a valid PnP3dObject.");
return;
}
//get symbolic ports
var portCollection = pipeObj.GetPorts(PortType.Symbolic);
foreach(Port port in portCollection)
{
Vector3d dir = port.Direction;
ed.WriteMessage(dir.ToString());
}
PipingProject pipingProject = PlantApplication.CurrentProject.ProjectParts["Piping"] as PipingProject;
DataLinksManager dlm = pipingProject.DataLinksManager;
Autodesk.ProcessPower.PnP3dObjects.ConnectionManager connManager = new ConnectionManager();
if (connManager == null)
{
ed.WriteMessage("\nConnection Manager is not available.");
return;
}
var connections = connManager.GetConnections(pipeId);
if (connections == null || connections.Count == 0)
{
ed.WriteMessage("\nNo connections found for the selected pipe.");
return;
}
foreach (Connection connection in connections)
{
ed.WriteMessage("\nConnection found between: " + connection.ObjectId1.ToString() + " and " + connection.ObjectId2.ToString());
ed.WriteMessage("\nPort 1: " + connection.Port1.Name + ", Port 2: " + connection.Port2.Name);
}
foreach (Port pPort in portCollection)
{
ed.WriteMessage("\nName of this Port = " + pPort.Name);
ed.WriteMessage("\nDirection of this Port = " + pPort.Direction.ToString());
Pair pair1 = new Pair
{
ObjectId = pipeId,
Port = pPort
};
if (connManager.IsConnected(pair1))
{
ed.WriteMessage("\n Pair is connected ");
Pair connectedPair = connManager.GetConnectedPairAt(pair1);
var arrowSymbol = tr.GetObject(connectedPair.ObjectId, OpenMode.ForRead) as IsoArrowSymbol;
var direction = arrowSymbol.Direction;
ed.WriteMessage("\nArrow Symbol Direction: " + direction.ToString());
double fixedLength = direction.Length;
ed.WriteMessage("\nFixed Length of Arrow Symbol: " + fixedLength.ToString());
}
else
{
ed.WriteMessage("\n Pair is NOT connected ");
}
}
tr.Commit();
}
}
Understanding the Output: Direction and Length
When you run this command, it will display the direction of the ISO Arrow entity associated with the selected Pipe component. You might notice that the Vector3d
representing the direction often has a non-unit magnitude (i.e., its length is not 1).
This is an important detail! Unlike a normalized vector that solely indicates direction, the Direction
property of an IsoArrowSymbol
in Plant 3D actually incorporates its fixed length. This means the magnitude of the Vector3d
directly corresponds to the displayed length of the arrow symbol itself, as seen in the Properties palette of the IsoArrowSymbol
.
This insight is crucial for developers who need to understand not just the orientation, but also the geometrical characteristics of these symbols within the Plant 3D drawing.
Recent Comments