Draw three point rectangle

Draw three point rectangle

angelinabrown0123
Advocate Advocate
1,375 Views
8 Replies
Message 1 of 9

Draw three point rectangle

angelinabrown0123
Advocate
Advocate

Please Help!

I have made code to draw rectangle but i don't know how to find imaginary(fourth) point,if any one request this expert help me to complete it.

Option Explicit

Sub DrawThreePointRectange()

  Dim SectionCoord(0 To 9) As Double
  Dim Topbar As Integer
  Dim BottomBar As Integer
  Dim Cover As Integer
  Dim Rectang As Object
  Dim ActDoc As Object
  Dim InsertP(2) As Double
  Dim CirObj As Object
  Dim i As Long

  Dim PickFirstPoint As Variant
  Dim PickSecondPoint As Variant
  Dim PickThirdPoint As Variant
  Dim PickForthPoint(0 To 2) As Double

     PickFirstPoint = ThisDrawing.Utility.GetPoint(, "Pick First Point")
     ReDim Preserve PickFirstPoint(0 To 1)
     PickSecondPoint = ThisDrawing.Utility.GetPoint(, "Pick Second Point")
     ReDim Preserve PickSecondPoint(0 To 1)
     PickThirdPoint = ThisDrawing.Utility.GetPoint(, "Pick Third Point")
     ReDim Preserve PickThirdPoint(0 To 1)

     SectionCoord(0) = PickFirstPoint(0): SectionCoord(1) = PickFirstPoint(1)
     SectionCoord(2) = PickSecondPoint(0): SectionCoord(3) = PickSecondPoint(1)
     SectionCoord(4) = PickThirdPoint(0): SectionCoord(5) = PickThirdPoint(1)
     SectionCoord(6) = PickFirstPoint(0): SectionCoord(7) = PickSecondPoint(1) '????????
     SectionCoord(8) = PickFirstPoint(0): SectionCoord(9) = PickFirstPoint(1)
     
  Set Rectang = ThisDrawing.ModelSpace.AddLightWeightPolyline(SectionCoord)
        
ZoomExtents

Set Rectang = Nothing
End Sub

 

0 Likes
Accepted solutions (3)
1,376 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

Only two points are sufficient to draw a rectangle. However, that is done orthogonally on the current xy plane. Specifying rotation can draw a rectangle in any orientation. Do you know about the Rotation option of the RECTANGLE command? You choose the first corner, then right-click and choose the Rotation option, specifying an angle. Then pick the second corner.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 9

angelinabrown0123
Advocate
Advocate

It is true that rectangles can be made from two points, but it will only make Delta X and Delta Y Rectangel in this straight line but I have to make cross rectangle just like that.

http://www.lee-mac.com/3pointrectangle.html

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

Did you try my suggestion? It works slightly different than Lee's, but the result is the same.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

angelinabrown0123
Advocate
Advocate

In your suggestion, some commands will increase too much, rotate the rectangle by referencing, I do not want it, while it can be simpler.

0 Likes
Message 6 of 9

grobnik
Collaborator
Collaborator

Hi @angelinabrown0123 ,

I don't understand very well your issue.

I guess you already know that the GetPoint function, allows you to define a base point, so after the First Point return coordinates you can use the previous one as base point:

PickFirstPoint = ThisDrawing.Utility.GetPoint(, "Pick First Point")
PickSecondPoint = ThisDrawing.Utility.GetPoint(PickFirstPoint , "Pick Second Point")
PickThirdPoint = ThisDrawing.Utility.GetPoint(PickSecondPoint , "Pick Third Point")
PickFourthPoint = ThisDrawing.Utility.GetPoint(PickThirdPoint , "Pick Fourth Point")

I don't understand why you are using redim, while GetPoint, on special way you will use the BasePoint into GetPoint function, needs 3 points coordinates.

 

0 Likes
Message 7 of 9

angelinabrown0123
Advocate
Advocate
Accepted solution

If we pick the fourth point manually, then the opposite point will not get the same distance, whereas if the fourth point can be found in some way, then the distance of the opposite point will be the same. I have attached an image as an example.
And speaking of "ReDim Preserve", I'll use it as a convenience the next time when I need the third point.
Test.jpg

 

 

0 Likes
Message 8 of 9

MakCADD
Advocate
Advocate
Accepted solution

better consider the third pick is only to define the height of the rectangle.

then you recalculate the third and fourth using height and angle

you can use anglefromxaxis and polarpoint functions

0 Likes
Message 9 of 9

Mesut_Akcan
Collaborator
Collaborator
Accepted solution

Draw three point rectangle: https://youtu.be/0Thfs7mjGf8

This video language is Turkish, but you can set the subtitle language to English.

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn