Just want to know if it is possible to do what you want with AutoCAD VBA? It is definitely YES (assuming the said blocks that have nested block in it are used correctly), so as with other programming language/API, such as Lisp, or .NET API.
If you intend to do it with VBA, you should show the code you have done so far and where/what is the coding difficulties you are to overcome and need help with.
I am looking for support with the code, I have no experience performing routines, only using the program, this is my intention when posting the problem.
@Dan-Rod wrote:
I am looking for support with the code, I have no experience performing routines, only using the program, this is my intention when posting the problem.
Why are you seeking help here if you got help in the lisp forum?
Try the code below, could help you to export blocks attributes to excel worksheet.
For the other parts of your request I don't understand the main issue.
bye
Sub TestNBlo()
Set NewExcel = GetObject(, "Excel.Application")
Set WRKBS = NewExcel.Workbooks.Add
Set wrks = NewExcel.ActiveSheet
MyRow = 1
MyCol = 1
Dim ent As AcadEntity
Dim blkRef As AcadBlockReference
Dim att As AcadAttributeReference
Dim atts As Variant
Dim i As Integer
With wrks.Cells
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Name = "Times New Roman"
.Font.Size = 10
.NumberFormat = "@"
End With
Dim blkDef As AcadBlock
For Each blkDef In ThisDrawing.Blocks ' Assume the block definition does exist in ThisDrawing
For Each ent In blkDef
If TypeOf ent Is AcadBlockReference Then
Set blkRef = ent
If blkRef.HasAttributes Then
wrks.Cells(MyRow, MyCol).Value = blkRef.EffectiveName
atts = blkRef.GetAttributes()
For i = 0 To UBound(atts)
wrks.Cells(MyRow + 1, MyCol + 1).Value = atts(i).TagString
wrks.Cells(MyRow + 1, MyCol + 2).Value = atts(i).TextString
MyRow = MyRow + 1
'MyCol = MyCol + 1
Next
End If
End If
Next
MyCol = MyCol + 2
MyRow = 1
Next
MsgBox "END"
End Sub
Hello, thanks for your time,
It gives me an alert attached to the photo,
As for what I am looking for, it is a way to be able to give consecutive attributes mentioned in the publication. If there is a way to extract them in Excel, modify and enter the new data, it would be perfect. It is the "GA" attribute of the "CAT" blocks. which are nested in the blocks between parentheses.
Hi, as far as I read you are not so expert with VBA.
I'll try to explain:
first of all procedure has been developed inside AUTOCAD VBA, so if you have not an Autocad release able to developing VBA Application, the procedure shall be devolped inside Excel, pointing to Autocad drawing, could be more or less the same but at the same time little bit different.
Starting from point above, you should declare inside Autocad the Excel library in order to use the Excel Worksheet like an object of Autocad.
So if the answer first point is true, first of all you have to create a VBA project, insert a Module, and paste the procedure.
Second point concerning the Excel library please look at picture below:
1) Open Visual Basic Editor
2) Excel Reference
Inside development module please find "Tools" -> "References", a window like the below should appear.
Please check the Excel Objet Library Flag, if you do not have the release 16 of the Library, probably you will find a "MISSING" side the Excel 16 Library text, in case de-flag the MISSING one, scroll the library list and flag the latest Excel Object Library available in your computer where MS OFFICE software tools is installed .
The attribute writing it's the same as the attribute reading, once you have the array atts(i).TextString of selected block do you want to modify, which is containing the value of your attribute (LABEL or TAG indicated in atts(i).Tagstring) you have to find a way to check the modified field in excel, and rewrite into Autocad like as atts( ... " POSITION OF ATTRIBUTE IN THE ARRAY .... ").TextString = wrks.Cells(MyRow , MyCol).Value.
I guess you have to create a mix of procedures, a part with autocad, and a part with Excel, I guess this will take time, or completely into EXCEL.
So first of all you have select only the blocks to be modify, get attributes, write to excel, modify in excel and rewrite in the block.
Please note that you could have a lot of blocks with the same name, but with different attributes, in this case you have to retrive a block properties named block ID, and write it to excel in order to modify only that block.
If this is not required, and you want to increase only one attribute sequentially as the block will be found during the scan in my opinion could be more easy.
I know are a lot of information, and suggestion perhaps you are searching for a working code but this take a time to working on.
I'm suggesting to use forums, or part of other routine on web and make experiment. Everybody in this forum or MS office Forum could help you.
Bye.