That's very cool.
So the first bit is getting the dimensions of the box, and this bit is placing the box?
Public Sub Draw()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using trx As Transaction = db.TransactionManager.StartTransaction()
Using docloc As DocumentLock = doc.LockDocument
Dim pl As New Polyline()
pl.AddVertexAt(0, Point2d.Origin, 0, 0, 0)
pl.AddVertexAt(1, New Point2d(Width, 0), 0, 0, 0)
pl.AddVertexAt(2, New Point2d(Width, Length), 0, 0, 0)
pl.AddVertexAt(3, New Point2d(0, Length), 0, 0, 0)
pl.Closed = True
Dim model As BlockTableRecord = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForWrite)
model.AppendEntity(pl)
trx.AddNewlyCreatedDBObject(pl, True)
trx.Commit()
End Using
End Using
End Sub
So if i want the user to place the box rather than using 0,0,0 i need to change this bit to?
Public Function DrawRectangle(ByVal ULCorner As Geometry.Point3d, _
ByVal Width As Double, ByVal Height As Double, _
ByVal Space As String, ByVal LayerName As String) As DatabaseServices.Polyline2d
Dim myDWG As Document
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myBT As BlockTable
Dim myBTR As BlockTableRecord
Dim myPL As Polyline2d
Dim myPLPointColl As New Geometry.Point3dCollection
Try
myDWG = Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForRead)
myBTR = myBT(Space).GetObject(OpenMode.ForWrite)
myPLPointColl.Add(New Geometry.Point3d(ULCorner.X, ULCorner.Y, ULCorner.Z))
myPLPointColl.Add(New Geometry.Point3d(ULCorner.X + Width, ULCorner.Y, ULCorner.Z))
myPLPointColl.Add(New Geometry.Point3d(ULCorner.X + Width, ULCorner.Y - Height, ULCorner.Z))
myPLPointColl.Add(New Geometry.Point3d(ULCorner.X, ULCorner.Y - Height, ULCorner.Z))
myPL = New Polyline2d(Poly2dType.SimplePoly, myPLPointColl, 0, True, 0, 0, Nothing)
myBTR.AppendEntity(myPL)
myPL.Layer = LayerName
myTrans.AddNewlyCreatedDBObject(myPL, True)
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
Return myPL
Catch ex As SystemException
MsgBox(ex.Message)
Return Nothing
Catch ex As Exception
Return Nothing
End Try
End Function