AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read Data Manager with .Net

10 REPLIES 10
Reply
Message 1 of 11
abilabib
1623 Views, 10 Replies

Read Data Manager with .Net

This is my first time for custom AutoCAD Plant 3D. Could some one explain me how to read Data Manager just for Engineering Items using VB.Net

This code below read all data in data manager. But can't read new data if I add new item/symbol. 

 

Here's my code :

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput


Imports Autodesk.ProcessPower.ProjectManager
Imports Autodesk.ProcessPower.PlantInstance
Imports Autodesk.ProcessPower.DataLinks
Imports Autodesk.ProcessPower.Styles



<Assembly: ExtensionApplication(Nothing)>

Namespace DataManagerCon
    Public Class DataManageCon
        'test connection to PID Data Manager
        <CommandMethod("TestConnection")>
        Public Sub TestPnPID()
            'Menghubungkan Net ke Plant 3D
            Dim myDb As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
            'Koneksi ke data links manager
            Dim myDlm As DataLinksManager = DataLinksManager.GetManager(myDb)
            'Mengakses data P&ID untuk project yang sedang aktif
            Dim myProject As Project = PlantApplication.CurrentProject.ProjectParts("PnId")
            'Mengambil Data Gambar Yang sedang aktif
            Dim myProjectDrawings As List(Of PnPProjectDrawing) = myProject.GetPnPDrawingFiles()
            Dim sProperties As String = String.Empty

            Dim myRowIDs As Autodesk.ProcessPower.DataObjects.PnPRowIdArray = myDlm.SelectAcPpRowIds(myDb)
            For Each myRowID As Integer In myRowIDs
                Dim myProperties As List(Of KeyValuePair(Of String, String)) = myDlm.GetAllProperties(myRowID, True)

                For Each myProperty As KeyValuePair(Of String, String) In myProperties
                    If myProperty.Key.ToUpper = "MANUFACTURER" Or myProperty.Key.ToUpper = "CLASSNAME" Then
                        sProperties = sProperties & myProperty.Key.ToUpper & ":" & myProperty.Value
                    End If
                Next
                sProperties = sProperties & vbNewLine

            Next
            MsgBox(sProperties)
        End Sub

    End Class

End Namespace
10 REPLIES 10
Message 2 of 11
jabowabo
in reply to: abilabib


@abilabib wrote:

But can't read new data if I add new item/symbol. 


Can you elaborate? I don't understand if there is a question here.

Message 3 of 11
abilabib
in reply to: jabowabo

@jabowabo 

 

If I put new P&ID symbol in the drawing and the running script. Program can't read new data. 

 

Regards,

 

Afri

Message 4 of 11
jabowabo
in reply to: abilabib

Do new items show in the results after you save the file?

Message 5 of 11
abilabib
in reply to: jabowabo

@jabowabo : The data is show in data manager. But if I running the code, the new data isn't shown.

Message 6 of 11
jabowabo
in reply to: abilabib

I think your issue is related to how you are retrieving the DataLinksManager. The following C# code works as expected:

            // get current dwg stuff
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            // get P3D stuff
            PlantProject currentProj = PlantApp.CurrentProject;
            PnIdProject pnidProj = (PnIdProject)currentProj.ProjectParts["PnId"];
            DataLinksManager dlm = pnidProj.DataLinksManager;

            // List of properties to report
            List<string> reportProps = new List<string>() { "MANUFACTURER", "CLASSNAME" };

            // Create message string
            string reportMsg = "";

            // get rowIds associated with current drawing database
            PnPRowIdArray rowIds = dlm.SelectAcPpRowIds(db);

            // iterate rowIds
            foreach (var rowId in rowIds)
            {
                reportMsg += $"\nrowId : {rowId}";
                List<KeyValuePair<string, string>> props = dlm.GetAllProperties(rowId, true);

                // iterate properties
                foreach (var prop in props)
                {
                    string propKeyUp = prop.Key.ToUpper();

                    // report properties
                    if (reportProps.Contains(propKeyUp))
                    {
                        reportMsg += $"\n\t {prop.Key} : {prop.Value}";
                    }
                }

                reportMsg += Environment.NewLine;
            }

            ed.WriteMessage(reportMsg);
Message 7 of 11
abilabib
in reply to: jabowabo

@jabowabo : Thanks for your reply. I'll try. 

Message 8 of 11
simonjones-uk
in reply to: abilabib

I'm trying the read the LineNumberTag from a pipe from within an Orthographic drawing (I know the handle of the pipe in the 3D Model from xdata on the Orthographic representation):

 

((-1 . <Entity name: 125a1b23f10>) (0 . "INSERT") (5 . "CD1") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 125a1b278c0>) (102 . "}") (330 . <Entity name: 125abe071f0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Top (Plan) View-PIPING") (100 . "AcDbBlockReference") (2 . "*U27") (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0) (-3 ("PnPOrthoApp" (1071 . 901) (1005 . "35E") (1071 . 0) (1000 . "Piping") (1000 . "{ACDD082F-9A28-284A-8616-7ADCEC8A0F9C}"))))

 

So far I've only been able to read the information via the Data Link Manager when I'm in the 3D Model and not from within the Orthographic drawing. In fact, if I try to open the Data Manager palette from the Orthographic Drawing nothing is displayed - any clues on that?

Message 9 of 11
jabowabo
in reply to: simonjones-uk

The DataManager window doesn't open while Plant 3D is in Ortho drawing context. You can only get a model entity's ObjectId while the model is open - this is because ObjectId is not persistent between sessions, while Handles are.

 

You can use the DwgId and the handle (translated to DwgHandleLow) to query the PnPDataLinks table to find the model item rowId. With the rowId, you can find the properties in whichever tables it exists in.

Message 10 of 11
simonjones-uk
in reply to: jabowabo

Thanks Jason, that helped. My handle is "35E" that converts to a DwgHandleLow of 862 which does indeed lead me to the required RowId of 1065:

 

simonjonesuk_0-1694725687355.png

However, to find that DwgHandleLow I looped through 1066 rows and for each calling:

 

List<KeyValuePair<string, string>> props = dlmgr.GetAllProperties(i, true);

 

Is there a way I can get those Properties directly with a query without having to loop through each row until I find it?

 

Much appreciated, Simon

Message 11 of 11
jabowabo
in reply to: simonjones-uk

There's no need to loop through the rows. You can query the datalinks table for the row with the same DwgId and DwgHandleLow. From here, you get the RowId, which you can use to get the properties from dlm. If that's not clear, DM me your code and I'll take a look.

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report