.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Nested Dynamic block

1 REPLY 1
Reply
Message 1 of 2
Anonymous
225 Views, 1 Reply

Nested Dynamic block

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
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

After I posted this I noticed I was calling my other recursive function (the one I copied this from).
I put this nestedupdate(BlkRef.Id)
in place of the getnestedblock (right above catch)
after a regen it updated the nested blocks. Need to work on original block dynamics.

If anyone sees something I can do to this function to capture the original blocks (1st level) let me know. It is amazing you can spend 4-6 hours pulling out hair and it was something like that.

thanks

pat

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost