Hi all. Ok i create a block (OrionPoint) and a simple attribute (The id of the point eg: 1, 2, 3, 4...)
The create block method:
Public Sub Create()
If Me.Exist = True Then Return
Using dLock As DocumentLock = doc.LockDocument
Using trans As Transaction = db.TransactionManager.StartTransaction()
'get the block table
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
'create new block table record
Dim btr As New BlockTableRecord()
btr.Name = "OrionPoint"
Dim btrId As ObjectId = bt.Add(btr)
trans.AddNewlyCreatedDBObject(btr, True)
'create a circle for the outer boundary of the hatch
Dim circ As Circle = New Circle()
circ.Center = New Point3d(0, 0, 0)
circ.Radius = 0.0005 * SCALE_FACTOR
circ.LineWeight = LineWeight.LineWeight009
'add the circle object to the block table record
btr.AppendEntity(circ)
trans.AddNewlyCreatedDBObject(circ, True)
'adds the circle to object id array
Dim oc As ObjectIdCollection = New ObjectIdCollection()
oc.Add(circ.ObjectId)
'create the hatch and append it to the block table record
Dim h As Hatch = New Hatch()
oc.Add(btr.AppendEntity(h))
trans.AddNewlyCreatedDBObject(h, True)
'properties of the hatch
h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID")
h.Associative = False
h.AppendLoop(HatchLoopTypes.Outermost, oc)
h.EvaluateHatch(True)
h.Color = Color.FromRgb(255, 255, 255)
Dim dot As DrawOrderTable = trans.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite)
dot.SwapOrder(oc.Item(0), oc.Item(1)) 'item 0 = circ, item 1 = hatch
'create an attribute definition
Dim ad As New AttributeDefinition
ad.Prompt = "Insert ID"
ad.Tag = "ID"
ad.TextString = "Point ID"
ad.Justify = AttachmentPoint.MiddleLeft
ad.AlignmentPoint = New Point3d(0.001 * SCALE_FACTOR, 0, 0)
ad.Preset = False
ad.Height = TEXT_HEIGHT
btr.AppendEntity(ad)
trans.AddNewlyCreatedDBObject(ad, True)
trans.Commit()
End Using
End Using
End Sub
I struggle for hours to add the brockreference (that's easy) and give the attribute (that isn't) the id (1, 2, 3...).
Thank you