- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Experts.
I'd like to create equipment subparts at the exact point3D of nozzle node by clicking nozzle.
I started my code by referencing SDK sample code.
I did not started with python script to do this job because I didn't have enough reference to python script and it is almost impossible to debug. So, I stuck to use .NET API.
My question is .... How to control the ECS(entity coordinate system) and WCS (world coordinate system) in Plant 3D
I have Equipment orientation matrix(Equipment.Ecs) & Equipment position(Equipment.Position) / Nozzle orientation matrix(Nozzle.Ecs) & Nozzle position(Nozzle.Port1.Position). And my nozzle orientation can be any angle around equipment body.
I 'd like to place box(3D solid) at node point3d of clicked nozzle with the same orientation as the nozzle.
1. solid3d.TransformBy(Matrix3d.Displacement(nozzle.Position - Point3d.Origin));
: with this code, the box is located at the exact node point of nozzle but the orientation is different.
2. solid3d.TransformBy(nozzle_matrix);
: with this code, the orientation is correct but the box is located at a different position from the node point of nozzle.
Here is my code :
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document active_document = Application.DocumentManager.CurrentDocument;
Database active_database = active_document.Database; // ok
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = active_database.TransactionManager;
ObjectId equipment_id;
PromptSelectionOptions selOpt = new PromptSelectionOptions();
selOpt.MessageForAdding = "\n Select Equipment Entity : ";
PromptSelectionResult res = ed.GetSelection(selOpt);
if (res.Status == PromptStatus.OK)
{
if(res.Value[0].ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Autodesk.ProcessPower.PnP3dObjects.Equipment))))
{
equipment_id = res.Value[0].ObjectId;
}
}
Transaction tr = tm.StartTransaction();
BlockTable bt = (BlockTable)tm.GetObject(active_database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Autodesk.ProcessPower.PnP3dObjects.Equipment equipment = tr.GetObject(equipment_id, OpenMode.ForRead) as Autodesk.ProcessPower.PnP3dObjects.Equipment;
Matrix3d equipment_matrix = equipment.Ecs;
Point3d equipment_position = equipment.Position;
// .....................
Matrix3d nozzle_matrix = match_nozzle.Ecs;
Point3d nozzle_position = match_nozzle.FindPort("S1", Autodesk.ProcessPower.PnP3dObjects.PortType.All).Position;
// .....................
Solid3d solid3d = new Solid3d();
solid3d.CreateBox(100, 200, 300);
//solid3d.TransformBy(Matrix3d.Displacement(nozzle_position - Point3d.Origin));
//solid3d.TransformBy(nozzle_matrix);
ObjectId box_id = btr.AppendEntity(solid3d);
tr.AddNewlyCreatedDBObject(solid3d, true);
tr.Commit();
thank in advance.
Solved! Go to Solution.