<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: saving rectangle vertex coordinates to access database in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831256#M27018</link>
    <description>&lt;P&gt;yeah i got what u say but problem is that x1, y1,x2,y2 are double but upperleft, upperright, ... are point3d type so literally i cant create rect as Rectangle3d&lt;/P&gt;</description>
    <pubDate>Tue, 06 Mar 2018 14:41:50 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-06T14:41:50Z</dc:date>
    <item>
      <title>saving rectangle vertex coordinates to access database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831032#M27016</link>
      <description>&lt;P&gt;i have method for creating rectangle:&lt;/P&gt;&lt;PRE&gt;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 &amp;amp; "First corner: ")
            If ppr.Status &amp;lt;&amp;gt; PromptStatus.OK Then Return
            Dim pt1 = ppr.Value
            ppr = ed.GetCorner(vbLf &amp;amp; "Opposite corner: ", pt1)
            If ppr.Status &amp;lt;&amp;gt; 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&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;and have uncompleted method to save coordinates of rectangle(upperleft, upperright, lowerleft, lowerright) to Database.&lt;/P&gt;&lt;PRE&gt;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 Sub&lt;/PRE&gt;&lt;P&gt;Pline 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&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 13:36:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831032#M27016</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-06T13:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: saving rectangle vertex coordinates to access database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831177#M27017</link>
      <description>&lt;P&gt;If you look at Rectangle3d class' Contructor, it has 4 rectagle's corner points as arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your first method PlotRectangle() (it sound strnange to any AutoCAD user for calling the process of adding entity as "Plot"&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;), you are able to get 4 points and draw a rectangle as Polyline. So, you should no problem to simply ccreate a Rectangle3d struct and use it in the other method SaveRectangle().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may slightly change the method signature of PlotRectangle, so it not only draws the rectangle as polyline, but also returns a Rectangle3d struct for the next method to use. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Public Shared Function PlotRectangle() As rectangle3d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;'' Pick 2 points as rectangle's opposite corners&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;'' Define 4 points (uperleft, upperright, lowerleft and lowerright)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Dim rect As Rectangle3d = New rectangle3d(upperleft, upperright, lowerleft, lowerright)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;'' draw polyline in drawing database according to the 4 points&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;'' Finally returns the Rectangle3d struct&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Return rect&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;End Function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in your main process code,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;Dim rect As Rectangle3d = PlotRectangle()&lt;/P&gt;
&lt;P&gt;SaveRectangle(rect, ...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, it is NOT that method SaveRectangle() incomplete, it is the PlotRectangle() should be able to pass/return useful information out for the next operation's convenience&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 14:20:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831177#M27017</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-03-06T14:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: saving rectangle vertex coordinates to access database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831256#M27018</link>
      <description>&lt;P&gt;yeah i got what u say but problem is that x1, y1,x2,y2 are double but upperleft, upperright, ... are point3d type so literally i cant create rect as Rectangle3d&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 14:41:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831256#M27018</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-06T14:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: saving rectangle vertex coordinates to access database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831425#M27019</link>
      <description>&lt;P&gt;While having pt1 and pt2, you can build an Extens3d instance which have a MinPoint (lower left) and MaxPoint (upper right) properties to help you creation your instance of Rectangle3d.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var extents = new Extents3d();
extents.AddPoint(pt1);
extents.AddPoint(pt2);
var minX = extents.MinPoint.X;
var minY = extents.MinPoint.Y;
var maxX = extents.MaxPoint.X;
var maxY = extents.MaxPoint.Y;
var z = pt1.Z;
var rectangle =  new Rectangle3d(
	new Point3d(minX, maxY, z),
	new Point3d(maxX, maxY, z),
	new Point3d(minX, minY, z),
	new Point3d(maxX, minY, z));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind pt1 and pt2 are defined in the current coordinate system which may be different from WCS.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 15:24:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-rectangle-vertex-coordinates-to-access-database/m-p/7831425#M27019</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-03-06T15:24:24Z</dc:date>
    </item>
  </channel>
</rss>

