Find All Data Shortcuts with a .NET API

Find All Data Shortcuts with a .NET API

tipitasa
Enthusiast Enthusiast
466 Views
2 Replies
Message 1 of 3

Find All Data Shortcuts with a .NET API

tipitasa
Enthusiast
Enthusiast

Is it possible to find all Data Shortcuts in the document?
I would like to get a list of all Data Shortcuts that includes Alignments, Surfaces, Pipe Networks, Pressure Networks and Corridors.

I know I can go group by group and traverse all entities in a group to find out which are references, like the below example for Surfaces.

Editor _ed = Application.DocumentManager.MdiActiveDocument.Editor;
CivilDocument _civilDoc = CivilApplication.ActiveDocument;
Database _db = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;

var surfaceIds = _civilDoc.GetSurfaceIds();
using (var tr = _db.TransactionManager.StartTransaction())
{
    foreach (ObjectId surfaceId in surfaceIds)
    {
        var surf = tr.GetObject(surfaceId, OpenMode.ForRead) as Entity;
        if (surf.IsReferenceObject)
        {
            var dsInfo = surf.GetReferenceInfo();
            _ed.WriteMessage("IsSourceDrawingExistent: " + dsInfo.IsSourceDrawingExistent + "\n");
            _ed.WriteMessage("SourceDrawing: " + dsInfo.SourceDrawing + "\n");
            _ed.WriteMessage("HandleHigh: " + dsInfo.HandleHigh + "\n");
            _ed.WriteMessage("HandleLow: " + dsInfo.HandleLow + "\n");
            _ed.WriteMessage("Type: " + dsInfo.Type + "\n");
        }
    }
    tr.Commit();
}


But this does not feel very efficient.

Is there a better way?

0 Likes
467 Views
2 Replies
Replies (2)
Message 2 of 3

kevin.bza
Advocate
Advocate

Was this resolved? Using better terms may help. DS Referenced objects are DREF's or Data References. Hoping to get all DREF's from a DWG DB in one step instead of iterating Object ID Collections, one by one.

0 Likes
Message 3 of 3

hosneyalaa
Advisor
Advisor

@tipitasa 

maybe this help you

code python

 

import sys
import clr

clr.AddReference('AeccDbMgd')
clr.AddReference('AeccDataShortcutMgd')

from Autodesk.Civil.DataShortcuts import *
from Autodesk.Civil.DataShortcuts import DataShortcutEntityType

vals = DataShortcuts.CreateDataShortcutManager(True)

dsm = vals[0]
c = dsm.GetPublishedItemsCount()
o = []
for i in range(c):
    p = dsm.GetPublishedItemAt(i)
    #pq = dsm.GetParentItemIndex(1)
    #o.append([p])
    if p.DSEntityType == DataShortcutEntityType.Alignment or p.DSEntityType == DataShortcutEntityType.Surface or p.DSEntityType == DataShortcutEntityType.PipeNetwork:
       o.append([p.Name , p.DSEntityType ])
    #o.append([p.Name , p.DSEntityType ])
    


OUT = o

393690103_6726025597475718_6101174310727086348_n.jpg

 

 

1.JPG