Private Sub CommandButton1_Click()
I've found TC can crash if you use Unload Me
Me.Hide
In fact I'm abit wary to free any objects because I'm not 100% on the teardown
process. I would have thought even if I had freed an object
from the memory and then TC tried to do it then TC would exit gracefully?????
End Sub
Private Function checkforblock(name As String) As Boolean
see if the block already exist in the block collection
Dim b As Block
For Each b In ActiveDrawing.Blocks
If b.name = name Then
checkforblock = True
Exit Function
End If
Next b
checkforblock = False
End Function
Private Sub MakeTestBlock()
make a Standalone graphic
Dim g As New Graphic
g.Graphics.AddLineSingle -1, 0, 0, 1, 0, 0
g.Graphics.AddLineSingle 1, 0, 0, 1, 10, 0
g.Graphics.AddLineSingle 1, 10, 0, 3, 10, 0
g.Graphics.AddLineSingle 3, 10, 0, 0, 20, 0
g.Graphics.AddLineSingle 0, 20, 0, -3, 10, 0
g.Graphics.AddLineSingle -3, 10, 0, -1, 10, 0
g.Graphics.AddLineSingle -1, 10, 0, -1, 0, 0
This has to be inserted for some reason???
ActiveDrawing.Graphics.AddGraphic g
Dim i As New Vertex
the insertion vertex
i.x = 0
i.Y = 0
i.Z = 0
turn the graphic into a block
Dim b As Block
Set b = ActiveDrawing.Blocks.Add("test", g)
b.Anchor = i
remove the unwanted graphic it from the drawing
g.Delete
End Sub
Private Sub CommandButton2_Click()
This is the main code for calculating and drawing Mohr's Circle
First check if my arrow block exits
If checkforblock("test") = False Then MakeTestBlock
FOrce into ModelSpace
ForceModalSpace
Dim rad As Double
Dim x1 As Double
Dim y1 As Double
Dim x2 As Double
Dim y2 As Double
Dim dx As Double
Dim dy As Double
x1 = CDbl(TextBox1.Text) Sigmax
y1 = CDbl(TextBox3.Text) tauxy
x2 = CDbl(TextBox2.Text) Sigmay
y2 = -1 * y1 Tauyx
dx = (x2 - x1)
dy = (y2 - y1)
rad = Sqr(dx ^ 2 + dy ^ 2) * 0.5
Ang = Atn(dy / dx) < Sigma2 round to the greater of the normal stresses
ActiveDrawing.Graphics.AddCross x1, y1, 0 sigmax,tauxy
ActiveDrawing.Graphics.AddCross x2, y2, 0 sigmay,tauyx top of intial element
Dim l As Graphic
Set l = ActiveDrawing.Graphics.AddLineSingle(x1, y1, 0, x2, y2, 0)
l.Properties("PenColor").Value = RGB(255, 0, 0)
Dim mpx As Double, mpy As Double
mpx = x1 / 2 + x2 / 2
mpy = y1 / 2 + y2 / 2
Dim c As Graphic
Set c = ActiveDrawing.Graphics.AddCircleCenterAndPoint(mpx, mpy, 0, x1, y1, 0)
Dim Sigma1 As Double, sigma2 As Double, tau As Double
Sigma1 = mpx - rad
sigma2 = mpx + rad sigma2 is conventially the largest
tau = rad
Apply the text summary
ActiveDrawing.Graphics.AddText "Compound Stress Mohr's Circle", -1.2 * rad, 2.6 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "SigmaX = " & TextBox1.Text, -1.2 * rad, 2.2 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "SigmaY = " & TextBox2.Text, -1.2 * rad, 2# * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Tau = " & TextBox3.Text, -1.2 * rad, 1.8 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Sigma1 = " & CStr(Sigma1), -1.2 * rad, 1.6 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Sigma2 = " & CStr(sigma2), -1.2 * rad, 1.4 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Tau Max = " & CStr(tau), -1.2 * rad, 1.2 * rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Angle = " & CStr(Ang), -1.2 * rad, rad, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Ang1 = " & CStr(Ang * 0.5), -1.2 * rad, 0.8 * rad, 0, rad * 0.1
Draw in the Axes
ActiveDrawing.Graphics.AddLineSingle Sigma1 - 1.2 * rad, 0, 0, sigma2 + 1.2 * rad, 0, 0
ActiveDrawing.Graphics.AddLineSingle 0, -1.2 * rad, 0, 0, 1.2 * rad, 0
ActiveDrawing.Graphics.AddText "0,0", 0.2, rad * 0.1, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Tensile stress", sigma2 + 0.1 * rad, rad * 0.1, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Compressive stress", -1.2 * rad, rad * 0.1, 0, rad * 0.1
ActiveDrawing.Graphics.AddText "Shear stress", -rad * 0.1, rad, 0, rad * 0.1, 1.5708
Draw the intial element
DrawStessedElement -2 * rad - 2 * sigma2, 0, rad, 0, "Sigma y", "Sigma x", True
Draw the prinipal axes
If x1 > x2 Then
DrawStessedElement 2 * rad + 2 * sigma2, 0, rad, Ang * 0.5, "Sigma 1", "Sigma 2", False
Else
DrawStessedElement 2 * rad + 2 * sigma2, 0, rad, Ang * 0.5, "Sigma 2", "Sigma 1", False
End If
End Sub
Private Sub DrawStessedElement(cenx As Double, ceny As Double, size As Double, Ang As Double, Sigma1 As String, sigma2 As String, shearforces As Boolean)
draw on the normal stresses and shearstresses
I really should reverse arrow directions for compression a negative shear direction
Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
Dim r As Graphic
x1 = -0.5 * size
y1 = -0.5 * size
x2 = 0.5 * size
y2 = 0.5 * size
put in the rectang element
Set r = ActiveDrawing.Graphics.AddLineRectangle(x1, y1, 0, x2, y2, 0)
r.MoveAbsolute cenx, ceny, 0
r.RotateAxis Ang
draw the first arrow'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim a As Graphic
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", 0, y2, 0, 0.2, 0.5, , 0)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
apply sigma1 text
Dim t As Graphic
Set t = ActiveDrawing.Graphics.AddText(Sigma1, 0, y2 + 15, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
draw the second arrow'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", 0, y1, 0, 0.2, 0.5, , PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set t = ActiveDrawing.Graphics.AddText(Sigma1, 0, y1 - 15, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
draw the 3rd arrow'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x1, 0, 0, 0.2, 0.5, , 0.5 * PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set t = ActiveDrawing.Graphics.AddText(sigma2, x1 - 15, 0, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
draw the fourth arrow'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x2, 0, 0, 0.2, 0.5, , -0.5 * PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set t = ActiveDrawing.Graphics.AddText(sigma2, x2 + 15, 0, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
apply the shear arrows
If shearforces = False Then Exit Sub
Draw the shearforce Arrows
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x2 - 3, y2 + 0.5, 0, 0.05, 0.15, , -0.5 * PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", y2 + 0.5, y2 - 3, 0, 0.05, 0.15, , 0)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x1 + 3, y1 - 0.5, 0, 0.05, 0.15, , 0.5 * PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", y1 - 0.5, y1 + 3, 0, 0.05, 0.15, , PI)
a.RotateAxis Ang, , , , 0, 0, 0
a.MoveRelative cenx, ceny, 0
Set t = ActiveDrawing.Graphics.AddText("Tau", x2 + size / 3, y2 + size / 3, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
Set t = ActiveDrawing.Graphics.AddText("Tau", x1 - size / 3, y1 - size / 3, 0, size / 3, 0)
t.RotateAxis Ang, , , , 0, 0, 0
t.MoveRelative cenx, ceny, 0
End Sub
Private Sub DrawPrincipalElement(cenx As Double, ceny As Double, size As Double, Ang As Double)
Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
Dim r As Graphic
x1 = -0.5 * size
y1 = -0.5 * size
x2 = 0.5 * size
y2 = 0.5 * size
Set r = ActiveDrawing.Graphics.AddLineRectangle(x1, y1, 0, x2, y2, 0)
r.RotateAxis Ang
r.MoveAbsolute cenx, ceny, 0
End Sub
Private Sub ForceModalSpace()
Dim MSpace As Long
MSpace = ActiveDrawing.Properties("TileMode")
If MSpace <> 1 Then
ActiveDrawing.Properties("TileMode").Value = 1
End If
End Sub