Create Equipment Subpart via API

Create Equipment Subpart via API

Anonymous
Not applicable
1,245 Views
4 Replies
Message 1 of 5

Create Equipment Subpart via API

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
1,246 Views
4 Replies
Replies (4)
Message 2 of 5

jabowabo
Mentor
Mentor

I'd suggest a different approach.

You can get the nozzle orientation by finding the nozzle port vector direction.

Port.Direction
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi,  

 

I still cannot understand how to orientate Solid3d with the Port.Direction Vector.

 

Thanks.

0 Likes
Message 4 of 5

jabowabo
Mentor
Mentor
Accepted solution

You are using Matrix3D.Displacement to move the object but you'll need Matrix3D.Rotation to change the orientation. You can use the port vector to get the axis of rotation needed.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thank you,  

I'll try again with your advice.

 

I have much experience with other 3D software like PDMS, PDS, Smart 3D. It was quite easy job to create primitives with those 3D systems but it is more than 10 times harder with Plant 3D.

0 Likes