Você está na página 1de 7

'This module consist of only code to create charts

Option Explicit
Option Base 1
Sub PlotGeometry()
On Error Resume Next
Dim Cx1, Cx2, Cy1, Cy2
ReDim mxVal(NM) As Variant
ReDim myVal(NM) As Variant
ReDim tagxVal(NM) As Variant
ReDim tagyVal(NM) As Variant
Dim am As Integer
'member coordinates
For i = 1 To NM
With Member(i)
Cx1 = Joint(.J1).x
Cy1 = Joint(.J1).y
Cx2 = Joint(.J2).x
Cy2 = Joint(.J2).y
End With
mxVal(i) = Array(Cx1, Cx2)
myVal(i) = Array(Cy1, Cy2)
tagxVal(i) = Array((Cx1 + Cx2) / 2)
tagyVal(i) = Array((Cy1 + Cy2) / 2)
Next i
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
Selection.ClearContents
'creating joints
For i = 1 To NJ
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = Joint(i).x
.SeriesCollection(i).Values = Joint(i).y
.SeriesCollection(i).Name = "J" & i
End With
'node marker
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = 3 'red
.MarkerForegroundColorIndex = 3
.MarkerStyle = xlCircle
.MarkerSize = 6
.Shadow = False

End With
ActiveChart.SeriesCollection(i).DataLabels.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Position = xlLabelPositionRight
.Orientation = xlHorizontal
End With
ActiveChart.SeriesCollection(i).DataLabels.Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 8
End With
Next i
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
n = NJ + NM
am = 1
'creating member lines
For i = NJ + 1 To n
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = mxVal(am)
.SeriesCollection(i).Values = myVal(am)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
.ColorIndex = 5
.Weight = xlThin
.LineStyle = xlContinuous
End With
am = am + 1
Next i
'creating member name tags
am = 1
For i = n + 1 To n + NM
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = tagxVal(am)
.SeriesCollection(i).Values = tagyVal(am)
.SeriesCollection(i).Name = "M" & am
End With
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = 5
.MarkerForegroundColorIndex = 5
.MarkerStyle = xlSquare
.Smooth = False
.MarkerSize = 6
.Shadow = False

End With
ActiveChart.SeriesCollection(i).DataLabels.Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 8
End With
am = am + 1
Next i
ActiveChart.ChartArea.Select
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"NJ = " & Format(NJ, "0") & ", NM = " & Format(NM, "0")
End With
ActiveChart.ShowWindow = True
End Sub
Sub PlotDisplacement()
On Error Resume Next
Dim Cx1, Cx2, Cy1, Cy2
ReDim mxValbf(NM) As Variant, myValbf(NM) As Variant
ReDim mxValaf(NM) As Variant, myValaf(NM) As Variant
Dim am As Integer, scx As Single
Dim Xmax As Double, at_joint As Integer
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
Selection.ClearContents
'======================
'scale for displacement
'======================
'user scale: max displacement are drawn up to 10% of the axis range
'or follows formula: X-range or Y-range * 10% = Xmax
'determine max. joint-X and Y displacement
'(user function UXMax written at the end of this module):
Xmax = Application.index(UXMax(Xs, NP), 1)
at_joint = Application.index(UXMax(Xs, NP), 2)
scx = (Application.Max(XAx_Wd, YAx_Wd) * 10 / 100) / Abs(Xmax)
'member coordinates: before & after loading
For i = 1 To NM
With Member(i)
Cx1 = Joint(.J1).x
Cy1 = Joint(.J1).y
Cx2 = Joint(.J2).x
Cy2 = Joint(.J2).y
mxValbf(i) = Array(Cx1, Cx2)
myValbf(i) = Array(Cy1, Cy2)
Cx1 = Joint(.J1).x + scx * Xs(2 * .J1 - 1)
Cy1 = Joint(.J1).y + scx * Xs(2 * .J1)
Cx2 = Joint(.J2).x + scx * Xs(2 * .J2 - 1)
Cy2 = Joint(.J2).y + scx * Xs(2 * .J2)
mxValaf(i) = Array(Cx1, Cx2)
myValaf(i) = Array(Cy1, Cy2)
End With
Next i
am = 1
'creating member lines: before loading
For i = 1 To NM
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = mxValbf(am)
.SeriesCollection(i).Values = myValbf(am)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
.ColorIndex = 5
.Weight = xlThin
.LineStyle = xlContinuous
End With
am = am + 1
Next i
n = NM + NM
am = 1
'creating member lines: after loading
For i = NM + 1 To n
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = mxValaf(am)
.SeriesCollection(i).Values = myValaf(am)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
.ColorIndex = 7
.Weight = xlMedium
.LineStyle = xlContinuous
End With
am = am + 1
Next i
ActiveChart.ChartArea.Select
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"Max Displacement, J." & at_joint & " = " & Format(Xmax, "0.00000")
End With
End Sub
Sub PlotAxial()
On Error Resume Next
Dim Cx1, Cx2, Cy1, Cy2
Dim Cmx1, Cmx2, Cmy1, Cmy2
ReDim mxVal(NM) As Variant
ReDim myVal(NM) As Variant
ReDim saxVal(NM) As Variant
ReDim sayVal(NM) As Variant
ReDim tagxVal(NM) As Variant
ReDim tagyVal(NM) As Variant
ReDim mjxVal(NM + NM) As Variant
ReDim mjyVal(NM + NM) As Variant
ReDim acolor(NM + NM) As Variant
ReDim Pa_LM(2, NM) As Double
ReDim Pa_RM(2, NM) As Double
ReDim Pa_LT(2, NM) As Double
ReDim Pa_RT(2, NM) As Double
Dim am As Integer, sca As Single
Dim Amax As Double, at_member As Integer, L_I As Integer, L_II As Integer
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
Selection.ClearContents
'analogous to plot displacement for scaling
Amax = Application.index(UAMax(Pmm, Fm, NM), 1)
at_member = Application.index(UAMax(Pmm, Fm, NM), 2)
sca = (Application.Max(XAx_Wd, YAx_Wd) * 10 / 100) / Abs(Amax)
For i = 1 To NM
Pa_LM(2, i) = -(Pmm(Idm(1, i), i) + Fm(1, i))
Pa_RM(2, i) = (Pmm(Idm(3, i), i) + Fm(3, i))
Next i
'transform member axial to global axis by using [TT]
'the drawing should be in global coordinates
For i = 1 To NM
For j = 1 To 2
For n = 1 To 2
Pa_LT(j, i) = Pa_LT(j, i) + TT(j, n, i) * Pa_LM(n, i)
Pa_RT(j, i) = Pa_RT(j, i) + TT(j, n, i) * Pa_RM(n, i)
Next n
Next j
Next i
For i = 1 To NM
With Member(i)
Cx1 = Joint(.J1).x
Cy1 = Joint(.J1).y
Cx2 = Joint(.J2).x
Cy2 = Joint(.J2).y
'assign force coordinates
Cmx1 = Cx1 + sca * Pa_LT(1, i)
Cmy1 = Cy1 + sca * Pa_LT(2, i)
Cmx2 = Cx2 + sca * Pa_RT(1, i)
Cmy2 = Cy2 + sca * Pa_RT(2, i)
End With
'member coordinates
mxVal(i) = Array(Cx1, Cx2)
myVal(i) = Array(Cy1, Cy2)
'axial coordinates
saxVal(i) = Array(Cmx1, Cmx2)
sayVal(i) = Array(Cmy1, Cmy2)
'member-joint coordinates
mjxVal(2 * i - 1) = Array(Cx1, Cmx1)
mjyVal(2 * i - 1) = Array(Cy1, Cmy1)
'mcolor: define color for positive/negative value
acolor(2 * i - 1) = -(Pmm(Idm(1, i), i) + Fm(1, i))
mjxVal(2 * i) = Array(Cx2, Cmx2)
mjyVal(2 * i) = Array(Cy2, Cmy2)
acolor(2 * i) = Pmm(Idm(3, i), i) + Fm(3, i)
Next i
'creating member lines
For i = 1 To NM
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = mxVal(i)
.SeriesCollection(i).Values = myVal(i)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
.ColorIndex = 5
.Weight = xlThin
.LineStyle = xlContinuous
End With
Next i
L_I = NM + NM
am = 1
'creating axial lines
For i = NM + 1 To L_I
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = saxVal(am)
.SeriesCollection(i).Values = sayVal(am)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
.ColorIndex = 7
.Weight = xlThin
.LineStyle = xlContinuous
End With
am = am + 1
Next i
L_II = NM + NM + NM + NM
am = 1
'creating joint lines to axis
For i = L_I + 1 To L_II
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = mjxVal(am)
.SeriesCollection(i).Values = mjyVal(am)
.SeriesCollection(i).Name = "="""""
End With
ActiveChart.SeriesCollection(i).Select
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
End With
With Selection.Border
If acolor(am) < 0 Then
.ColorIndex = 3
Else
.ColorIndex = 5
End If
.Weight = xlMedium
.LineStyle = xlContinuous
End With
am = am + 1
Next i
ActiveChart.ChartArea.Select
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"Max Axial, M." & at_member & " = " & Format(Amax, "0.000")
End With
End Sub
'user function to determine maximum value of
'joint X1 and X2
Function UXMax(Xs, NP) As Variant
Dim Abs_FXMax As Double
Dim FXMax As Double
ReDim Idis(NP) As Double
'Joint displacement index
n = 1
For i = 2 To NP Step 2
Idis(i - 1) = n
Idis(i) = n
n = n + 1
Next i
Abs_FXMax = 0
n = 0
For i = 1 To NP
If Abs(Xs(i)) > Abs_FXMax Then
Abs_FXMax = Abs(Xs(i))
FXMax = Xs(i)
n = Idis(i)
UXMax = Array(FXMax, n)
'UXMax keeps origin value(+ or - value)
End If
n = n + i
Next i
End Function
'user function to determine maximum value of
'axial force, F1
Function UAMax(Pmm, Fm, NM) As Variant
Dim Abs_FAMax As Double
Dim FAMax As Double
Abs_FAMax = 0
n = 0
For i = 1 To NM
If Abs(Pmm(Idm(1, i), i) + Fm(1, i)) > Abs_FAMax Then
Abs_FAMax = Abs(Pmm(Idm(1, i), i) + Fm(1, i))
FAMax = -(Pmm(Idm(1, i), i) + Fm(1, i))
n = i
UAMax = Array(FAMax, n)
End If
If Abs(Pmm(Idm(3, i), i) + Fm(3, i)) > Abs_FAMax Then
Abs_FAMax = Abs(Pmm(Idm(3, i), i) + Fm(3, i))
FAMax = Pmm(Idm(3, i), i) + Fm(3, i)
n = i
UAMax = Array(FAMax, n)
End If
Next i
End Function

Você também pode gostar