.NET

Reply
Distinguished Contributor
Patrick Johnson
Posts: 229
Registered: ‎04-26-2005
Message 1 of 1 (70 Views)

here is a sample of the code.

70 Views, 0 Replies
11-22-2006 10:50 AM
Also, my nested dynamic blocks do not update. Is there something I need to do to get the nested blocks to update and get the attributes to come in on insert?

thanks

Private Sub btnGetDrawing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDrawing.Click
Dim getFile As New OpenFileDialog
Dim strFileName As String

'getFile.InitialDirectory = "C:\program files\autocad 2007\"
getFile.InitialDirectory = "N:\Everyone\Design & Compliance\AutoCAD Library & Templates\"

getFile.AddExtension = True
getFile.Filter = "Drawing Files|*.dwg"
If getFile.ShowDialog = Windows.Forms.DialogResult.OK Then
strFileName = getFile.FileName
Else
Exit Sub
End If

Dim ED As Autodesk.AutoCAD.EditorInput.Editor
ED = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim InsertPoint As PromptPointResult

InsertPoint = ED.GetPoint("Pick Insertion Point")
Dim strSelectedName As String = Me.cmbBlockName.SelectedItem

Dim obj1 As ObjectId = InsertDrawing(strFileName, InsertPoint.Value)
Using DB As Database = HostApplicationServices.WorkingDatabase
Using Trans As Transaction = DB.TransactionManager.StartTransaction()
Try
Dim bRef As BlockReference = Trans.GetObject(obj1, OpenMode.ForWrite)

If bRef.IsDynamicBlock Then
m_BlkRefArray.Add(obj1)
GetNestedBlock(obj1)
DynamicProperties(obj1)
Else
MsgBox("Selected Block does not have Dynamic Properties", MsgBoxStyle.OkOnly, "Dynamic Information")
bRef.Erase(True)
End If
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
Trans.Commit()
Trans.Dispose()
End Try
End Using
End Using
End Sub

**************************************************************
Private Sub DynamicProperties(ByVal objID1 As ObjectId)
Dim intNumProps As Integer = 0
Dim ED As Autodesk.AutoCAD.EditorInput.Editor
ED = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
If objID1.IsNull Then
ED.WriteMessage("Dynamic Block error, no block selected")
Exit Sub
End If
Using DB As Database = HostApplicationServices.WorkingDatabase
Using Trans As Transaction = DB.TransactionManager.StartTransaction()
lblMainBlock.Text = "File Name = " & strBlkName
Dim BlkRef As BlockReference
Dim dynBlkRefProps As DynamicBlockReferencePropertyCollection
Dim dynBlkRefProp As DynamicBlockReferenceProperty
Dim intPanelHeight As Integer
Try

For intBlockCount As Integer = 0 To m_BlkRefArray.Count - 1

BlkRef = Trans.GetObject(m_BlkRefArray(intBlockCount), OpenMode.ForRead) 'doublecheck
If intBlockCount > 0 Then
Dim intPanelTop As Integer
If intBlockCount = 1 Then
intPanelTop = 35 + intPanelHeight
Else
intPanelTop = 5 + intPanelHeight + intPanelTop
End If

Dim Panel As New Panel
Panel.SuspendLayout()

Panel.BorderStyle = BorderStyle.FixedSingle
Panel.Location = New System.Drawing.Point(5, intPanelTop)
Panel.AutoScroll = False
Panel.Tag = CObj(intBlockCount)
Panel.Name = "pnlDynamicNest" & CStr(intBlockCount)

DynamicLabels(Panel, BlkRef.Id, Panel.Tag, Trans)

Dim i As Integer = 0
dynBlkRefProps = blkRef.DynamicBlockReferencePropertyCollection
intNumProps = dynBlkRefProps.Count

Dim PropList(intNumProps) As DynamicControl.DynamicControl
Dim l_DynamicNameArray As New ArrayList
Dim intTop As Integer
For Each dynBlkRefProp In dynBlkRefProps
PropList(i) = New DynamicControl.DynamicControl
Dim intLength As Integer = 0

