Public Class Class1 <CommandMethod("CBWA")> Public Sub CreateBlockWithAttributes() Dim db As Database = HostApplicationServices.WorkingDatabase Dim blockId As ObjectId = ObjectId.Null Using trans As Transaction = db.TransactionManager.StartTransaction Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) If bt.Has("RmNum") Then Return End If Dim record As New BlockTableRecord record.Name = "RmNum" blockId = bt.Add(record) trans.AddNewlyCreatedDBObject(record, True) Dim points As New Point3dCollection points.Add(New Point3d(-18, -6, 0)) points.Add(New Point3d(18, -6, 0)) points.Add(New Point3d(18, 6, 0)) points.Add(New Point3d(-18, 6, 0)) Dim pline As New Polyline2d(Poly2dType.SimplePoly, points, 0, True, 0, 0, Nothing) record.Origin = points(3) record.AppendEntity(pline) trans.AddNewlyCreatedDBObject(pline, True) Dim attdef As New AttributeDefinition attdef.Position = New Point3d(100, 200, 0) attdef.Height = 8 attdef.Rotation = 0 attdef.HorizontalMode = TextHorizontalMode.TextMid attdef.VerticalMode = TextVerticalMode.TextVerticalMid attdef.Prompt = "Room Number;" attdef.TextString = "0000" attdef.Tag = "Number" attdef.Invisible = False attdef.Verifiable = False attdef.Preset = False attdef.Constant = False record.Origin = points(3) record.AppendEntity(attdef) trans.AddNewlyCreatedDBObject(attdef, True) trans.Commit() End Using End Sub End Class |