Select object nested in block reference

Hi … In a dynamo graph, I need to select an object that is within a block reference in model space, also referred to as a nested object (referene: Express Tools > Copy nested object).
Havent found it yet …
Thanks for your patience.

Is this python on the right track? No need for a transaction … right?

import sys
import clr

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

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

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

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

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

rs = editor.GetNestedEntity('\nSelect nested entity: ')
objIds = rs.GetContainers()

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

It almost worked!!! No errors … no civil 3d crash…

Hi
Try you write code into this code
You have knowledge of C# write a program on c#
Then converted it into a python


import sys
import clr

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

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

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

 # Add DesignScript references
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference("System.Core")
import System
clr.ImportExtensions(System.Linq)
from System.Linq import Enumerable

# Enable Python support and load DesignScript library
from System.Collections.Generic import Dictionary

def get_text():
	
	textProps = []
	obj=[]
	handles = []
	errorReport = None
	global adoc
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
				btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				#btrlq = btr.Cast[ObjectId ]().ToArray()
				#btraa = btr.Cast[ObjectId ]().Select(id >= t.GetObject(id, OpenMode.ForWrite))
				t.Commit()			
	if errorReport == None:
		return btrlq
	else:
		return errorReport
	
OUT = get_text()

No need to program, OOTB nodes are enough:

1 Like

oops … huge aplogy. I didnt explain clearly. I need a node that lets the user select a single object in the drawing view. The drawing object is expected to be a nested object - one that is within a block. On selecting, the output needs to be the nested object details - not the block referenced details. You can get the nexted object using Editor.GetNestedeEntity. This is probabanly already included in one of the packages, like the Civil 3D Toolkit. For now … I will try to code with python. I am not sure how to get it right though. Editor.GetNestedEntity works with Automatic mode. In my graph I need it in manual mode, to let the user select the nested object before running the graph.
Thanks for responding. I was just unclear with the need this time round.

1 Like

Hi Anton,

Is it possible to further filter the nested objects by layer? I have a drawing where they are all solids nested but all are on different layers.

You probably can request the layer name with the Object.Layer node. The result of that list can be used to filter, for example with the FilterByBoolMask.

1 Like

Great thanks