Parallelogram shape

Parallelogram shape

Anonymous
Not applicable
1,889 Views
10 Replies
Message 1 of 11

Parallelogram shape

Anonymous
Not applicable

Hi all 

I would like to do this shape with VBA, basically  a straight bottom line two legs with  angles and the top line will just be the close line 

Any help will be very much appreciated 

cTRLS9_0-1589711355786.png

 

 

0 Likes
1,890 Views
10 Replies
Replies (10)
Message 2 of 11

grobnik
Collaborator
Collaborator

Hi Chris, @Anonymous ,

seems you are building a space shuttle,

concerning you last request, I have just a question, line angle and points distances will be always the same ? or could  change or are coming from a user form ?.

I guess you can Joke with polyline, and geometry formula, however I'll try to help you after your confirmation.

0 Likes
Message 3 of 11

Anonymous
Not applicable

Hi Thanks and that last one is working fine.

with this shape the left and right legs are any length & angle the base any length the top finished with the close line

 

Regards Chris

0 Likes
Message 4 of 11

Anonymous
Not applicable

Hi Sorry 

Forgot to say sizes will be from user form input (textboxes)

0 Likes
Message 5 of 11

grobnik
Collaborator
Collaborator

Hi Chris, ok, thank you, but just another question...

which is the difference from last solution I gave you ? it's always a polyline with several vertex, that you input in a form, the same the polyline it's closed, if you want to fix the DY based upon the angle it's simple geometry formula nothing related to VBA or Autocad.

Probably something is missing on my evaluation of you issue.

Thank you

0 Likes
Message 6 of 11

Anonymous
Not applicable

Hi yes it is very similar I just want to enter a angle in the text box for the 2 legs, I think but not sure it would need polar point for angle? (Can a polyline have an angle?)

0 Likes
Message 7 of 11

Anonymous
Not applicable

cTRLS9_0-1589726295779.png

 

0 Likes
Message 8 of 11

grobnik
Collaborator
Collaborator

Hi Chris, @Anonymous 

In my opinion it's only a trigonometrical issue, I'll try to explain see picture below

grobnik_0-1589743590440.png

We can associate the left part of your parallelogram to a right-angled triangle.

So we have the hypothetical leg length that can be used with own angle to calculate the length of hypotenuse by 

leg length/SIN(ANGLE LEG 1), OBTAINING THE X value of first part of poly-line, the Y value will be the base point Y value subtracted of leg 1 length. The same could be applied to LEG 2.

Look on web about trigonometry of right-angled triangle.

I hope this should work, even if I'm not so fresh on trigonometry rules.

Bye

 

 

 

0 Likes
Message 9 of 11

Anonymous
Not applicable

Hi

Just to clarify these angles are taken from A staircase, so the actual angles and measurements are know, its just a matter of drawing them on autocad through vba  hope this is clearer.

 

So first leg Left   (length,angle) Base or bottom (Base length) Right leg (Length,angle) and then close

 

 

0 Likes
Message 10 of 11

grobnik
Collaborator
Collaborator

Hi Chris, @Anonymous 

My answer seems stupid but was focused to find the vertex of polyline in order create the parallelogram as you required, the giving data of height of left arm or right arm cannot give you the length of line from insertions point you selected and second point (hypothetical hipotenuse of the right triangle) , and from third to fourth (after the base length).

If you already have all dimensions and data just pick a point on drawing and pass the vertex coordinates to a polyline as you already done, then ask to close the polyline.

I'm sorry but I'm not so expert with civil works and geometrical data, so my mind probably could not understand the issue, that in my opinion still concern geometrical issue and not Autocad VBA issue.

Bye

0 Likes
Message 11 of 11

parikhnidi
Advocate
Advocate

Sorry for replying so late but here is the another way to address the problem. I have created a class module where all functionality are wrapped.

In VBA IDE go to Insert and then select Class Module. In that module write the following code. I have given name to that class module as clsmyParallogram.

Option Explicit

Private pi As Double

Private mLeg1Height As Double
Private mLeg1Angle As Double
Private mLeg2Height As Double
Private mLeg2Angle As Double
Private mBaseLength As Double

Private mLocation As Variant

'================
Public Property Let Leg1Height(pLeg1Height As Double)
    mLeg1Height = pLeg1Height
End Property
'================
Public Property Get Leg1Height() As Double
    Leg1Height = mLeg1Height
End Property
'================
Public Property Let Leg1Angle(pLeg1Angle As Double)
    mLeg1Angle = pLeg1Angle
End Property
'================
Public Property Get Leg1Angle() As Double
    Leg1Angle = mLeg1Angle
End Property
'================
Public Property Let Leg2Height(pLeg2Height As Double)
    mLeg2Height = pLeg2Height
End Property
'================
Public Property Get Leg2Height() As Double
    Leg2Height = mLeg2Height
End Property
'================
Public Property Let Leg2Angle(pLeg2Angle As Double)
    mLeg2Angle = pLeg2Angle
End Property
'================
Public Property Get Leg2Angle() As Double
    Leg2Angle = mLeg2Angle
End Property
'================
Public Property Let BaseLength(pBaseLength As Double)
    mBaseLength = pBaseLength
End Property
'================
Public Property Get BaseLength() As Double
    BaseLength = mBaseLength
End Property
'================
Public Property Let Location(pLocation As Variant)
    mLocation = pLocation
End Property
'================
Public Property Get Location() As Variant
    Location = mLocation
End Property
'================
Public Sub Draw()
    Dim point(0 To 11) As Double
    Dim tempPoint As Variant
    Dim polyObj As AcadPolyline
    
    point(0) = mLocation(0)
    point(1) = mLocation(1)
    point(2) = 0
    
    With ThisDrawing.Utility
        tempPoint = .PolarPoint(mLocation, mLeg1Angle + pi, mLeg1Height / Sin(mLeg1Angle))
        point(3) = tempPoint(0)
        point(4) = tempPoint(1)
        point(5) = 0
        
        tempPoint = .PolarPoint(tempPoint, 0, mBaseLength)
        point(6) = tempPoint(0)
        point(7) = tempPoint(1)
        point(8) = 0
        
        tempPoint = .PolarPoint(tempPoint, mLeg2Angle, mLeg2Height / Sin(mLeg2Angle))
        point(9) = tempPoint(0)
        point(10) = tempPoint(1)
        point(11) = 0
        
    End With
    Set polyObj = ThisDrawing.ModelSpace.AddPolyline(point)
    polyObj.Closed = True
    polyObj.Update
    
    Set polyObj = Nothing
End Sub

Private Sub Class_Initialize()
    pi = 4 * Atn(1)
End Sub

 In the Draw button click event write the following code -

Option Explicit
Private Sub cmdDraw_Click()
    Dim pi As Double
    Dim parallogram As clsmyParallogram
    Set parallogram = New clsmyParallogram
    
    Dim loc(0 To 2) As Double
    
    'loc is initialized for the program tesing purpose only
    loc(0) = 3000
    loc(1) = 6000
    loc(2) = 0
    
    pi = 4 * Atn(1)
    
    With parallogram
        'Replace 5000 with the Val(applicable textbox)
        .Leg1Height = 5000
        'Replace 35 with the Val(applicable textbox)
        .Leg1Angle = 35 * pi / 180 
        'Replace 3000 with the Val(applicable textbox)
        .Leg2Height = 3000
        'Replace 45 with the Val(applicable textbox)
        .Leg2Angle = 45 * pi / 180
        'Replace 6000 with the Val(applicable textbox)
        .BaseLength = 6000
        'Replace loc with ThisDrawing.Utility.GetPoint(,"Select Reference Point: ")
        .Location = loc
        .Draw
    End With
    
    Set parallogram = Nothing
End Sub

 

Please note that, the angles in the text boxes are in degrees and are converted to radians outside the class module.

 

Hope this helps.

Nimish

0 Likes