I tried putting together a recursive program to iterate thru nested blocks with dynamics. First off it is not returning true on the isdynamic call. I do not even know if this will update the blockreference in the block yet. Can some one take a look and see where my issue is, or if I can even use a recursive style programming with this.
I have nested dynamic blocks to about 4 levels, that is why I am trying recursive. I used it to populate the UI with all the dynamic properties. Just does not seem to be working writing back.
thanks in advance
pat
Private Function nestedupdate(ByRef obj1 As ObjectId)
'this is iterating thru the block and seeing if there are any block references that are in the
'current block that are nested and also have dynamics. It is using a recursive style of
'programming (calling itself)
Dim DynBlkRefProps As DynamicBlockReferencePropertyCollection
Dim DynBlkRefProp As DynamicBlockReferenceProperty
Using DB As Database = HostApplicationServices.WorkingDatabase
Using Trans As Transaction = DB.TransactionManager.StartTransaction()
Try
Dim bRef As BlockReference = Trans.GetObject(obj1, OpenMode.ForRead)
Dim BTR As BlockTableRecord = Trans.GetObject(bRef.BlockTableRecord, OpenMode.ForRead, True)
Dim ID As ObjectId
'looping thru to grab all the objectid in the table on the block reference
For Each ID In BTR
Dim Ent As Entity = Trans.GetObject(ID, OpenMode.ForWrite)
'is the selected entity a block
If TypeOf Ent Is BlockReference Then
Dim BlkRef As BlockReference = Ent
Dim bolAttributes As Boolean
If BlkRef.IsDynamicBlock Then
Dim dynObjectID As ObjectId = BlkRef.DynamicBlockTableRecord
Dim dynBtr As BlockTableRecord = CType(Trans.GetObject(dynObjectID, OpenMode.ForRead, False), BlockTableRecord)
DynBlkRefProps = BlkRef.DynamicBlockReferencePropertyCollection
For Each DynBlkRefProp In DynBlkRefProps
For iCount As Integer = 0 To DynBlkRefProps.Count - 1
If DynBlkRefProp.PropertyName = DynBlkRefProps(iCount).PropertyName Then
Dim control1 As Control
For Each control1 In Me.grpDynamic.Controls
If TypeOf control1 Is Panel Then
Dim PanelTemp As Panel
PanelTemp = CType(control1, Panel)
If PanelTemp.Tag = CObj(dynBtr.Name) Then
Dim control As Object
For Each control In PanelTemp.Controls
If TypeOf control Is DynamicControl.DynamicControl Then
Dim PropList As DynamicControl.DynamicControl
PropList = CType(control, DynamicControl.DynamicControl)
'If PropList.DynamicName = l_DynamicNameArray(iCount) Then
If PropList.DynamicName = DynBlkRefProps(iCount).PropertyName Then
If PropertyType(DynBlkRefProp) = "String" Then
DynBlkRefProp.Value = CType(PropList.GetValue, String)
ElseIf PropertyType(DynBlkRefProp) = "Double" Then
DynBlkRefProp.Value = CType(PropList.GetValue, Double)
ElseIf PropertyType(DynBlkRefProp) = "Short" Then
DynBlkRefProp.Value = CType(PropList.GetValue, Short)
ElseIf PropertyType(DynBlkRefProp) = "Long" Then
DynBlkRefProp.Value = CType(PropList.GetValue, Long)
ElseIf PropertyType(DynBlkRefProp) = "" Then
DynBlkRefProp.Value = CType(PropList.GetValue, String)
End If
'Exit For
End If
End If
If bolAttributes = True Then
If TypeOf control Is Label Then
Dim lblTemp As Label
lblTemp = CType(control, Label)
If Microsoft.VisualBasic.Left(lblTemp.Tag, 3) = "Att" Then
Dim control2 As Object
For Each control2 In PanelTemp.Controls
If TypeOf control2 Is TextBox Then
Dim txtTemp As TextBox
txtTemp = CType(control2, TextBox)
If txtTemp.Tag = lblTemp.Tag Then
UpdateAttributes("", BlkRef, lblTemp.Text, txtTemp.Text)
End If
End If
Next
End If
End If
End If
Next
End If
End If
Next
End If
Next iCount
Next
'insPoint = BlkRef.Position
BlkRef.RecordGraphicsModified(True)
End If
'intBlockCt = intBlockCt + 1
GetNestedBlock(BlkRef.Id)
End If
Next
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
Trans.Commit()
Trans.Dispose()
End Try
End Using
End Using
End Function