Message 1 of 4
Not applicable
03-06-2018
05:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i have method for creating rectangle:
Public Shared Sub PlotRectangle()
Dim doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db = doc.Database
Dim ed = doc.Editor
Dim ppr = ed.GetPoint(vbLf & "First corner: ")
If ppr.Status <> PromptStatus.OK Then Return
Dim pt1 = ppr.Value
ppr = ed.GetCorner(vbLf & "Opposite corner: ", pt1)
If ppr.Status <> PromptStatus.OK Then Return
Dim pt2 = ppr.Value
Dim x1 = pt1.X
Dim y1 = pt1.Y
Dim x2 = pt2.X
Dim y2 = pt2.Y
Using locked As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Using tr = db.TransactionManager.StartTransaction()
Dim pline = New Polyline(4)
pline.AddVertexAt(0, New Point2d(x1, y1), 0, 0, 0)
pline.AddVertexAt(1, New Point2d(x2, y1), 0, 0, 0)
pline.AddVertexAt(2, New Point2d(x2, y2), 0, 0, 0)
pline.AddVertexAt(3, New Point2d(x1, y2), 0, 0, 0)
pline.Closed = True
pline.TransformBy(ed.CurrentUserCoordinateSystem)
Dim curSpace = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
curSpace.AppendEntity(pline)
SaveRectangle(pline,Username,pline.Handle)
tr.AddNewlyCreatedDBObject(pline, True)
tr.Commit()
End Using
End Using
and have uncompleted method to save coordinates of rectangle(upperleft, upperright, lowerleft, lowerright) to Database.
Public Shared Sub SaveRectangle(ByVal rectEnt As Rectangle3d, ByVal username As String, GeomId As Handle)
Dim groupid as Integer
Dim ObjectsInGroup As List(Of Handle) = New List(Of Handle)
Dim sqlSelectObjIds As String = "SELECT ENT_ID FROM ObjectIds"
Dim sqlSelect As String = "SELECT GROUP_ID from Groups"
Dim sqlQryGrp As String = "INSERT INTO Groups (GROUP_ID,Group_name) VALUES (pGroup_id,pGroup_name)"
Dim sqlQryEnt As String = "INSERT INTO EntityParams (Geom_type, CREATED_BY, UPDATED_BY) VALUES (pGeom_type,pCreated,pUpdated)"
Dim sqlQryEntInGroups As String = "INSERT INTO EntitiesInGroups (GROUP_ID, ENT_ID) VALUES (pGroup_id,pEnt_id)"
Dim sqlQryRect As String = "INSERT INTO RectangleParams (ENT_ID, CoordinateX1, CoordinateX2, CoordinateY1, CoordinateY2) VALUES (pENT_ID, pCoordinateX1, pCoordinateX2, pCoordinateY1,pCoordinateY2)"
Dim myconnection As New OleDbConnection(ConnectionString)
Dim cmd As New OleDbCommand(sqlSelect, myconnection)
Using myconnection
myconnection.Open()
Using cmd
Using cmd
cmd.Parameters.AddWithValue("pGroup_name",groupName)
If cmd.ExecuteScalar IsNot Nothing Then
groupId = cmd.ExecuteScalar()
End If
End Using
End Using
cmd.CommandText = sqlQryEnt
cmd.Connection = myconnection
Using cmd
cmd.Parameters.AddWithValue("pGeom_type", "Rectangle")
cmd.Parameters.AddWithValue("pCreated", username)
cmd.Parameters.AddWithValue("pUpdated", username)
cmd.ExecuteNonQuery()
cmd.CommandText = "SELECT @@IDENTITY"
EntId = cmd.ExecuteScalar()
End Using
cmd.CommandText = sqlQryRect
cmd.Connection = myconnection
Using cmd
cmd.Parameters.AddWithValue("pENT_ID", EntId)
cmd.Parameters.AddWithValue("pCenterX", rectEnt.LowerLeft)
cmd.ExecuteNonQuery()
End Using
End Using
myconnection.Close()
DictAutoCadIdToDbId.Add(GeomId.Value(), EntId)
ObjectsInGroup.Add(GeomId)
AddToGroup(groupName,GeomId)
RightPal.RefreshTree()
End SubPline type is Polyline but i need it to Rectangle3d to be able to save all 4 vertex coordinates any suggestions how to convert polyline to rectangle3d or smth
Solved! Go to Solution.