Get Attribute from Layer, how?

Hello,

based on that topic:

how can i extent my infos from the .dwg ?

i want to get “Bezeichnung” - it is the BlockName.

grafik
:face_with_monocle:

KR

Andreas

Hola amigo @Draxl_Andreas como estas?? this is a hard nut to crack my friend, there is a way with open mep for .dwg attached to a revit file i let you the link, in the default dynamo de C3D even with packages only you can get the anonymous name, with Civil3D Toolkit you can have at least the handle, better than the anonymous name!! (Version 2023)

2 Likes

@gilberto.arechigaiba ,

Estoy bien, mi jefe dijo " tu eres mastro de MEP…", yo dijo “desde cuando?” , “…desde ahorita”

sadly it is closed that means, i can maybe find in github something… Muchas gracias

thats realy a progress

i can get Name, U253

i just need Atribute or Blockname like in revit(pic)

KR

Andreas

1 Like

@Draxl_Andreas

1 Like

are you need the c# cod ?

1 Like

@RMohareb ,

i prefer python, but i can traduce C# to python very well. I work on a PyRevit implementation.

when you have a hint, let me know :wink:

KR

Andreas

I work in Revit 2022 …still … hmmm @RMohareb

1 Like

for revit 2022

1 Like

Glad to help amigo Draxl, i’m also stock whit a similar situation since a couple months, amigo @RMohareb any chance of we can make work this .dll in dynamo for C3D? i’m not so strong in programation either!! :woozy_face: couldn’t select the blocks by the real name is a strong handycap for users!

1 Like

Brimoahreb Pak is Revit Pak… You can not load into dynamo C3d
image

In your case, you can use this node in Open MEP package : Class BlockReference | Open MEP

GetAttributes

2 Likes

Amigo @chuongmep buenas. you are: “El Chingon” :cowboy_hat_face: ; last time i didn’t make it work the .msi don’t install automatically the folder in the current Dynamo C3D, this time I search the folder an place it in the current version, it works, tank you man for real!!

1 Like

Hi,

An alternative is to convert the dwg to dxf then read the properties with a library like

an example with netDxf


# 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)

# 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.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="TEST")
5 Likes

Update: I made an script that works as Data Extraction with steroids: is to obtain position data, dynamic parameters (DP) with their values and attributes (AT) with their values, it generates an Excel file ([dwg file name + -DP OR -AT]) as appropriate, each sheet is a type of Block with its instances listed with its Attribute or Dynamic parameter values, Thanks again amigo @chuongmep i was 4 months blocked.