Get Attribute from Layer, how?

Thanks @c.poupin great, that is, but I’m on Revit 2023, with “CPython3” and I have an error to get the name:

if I skip this verification I have another error with the “insert”:

thanks in advance for your help

_Get_Attributes_Block_DWG_D216_R23.dyn (40.9 KB)

Projet1_With_Block_R23_ENG.rvt (9.3 MB)

BLOCk_with_ATT_Convert_To_DXF_2013.dxf (133.2 KB)

@paris

it’s a PythonNet2.5 (CPython3) bug (use the getter method get_Name() instead)

# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DS

# Import necessary Revit libraries
clr.AddReference('RevitAPI')
import Autodesk
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import DynamoServices for workspace information
clr.AddReference("DynamoServices")
from Dynamo.Events import *

# Access to the current Dynamo workspace path (e.g., location of the opened dynamo file)
currentWorkspacePath = ExecutionEvents.ActiveSession.CurrentWorkspacePath
currentWorkspace = ExecutionEvents.ActiveSession.CurrentWorkspacePath
directoryScript = System.IO.Path.GetDirectoryName(currentWorkspace)
#sys.path.append(directoryScript)
# sys.path.append(r"C:\Users\<user>\Downloads\netdxf.netstandard.3.0.1.nupkg\lib\netstandard2.0")
sys.path.append(r"D:\dy___Script x VE_CLEAN_2025-09-15\DWG_2025-09-23\package\netdxf.netstandard.3.0.1\lib\netstandard2.0")

# Import netDxf library for working with DXF files
clr.AddReference('netDxf.netstandard')
import netDxf
from netDxf import *
from netDxf.Blocks import *
from netDxf.Collections import *
from netDxf.Entities import *
from netDxf.Tables import *

# Define a class for working with DXF files
class DXF_Utils():
    def __init__(self, outDxfpath):
        self.outDxfpath = outDxfpath
        self._doc_dxf = None
        # Check if the DXF file exists, and if so, load it
        if System.IO.File.Exists(self.outDxfpath):
            # Initialize Document
            self._doc_dxf = DxfDocument()
            self._doc_dxf = netDxf.DxfDocument.Load(self.outDxfpath)

    # Method to get all insert blocks with a specific attribute tag
    def GetAll_Insert_Blocks(self, searchTag=""):
        out = []
        for e in self._doc_dxf.Inserts:
            # Check if the block has the specified attribute tag
            att_Test = e.Attributes.AttributeWithTag(searchTag)
            if att_Test is not None:
                # Create a DesignScript point from the DXF insert position
                pt = DS.Point.ByCoordinates(e.Position.X, e.Position.Y, e.Position.Z)
                out.append([e.Block.Name, pt, att_Test.Tag, att_Test.Value])
        return out

# Unwrap the imported DXF element
import_inst_dxf = UnwrapElement(IN[0])
cadLinkType = doc.GetElement(import_inst_dxf.GetTypeId())

# Check if the linked CAD file is a DXF file
if cadLinkType.get_Name().endswith(".dxf"):
    # Get the file path of the linked DXF file
    ext_fileRef = cadLinkType.GetExternalFileReference()
    modelpath_dxf = ext_fileRef.GetAbsolutePath()
    dxf_filepath = DB.ModelPathUtils.ConvertModelPathToUserVisiblePath(modelpath_dxf)

    # Create an instance of DXF_Utils class and get all insert blocks with a specific attribute tag
    obj_dxf = DXF_Utils(dxf_filepath)
    OUT = obj_dxf.GetAll_Insert_Blocks(searchTag="ATT_1")

related article

Hi @c.poupin , great news — the get_Name() function is working as expected!
However, I’m still encountering an error with the method def GetAll_Insert_Blocks(self, searchTag=""):.

Thanks in advance for your help.
Cheers, and have a great day!

It works fine on my side, maybe a CPython3 bug

try with IronPython2 or IronPython3 with this code

# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DS

# Import necessary Revit libraries
clr.AddReference('RevitAPI')
import Autodesk
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import DynamoServices for workspace information
clr.AddReference("DynamoServices")
from Dynamo.Events import *

# Access to the current Dynamo workspace path (e.g., location of the opened dynamo file)
currentWorkspacePath = ExecutionEvents.ActiveSession.CurrentWorkspacePath
currentWorkspace = ExecutionEvents.ActiveSession.CurrentWorkspacePath
directoryScript = System.IO.Path.GetDirectoryName(currentWorkspace)
#sys.path.append(directoryScript)
sys.path.append(r"C:\Users\sneep\Downloads\netdxf.netstandard.3.0.1.nupkg\lib\netstandard2.0")

# Import netDxf library for working with DXF files
clr.AddReference('netDxf.netstandard')
import netDxf
from netDxf import *
from netDxf.Blocks import *
from netDxf.Collections import *
from netDxf.Entities import *
from netDxf.Tables import *

# Define a class for working with DXF files
class DXF_Utils():
    def __init__(self, outDxfpath):
        self.outDxfpath = outDxfpath
        self._doc_dxf = None
        # Check if the DXF file exists, and if so, load it
        if System.IO.File.Exists(self.outDxfpath):
            # Initialize Document
            self._doc_dxf = DxfDocument()
            self._doc_dxf = netDxf.DxfDocument.Load(self.outDxfpath)

    # Method to get all insert blocks with a specific attribute tag
    def GetAll_Insert_Blocks(self, searchTag=""):
        out = []
        for e in self._doc_dxf.Inserts:
            # Check if the block has the specified attribute tag
            att_Test = e.Attributes.AttributeWithTag(searchTag)
            if att_Test is not None:
                # Create a DesignScript point from the DXF insert position
                pt = DS.Point.ByCoordinates(e.Position.X, e.Position.Y, e.Position.Z)
                out.append([e.Block.Name, pt, att_Test.Tag, att_Test.Value])
        return out

# Unwrap the imported DXF element
import_inst_dxf = UnwrapElement(IN[0])
cadLinkType = doc.GetElement(import_inst_dxf.GetTypeId())

# Check if the linked CAD file is a DXF file
if cadLinkType.ToDSType(False).Name.endswith(".dxf"):
    # Get the file path of the linked DXF file
    ext_fileRef = cadLinkType.GetExternalFileReference()
    modelpath_dxf = ext_fileRef.GetAbsolutePath()
    dxf_filepath = DB.ModelPathUtils.ConvertModelPathToUserVisiblePath(modelpath_dxf)

    # Create an instance of DXF_Utils class and get all insert blocks with a specific attribute tag
    obj_dxf = DXF_Utils(dxf_filepath)
    OUT = obj_dxf.GetAll_Insert_Blocks(searchTag="ATT_1")

Hi @c.poupin thanks for your help. yes it might be an issue with my PC.
I’ll try again another time.
Have a great day – cheers!"