theone 发表于 2022-7-6 17:06:31

[HELP] How to get attributes

Hi frnds,
 
I have a dwg file which contains thousands of blockrefrence type objects
 
What i want is.....
 
for each block(block refrence type) in thedrawing
get its layer name
get is block name
nd get its block attributes
next
 
all this should be exported in the excel file
 
I have coded but it seems i m not getting the thing i want
 

Public Sub ChTitle_click()Dim acadOBJ As AcadObjectDim oEnt As AcadEntityDim oAtt As AcadAttributeReferenceDim varAtts As VariantDim varName As VariantDim varLayer As VariantDim varSwitchGearNo As VariantDim i, j, z As Integeri = j = 0'connect to excelDim oExcel As Excel.ApplicationDim oBook As Excel.WorkbookDim oSheet As Excel.WorksheetDim nRow As Integer'Open ExcelSet oExcel = New Excel.ApplicationoExcel.Visible = True'Set oBook = oExcel.Workbooks.Add("C:\trial.xls")' OptionalSet oBook = oExcel.Workbooks.Add()Set oSheet = oBook.Sheets("Sheet1")'With oSheetoSheet.Cells(1, 1).Borders.LineStyle = xlContinuousoSheet.Cells(1, 1).Font.Bold = TrueoSheet.Cells(1, 1) = "FEEDER ID"oSheet.Cells(1, 2).Borders.LineStyle = xlContinuousoSheet.Cells(1, 2).Font.Bold = TrueoSheet.Cells(1, 2) = "SwitchGear Type"oSheet.Cells(1, 3).Borders.LineStyle = xlContinuousoSheet.Cells(1, 3).Font.Bold = TrueoSheet.Cells(1, 3) = "SwitchGear No"'Variable declarationDim nStartwriting As IntegernStartwriting = 2'For Each oEnt In ThisDrawing.ModelSpaceFor Each oEnt In ThisDrawing.ModelSpace   If TypeName(oEnt) = "IAcadBlockReference" Then       oSheet.Cells(nStartwriting, 1) = oEnt.Layer       oSheet.Cells(nStartwriting, 2) = oEnt.Name       If oEnt.HasAttributes Then         varAtts = oEnt.GetAttributes         For i = 0 To UBound(varAtts)               ReDim varSwitchGearNo(j) As Variant               oSheet.Cells(nStartwriting, 3) = varAtts(i).TextString'                varSwitchGearNo(j) = varAtts(i).TextString               j = j + 1         Next i       End If       nStartwriting = nStartwriting + 1   End IfNextCall oBook.Close(True, "C:\" & "SLD" & ".xls")oExcel.DisplayAlerts = FalseoExcel.QuitEnd Sub
 
Anyone, what i m doing wrong

borgunit 发表于 2022-7-6 18:41:26

Rather than trying to figure it out, what exactly does it do? Does it fail? Does it put in wrong info? A little more specific please.
页: [1]
查看完整版本: [HELP] How to get attributes