PDA

View Full Version : Dynamic Block Effective Name



CADdancer
2007-10-10, 04:24 PM
Hello AUGI Members,

I am trying to extract information from AutoCAD "Dynamic Blocks" into an Excel spread sheet. I have developed the segment of code below that worked fine when I was using normal blocks with attributes however, it does not work properly with Dynamic Blocks. I have tried to use the "Effective Name" property but I still get incorrect results.



If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
If StrComp(Left(.Name, 3), UCase(PartEnt.EffectiveName) = UCase("SB1"), vbTextCompare) = 0 Then '
If .HasAttributes Then
Array1 = .GetAttributes
For count = LBound(Array1) To UBound(Array1)
If Header = False Then
If RowNum = 1 Then
iFoo = 1
excelSheet.Cells(RowNum, iFoo).Font.Bold = True
excelSheet.Cells(RowNum, iFoo).Value = "STEEL REPORT"
RowNum = RowNum + 1
iFoo = 0
End If
If StrComp(Array1(count).EntityName, "AcDbAttribute", 1) = 0 Then
'do not print the first element btag because it is a duplicate
If Array1(count).TagString <> "BTAG" Then
iFoo = iFoo + 1
excelSheet.Cells(RowNum, iFoo).HorizontalAlignment = xlCenter
excelSheet.Cells(RowNum, iFoo).Font.Bold = True
excelSheet.Cells(RowNum, iFoo).Value = Array1(count).TagString
End If
End If
End If
Next count

RowNum = RowNum + 1 'New row
iSkip = 0 'Do not print the first element in the collection
iFoo = 0 'Reset the column counter

For count = LBound(Array1) To UBound(Array1)
'If break of member then print summary record
If count <> iSkip Then
iFoo = iFoo + 1
If count <> 2 Then
excelSheet.Cells(RowNum, iFoo).Value = Array1(count).TextString
Else
excelSheet.Cells(RowNum, iFoo).Style.Name = "Number"
excelSheet.Cells(RowNum, iFoo).Value = CDbl(Array1(count).TextString)
End If
End If

Next count
Header = True
End If
End If
End If
End With
Next elem



Can someone with more VBA experience help me with the correct use of the "EffectiveName" property to filter for the dynamic blocks named "SB1".

Any assistance would be appreciated...!

Regards,
Vince

RobertB
2007-10-10, 06:39 PM
This is bad:
If StrComp(Left(.Name, 3), UCase(PartEnt.EffectiveName) = UCase("SB1"), vbTextCompare) = 0

All it needs to be is:
If Left$(UCase(.EffectiveName), 3) = "SB1" Then

CADdancer
2007-10-10, 10:20 PM
Robert,

I want to thank you for your code example....it appears to work great with the dynamic blocks. However, I do have a question regarding other similar name blocks I would like to include in the filter such "SB1-D" and "SB1-C" and "SB1-T" etc. I tried to wild-card the SB1 with SB1* and it did not work. What would I need to do to include all of the similar named DB's in the selection....??

Once again thank you for you help....!

Regards,
Vince

RobertB
2007-10-10, 10:50 PM
My posted example should be doing what you want. How much VBA experience do you have? Can you understand what my posted code is doing?

CADdancer
2007-10-11, 11:27 AM
Robert,

Thank you for your response.

I have limited VBA experience and I and trying to learn as I go and at the same time develop some routines that can be helpful. I have since tested your posted code and found that it does fine all of the dynamic blocks that have "SB1" as part of their name.

Can you recommend some good documentation and/or tutorials I can read to expand my VBA knowledge....??

Once again thank you for your assistance....!

Regards,
Vince

Ed Jobe
2007-10-11, 02:10 PM
Check out the ATP archives.