Message 1 of 4
VB.NET block with attributes problem

Not applicable
11-12-2020
11:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm trying to work with block + attributes, I can create it but if I insert it by .net hte block don't have attributes, if I
insert it manually the attributes are ok why?
<CommandMethod("AddingAttributeToABlock")>
Public Sub AddingAttributeToABlock()
' Get the current database and start a transaction
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim blkRecId As ObjectId = ObjectId.Null
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
If Not acBlkTbl.Has("CircleBlockWithAttributes") Then
Using acBlkTblRec As New BlockTableRecord
acBlkTblRec.Name = "CircleBlockWithAttributes"
' Set the insertion point for the block
acBlkTblRec.Origin = New Point3d(0, 0, 0)
' Add a circle to the block
Using acCirc As New Circle
acCirc.Center = New Point3d(0, 0, 0)
acCirc.Radius = 2
acBlkTblRec.AppendEntity(acCirc)
' Add an attribute definition to the block
Using acAttDef As New AttributeDefinition
acAttDef.Position = New Point3d(0, 0, 0)
acAttDef.Verifiable = True
'acAttDef.Visible = False
acAttDef.Prompt = "Door #: "
acAttDef.Tag = "Door#"
acAttDef.TextString = "DXX"
acAttDef.Height = 1
acAttDef.Justify = AttachmentPoint.MiddleCenter
acAttDef.LockPositionInBlock = True
acBlkTblRec.AppendEntity(acAttDef)
acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite)
acBlkTbl.Add(acBlkTblRec)
acTrans.AddNewlyCreatedDBObject(acBlkTblRec, True)
End Using
End Using
blkRecId = acBlkTblRec.Id
End Using
End If
Dim pPtRes As PromptPointResult
Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
'' Prompt for the start point
pPtOpts.Message = vbLf & "Enter the point: "
pPtRes = acDoc.Editor.GetPoint(pPtOpts)
Dim ptStart As Point3d = pPtRes.Value
'' Exit if the user presses ESC or cancels the command
If pPtRes.Status = PromptStatus.Cancel Then Exit Sub
' Insert the block into the current space
If blkRecId <> ObjectId.Null Then
Using acBlkRef As New BlockReference(ptStart, blkRecId)
Dim acCurSpaceBlkTblRec As BlockTableRecord
acCurSpaceBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite)
acCurSpaceBlkTblRec.AppendEntity(acBlkRef)
acTrans.AddNewlyCreatedDBObject(acBlkRef, True)
End Using
End If
' Save the new object to the database
acTrans.Commit()
' Dispose of the transaction
End Using
End Sub
End Class