How to get P3D object by LineNumber?
if I have the LinenUmber 'P-00-001', I want to get all P3d Object of this line "P-00-001"
Решено! Перейти к решению.
Решено: rflin-CTCIM. Перейти к решению.
Решено: sergey.utkin. Перейти к решению.
Решено: sergey.utkin. Перейти к решению.
Решено: sergey.utkin. Перейти к решению.
Hello,
please try the following code.
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.ProcessPower.ProjectManager; // add reference to 'PnPProjectManagerMgd.dll' using Autodesk.ProcessPower.PlantInstance; using Autodesk.ProcessPower.DataLinks; // add reference to 'PnPDataLinks.dll' using Autodesk.ProcessPower.DataObjects; // add reference to 'PnPDataObjects.dll' public class Commands { [CommandMethod("GPOL")] public static void GetPartsOnLinenumber() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // We prompt for the 'Tag' of linenumber PromptStringOptions pso = new PromptStringOptions("\nEnter the 'Tag' of linenumber: "); PromptResult pr = ed.GetString(pso); if (pr.Status != PromptStatus.OK) { return; } string linetag = pr.StringResult; // We get the project piping database PlantProject plantproj = PlantApplication.CurrentProject; Project proj = plantproj.ProjectParts["Piping"]; DataLinksManager dlm = proj.DataLinksManager; PnPDatabase pipingdb = dlm.GetPnPDatabase(); // We query the 'P3dLineGroup' table for records with our tag PnPRow[] linegroup = pipingdb.Tables["P3dLineGroup"].Select("Tag='" + linetag + "'"); if (linegroup.Length == 0) { // No records found ed.WriteMessage("\nThere is no linenumber with this 'Tag'"); } else { // We found a record. // Now we get the ids of all parts related to our linenumber PnPRowIdArray relatedids = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship", "LineGroup", linegroup[0].RowId, "Part"); if (relatedids.Count == 0) { // No related parts ed.WriteMessage("\nThere are no parts on this line number"); } else { // There are some related parts. // We create a header for the list of parts ed.WriteMessage("\n-------------Parts on '{0}'-------------", linetag); // We iterate through the related parts foreach (int partid in relatedids) { // We get the record from 'EngineeringItems' table PnPRow[] partrows = pipingdb.Tables["EngineeringItems"].Select("PnPID=" + partid); if (partrows.Length == 1) { // Now we output some data for the current part ed.WriteMessage("\nPnPId : {0} PartSizeLongDesc : {1} Spec : {2} Material : {3}", partid, partrows[0]["PartSizeLongDesc"], partrows[0]["Spec"], partrows[0]["Material"]); } } } } } }
Can I modify this program to get all of connection object (Ex, weld,Thread,...) by Linenumber?
Can I Modify the query condition? like 'tag=linetag AND .......' , Like SQL syntax
PnPRow[] linegroup = pipingdb.Tables["P3dLineGroup"].Select("Tag='" + linetag + "'");
I slightly modified the code to output only connection parts.
Not sure that this is the perfect way to achieve this, but it works for me.
And there is a more complex query in this code as reply for your second question.
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.ProcessPower.ProjectManager; // add reference to 'PnPProjectManagerMgd.dll' using Autodesk.ProcessPower.PlantInstance; using Autodesk.ProcessPower.DataLinks; // add reference to 'PnPDataLinks.dll' using Autodesk.ProcessPower.DataObjects; // add reference to 'PnPDataObjects.dll' public class Commands { [CommandMethod("GPOL")] public static void GetPartsOnLinenumber() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // We prompt for the 'Tag' of linenumber PromptStringOptions pso = new PromptStringOptions("\nEnter the 'Tag' of linenumber: "); PromptResult pr = ed.GetString(pso); if (pr.Status != PromptStatus.OK) { return; } string linetag = pr.StringResult; // We get the project piping database PlantProject plantproj = PlantApplication.CurrentProject; Project proj = plantproj.ProjectParts["Piping"]; DataLinksManager dlm = proj.DataLinksManager; PnPDatabase pipingdb = dlm.GetPnPDatabase(); // We query the 'P3dLineGroup' table for records with our tag PnPRow[] linegroup = pipingdb.Tables["P3dLineGroup"].Select("Tag='" + linetag + "'"); if (linegroup.Length == 0) { // No records found ed.WriteMessage("\nThere is no linenumber with this 'Tag'"); } else { // We found a record. // Now we get the ids of all parts related to our linenumber PnPRowIdArray relatedids = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship", "LineGroup", linegroup[0].RowId, "Part"); if (relatedids.Count == 0) { // No related parts ed.WriteMessage("\nThere are no parts on this line number"); } else { // There are some related parts. // We create a header for the list of parts ed.WriteMessage("\n-------------Parts on '{0}'-------------", linetag); // We iterate through the related parts foreach (int partid in relatedids) { // We query the 'PnPDataLinks' table. // The 'P3dConnector' class objects have DwgSubIndex=0. // 'Buttweld', 'Thread', etc. class objects have DwgSubIndex<>0 PnPRow[] subpartrows = pipingdb.Tables["PnPDataLinks"].Select("RowId=" + partid + " AND DwgSubIndex<>0"); if (subpartrows.Length > 0) { // The object is part of connection ('P3dConnector') // We get the record from 'EngineeringItems' table PnPRow[] partrows = pipingdb.Tables["EngineeringItems"].Select("PnPID=" + partid); if (partrows.Length == 1) { // Now we output some data for the current part ed.WriteMessage("\nPnPId : {0} PartSizeLongDesc : {1} Spec : {2} Material : {3}", partid, partrows[0]["PartSizeLongDesc"], partrows[0]["Spec"], partrows[0]["Material"]); } } } } } } }
I tested this code on Plant 3D 2013.
I guess there might be a change in database structure in the latter versions causing this error.
You can check the 'PnPRoleTypes' table for relation system in your current Plant 3D version.
Could you printscreen the contents of the 'PnPRoleTypes' table of your current project?
Sorry, i meant not changing the code, but a pictire like this.
And please make sure your current project includes the table i marked green.
I don't see any difference in the relations system in your project compared to mine.
Does the error occur for the first or second code or both?
Could you try different linenumbers?
The other Linenumber is same.
it's OK ==> PnPRow[] linegroup = pipingdb.Tables["P3dLineGroup"].Select("Tag='" + linetag + "'");
But this line has error. ==>PnPRowIdArray relatedids = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship", "LineGroup", linegroup[0].RowId, "Part");
I have checked the table P3dLineGroupPartRelationship, field LineGroup has linegroup[0].RowId (ex, 6402) information.
I could reproduce the error by changing
PnPRowIdArray relatedids = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship", "LineGroup", linegroup[0].RowId, "Part");
to
PnPRowIdArray relatedids = dlm.GetRelatedRowIds("Test", "LineGroup", linegroup[0].RowId, "Part");
Could you try this code to get the relation system of your current project?
[CommandMethod("RT")] public static void RelationshipTypes() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // We get the project piping database PlantProject plantproj = PlantApplication.CurrentProject; Project proj = plantproj.ProjectParts["Piping"]; DataLinksManager dlm = proj.DataLinksManager; PnPDatabase pipingdb = dlm.GetPnPDatabase(); PnPRelationshipTypes rels = pipingdb.RelationshipTypes; foreach (PnPRelationshipType rel in rels) { foreach (PnPRoleType role in rel.RoleTypes) { ed.WriteMessage("\nTypeName : {0} RoleName : {1}", rel.Name, role.Name); } } }
That's what i get here on Plant 3D 2013.
Just tried the code from my first two posts on trial Plant 3D 2016 English version. Everything works fine.
I suggest you contact Autodesk Support or ADN for this issue.
Hi,
Thanks'
I will send my code to Autodesk support.
Command: RT ( Plant 3D 2016 Ext1 )
TypeName : AssetOwnership RoleName : Owned
TypeName : AssetOwnership RoleName : Owner
TypeName : P3dDrawingLineGroupRelationship RoleName : Drawing
TypeName : P3dDrawingLineGroupRelationship RoleName : LineGroup
TypeName : P3dLineGroupPartRelationship RoleName : LineGroup
TypeName : P3dLineGroupPartRelationship RoleName : Part
TypeName : P3dPartConnection RoleName : Part1
TypeName : P3dPartConnection RoleName : Part2
TypeName : PartPort RoleName : Part
TypeName : PartPort RoleName : Port
TypeName : ReferenceRelationship RoleName : Referenced
TypeName : ReferenceRelationship RoleName : Referencing
Hi,
it's OK now.
I try to delete this line code then re-keyin it again, that is OK.
PnPRowIdArray relatedids = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship","LineGroup",lineRowid,"Part");
-------------Parts on 'p-00-004'-------------
PnPId:43713, PartSizeLongDesc:PIPE, SEAMLESS, 6" ND, PE, ASME B36.10, Spec:CS150, Material:
PnPId:43709, PartSizeLongDesc:Buttweld, Spec:CS150, Material:
PnPId:43703, PartSizeLongDesc:ELL 90 LR, 6" ND, BW, ASME B16.9, Spec:CS150, Material:
PnPId:43705, PartSizeLongDesc:Buttweld, Spec:CS150, Material:
Thanks'
Не нашли то, что искали? Задайте вопросы в сообществе или поделитесь своими знаниями.