Сообщество
AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
отмена
Отображаются результаты для 
Показать  только  | Вместо этого искать 
Вы имели в виду: 

API, How to get P3D object by LineNumber?

17 ОТВЕТ 17
РЕШЕНО
Ответить
Сообщение 1 из 18
rflin-CTCIM
1902 просмотров, 17 ответов

API, How to get P3D object by LineNumber?

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"

 

17 ОТВЕТ 17
Сообщение 2 из 18
sergey.utkin
в ответ: rflin-CTCIM

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"]);
                    }
                }
            }
        }
    }
}
Сообщение 3 из 18
rflin-CTCIM
в ответ: sergey.utkin

Thanks'

 

 Afa Lin

Сообщение 4 из 18
rflin-CTCIM
в ответ: rflin-CTCIM

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 + "'");

 

Сообщение 5 из 18
sergey.utkin
в ответ: rflin-CTCIM

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"]);
                        }
                    }
                }
            }
        }
    }
}

 

Сообщение 6 из 18
rflin-CTCIM
в ответ: sergey.utkin

when I run the function '[CommandMethod("GPOL")]', it has error msg?

ERROR.png

Сообщение 7 из 18
sergey.utkin
в ответ: rflin-CTCIM

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.

Сообщение 8 из 18
rflin-CTCIM
в ответ: sergey.utkin

Hi,

Thanks'

My Plant 3D version: 2016

Сообщение 9 из 18
sergey.utkin
в ответ: rflin-CTCIM

Could you printscreen the contents of the 'PnPRoleTypes' table of your current project?

Сообщение 10 из 18
rflin-CTCIM
в ответ: sergey.utkin

ERROR.png

Сообщение 11 из 18
sergey.utkin
в ответ: rflin-CTCIM

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.

 

f5.png

Сообщение 12 из 18
rflin-CTCIM
в ответ: sergey.utkin

SQL.png

 

SQL.png

Сообщение 13 из 18
sergey.utkin
в ответ: rflin-CTCIM

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?

Сообщение 14 из 18
rflin-CTCIM
в ответ: sergey.utkin

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.

 

Сообщение 15 из 18
sergey.utkin
в ответ: rflin-CTCIM

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.

 

f6.png

Сообщение 16 из 18
sergey.utkin
в ответ: sergey.utkin

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.

 

f7.png

Сообщение 17 из 18
rflin-CTCIM
в ответ: sergey.utkin

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

Сообщение 18 из 18
rflin-CTCIM
в ответ: rflin-CTCIM

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'

Не нашли то, что искали? Задайте вопросы в сообществе или поделитесь своими знаниями.

Новая тема  

Autodesk Design & Make Report

”Boost