Selecting Body (bodies) with Dynamo

Seeing this thread (Select all multi-leaders and delete) I’d like to share my approach on selecting (unknown) types in Dynamo. Now I found the “expose extra object types” node usefulle but still missed some types. This is my solution to this problem using the Civil3DToolkit. Hope you find it helpfull, comments are appreciated as well.


# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('Autodesk.Civil3DToolkit')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

import Autodesk.AutoCAD.DynamoNodes as DA

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument

## prepare output
dynamo_objects = []

with adoc.LockDocument():
    with adoc.Database as db:
        try:
            with db.TransactionManager.StartTransaction() as t:
                bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
                btrID = bt.get_Item("*Model_Space")
                mspace = t.GetObject(btrID, OpenMode.ForRead)
                
                
                for objID in mspace:
                    try:
                        obj = t.GetObject(objID, OpenMode.ForRead)
                        if type(obj) == Body:
                            dobj = DA.Object.InternalMakeObject(obj, False)
                            dynamo_objects.append(dobj)
                    except:
                        pass
               

                #t.Commit()
                pass
        except:
            pass

# Assign your output to the OUT variable.
OUT = dynamo_objects