If i = 0 Then
intTop = 40
Else
intTop = PropList(i - 1).Top + PropList(i).Height
End If

PropList(i).Location = New System.Drawing.Point(5, intTop)
PropList(i).DynamicName = dynBlkRefProp.PropertyName
l_DynamicNameArray.Add(dynBlkRefProp.PropertyName)
PropList(i).DynamicDescription = dynBlkRefProp.Description

Dim objObject As Object()
objObject = dynBlkRefProp.GetAllowedValues()
Dim intCount As Integer = objObject.Length
For iCount As Integer = 0 To intCount - 1
PropList(i).AddValue(objObject(iCount))
Next iCount
PropList(i).SetValue(dynBlkRefProp.Value)
If objObject.Length > 0 Then
PropList(i).drHeight = objObject.Length * 15
Else
PropList(i).drHeight = 5
End If

PropList(i).drWidth = 350

Panel.Controls.Add(PropList(i))

i += 1
Next
intPanelHeight = 45 + (intNumProps * PropList(i - 1).Height + (BlkRef.AttributeCollection.Count * 20))
Panel.Size = New System.Drawing.Size(380, intPanelHeight)

Me.grpDynamic.Controls.Add(Panel)
Panel.ResumeLayout()
m_DynamicNameArray.Add(l_DynamicNameArray)
If BlkRef.AttributeCollection.Count > 0 Then
GetAttributeInfo(Panel, Trans, BlkRef, intTop)
End If

Else
BlkRef = Trans.GetObject(objID1, OpenMode.ForRead)
Dim i As Integer = 0
dynBlkRefProps = BlkRef.DynamicBlockReferencePropertyCollection
intNumProps = dynBlkRefProps.Count

grpMainBlock.SuspendLayout()
Me.grpMainBlock.BorderStyle = BorderStyle.FixedSingle
If i = 0 Then
DynamicLabels(grpMainBlock, BlkRef.Id, grpMainBlock.Tag, Trans)
End If

Dim PropList(intNumProps) As DynamicControl.DynamicControl
Dim l_DynamicNameArray As New ArrayList
Dim intTop As Integer
For Each dynBlkRefProp In dynBlkRefProps

PropList(i) = New DynamicControl.DynamicControl
Dim intLength As Integer = 0

If i = 0 Then
intTop = 40
Else
intTop = PropList(i - 1).Top + PropList(i).Height
End If



PropList(i).Top = intTop
PropList(i).DynamicName = dynBlkRefProp.PropertyName
l_DynamicNameArray.Add(dynBlkRefProp.PropertyName)
PropList(i).DynamicDescription = dynBlkRefProp.Description

Dim objObject As Object()
objObject = dynBlkRefProp.GetAllowedValues()
Dim intCount As Integer = objObject.Length
For iCount As Integer = 0 To intCount - 1
PropList(i).AddValue(objObject(iCount))

Next iCount
PropList(i).SetValue(dynBlkRefProp.Value)
If objObject.Length > 0 Then
PropList(i).drHeight = objObject.Length * 15
Else
PropList(i).drHeight = 5
End If
PropList(i).drWidth = 350

' End If
'Dim dblScreen As Double = Screen.PrimaryScreen.Bounds.Height
Me.grpMainBlock.Tag = CObj(intBlockCount)
Me.grpMainBlock.Controls.Add(PropList(i))

i += 1
Next
intPanelHeight = 45 + (intNumProps * PropList(i - 1).Height)
grpMainBlock.Size = New System.Drawing.Size(380, intPanelHeight)
grpMainBlock.ResumeLayout()
m_DynamicNameArray.Add(l_DynamicNameArray)
If BlkRef.AttributeCollection.Count > 0 Then
GetAttributeInfo(grpMainBlock, Trans, BlkRef, intTop)
End If
End If
Next intBlockCount
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
If (Not Trans Is Nothing) Then
Trans.Dispose()
End If
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
End Try
End Using
End Using
End Sub
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.