Evolutionary Solver (Simplified)
Código do solver criado (Sub mysolversimplified()), juntamente com:
- a função de cálculo da sustentação (LiftFunction);
- a função que verifica se o AR e o MTOM, assim como os valores máximos das variáveis globais, são respeitados (IsValid);
- a função de geração de populações (GeneratePopulation);
Dim tempmaterial As String
Dim templocation As String
Dim tempstressratio As Double
Dim Reynolds As Double
Dim CL As Double
Dim density As Double
Dim miu As Double
Dim maxchord As Double
Dim maxspan As Double
Dim maxAR As Double
Dim minAR As Double
Dim tempArea As Double
Dim tempAR As Double
Dim liftmin As Double
Dim tempvel As Double
Dim tempminvel As Double
Dim tempMTOM As Double
Dim population() As Variant
Dim populationSize As Integer
Dim stressmain() As Variant
Dim dispmain() As Variant
Dim ratiostresses() As Variant
Public indchordtip As Double
Public indenvergadura As Double
Public indlift As Double
' Define the lift function to optimize
Function LiftFunction(tempenvergadura, tempchordroot, tempchordtip, Reynolds, miu, density, CL) As Double
LiftFunction = (tempenvergadura / 4) * (tempchordroot + tempchordtip) * ((Reynolds * miu) / (density * (tempchordroot + tempchordtip) / 2)) ^ 2 * CL
End Function
' Check if constraints are met
Function IsValid(tempenvergadura, tempchordroot, tempchordtip, Reynolds, miu, density, CL) As Boolean
tempArea = (tempenvergadura / 2) * (tempchordroot + tempchordtip)
tempAR = (tempenvergadura * tempenvergadura) / tempArea
tempvel = (Reynolds * 2 * miu) / (density * (tempchordtip + tempchordroot))
tempminvel = tempvel / 1.9
liftmin = 0.5 * tempArea * tempminvel * tempminvel * CL
tempMTOM = liftmin / 9.8If tempchordroot <= maxchord And tempchordtip <= maxchord And tempenvergadura <= maxspan And tempchordtip <= tempchordroot And tempAR <= maxAR And tempAR >= minAR And tempMOTM <= 9 Then
IsValid = True
Else
IsValid = False
End If
End Function
Sub GeneratePopulation(population() As Variant, populationSize As Integer, maxchord As Double, maxspan As Double, Reynolds As Double, miu As Double, density As Double, CL As Double)
Dim i As Integer
For i = 1 To populationSize
' Generate random values for chord1, chord2, and span within their respective ranges
Do
population(i, 1) = 0 + Rnd * (maxchord - 0) ' chordtip
population(i, 2) = 0 + Rnd * (maxchord - 0) ' chordroot
population(i, 3) = 0 + Rnd * (maxspan - 0) ' span
' Ensure the generated values meet the constraints
Loop Until IsValid(population(i, 3), population(i, 2), population(i, 1), Reynolds, miu, density, CL)
Next i
End Sub
Sub mysolversimplified()
Dim populationSize As Integer
'Dim xMin As Double, xMax As Double
Dim generations As Integer
Dim mutationRate As Double
'Dim population() As Variant
'Dim selected() As Variant
'Dim nextGeneration() As Variant
Dim fitness() As Double
Dim i As Integer, generation As Integer
'Dim parent1(1 To 3) As Double, parent2(1 To 3) As Double, child(1 To 3) As Double
'Dim bestIndividual(1 To 3) As Double
'Dim bestFitness As Double
'Dim numIndividuals As IntegerCL = Range("C6").Value
density = Range("C4").Value
miu = Range("C5").Value
Reynolds = Range("C9").Value
maxchord = Range("J8").Value
maxspan = Range("J7").Value
maxAR = Range("K5").Value
minAR = Range("I5").Value
populationSize = 150
ReDim stressmain(1 To populationSize)
ReDim dispmain(1 To populationSize)
ReDim ratiostresses(1 To populationSize)
ReDim population(1 To populationSize, 1 To 3)
ReDim selected(1 To populationSize \ 2, 1 To 3)
ReDim nextGeneration(1 To populationSize, 1 To 3)
ReDim fitness(1 To populationSize)
GeneratePopulation population(), populationSize, maxchord, maxspan, Reynolds, miu, density, CL
' Print the initial population
Debug.Print "Initial Population:"
For i = 1 To populationSize
Debug.Print "Individual " & i & ": chordtip = " & population(i, 1) & ", chordroot = " & population(i, 2) & ", span = " & population(i, 3)
Next i
Debug.Print " "
Debug.Print " "
Debug.Print " "
Debug.Print " "
' Calculate fitness for each individual
For i = 1 To populationSize
fitness(i) = LiftFunction(population(i, 3), population(i, 2), population(i, 1), Reynolds, miu, density, CL)
indchordroot = population(i, 2)
indchordtip = population(i, 1)
indenvergadura = population(i, 3)
indlift = fitness(i)
Debug.Print "Point" & i
Debug.Print indchordroot
Debug.Print indchordtip
Debug.Print indenvergadura
Debug.Print indlift
Debug.Print " "
Call opensolidworkswithsolver
stressmain(i) = StressArray(3)
ratiostresses(i) = 47.1 / stressmain(i)
Debug.Print "Individual " & i & " stress is " & stressmain(i)
Debug.Print "Individual " & i & " safetyfactor is " & ratiostresses(i)
If ratiostresses(i) < 1.5 Then
fitness(i) = 0
End If
Next i
Dim arr As Variant
ReDim arr(1 To populationSize, 1 To 4)For h = 1 To populationSize
For j = 1 To 4
arr(h, 1) = population(h, 2)
arr(h, 2) = population(h, 1)
arr(h, 3) = population(h, 3)
arr(h, 4) = fitness(h)
Next j
Debug.Print arr(h, 1) & " \\ "; arr(h, 2) & " \\ "; arr(h, 3) & " |||| "; arr(h, 4)
Next h
' Initialize the max value and row
Dim maxVal As Double
Dim maxRow As LongmaxVal = arr(1, 4)
maxRow = 1' Find the row with the largest value in the fourth column
For b = 2 To populationSize
' Start from the second row
If arr(b, 4) > maxVal Then
maxVal = arr(b, 4)
maxRow = b
End If
Next b
Debug.Print maxValDebug.Print maxRowDebug.Print "The best solution is a " & maxVal & " lift obtained with "; arr(maxRow, 1) & " chordroot, "; arr(maxRow, 2) & " chordtip and a span off "; arr(maxRow, 3)
'MsgBox "The best solution is a " & maxVal & " lift obtained with " & arr(b, 1) & " chordroot, " & arr(h, 2) & " chordtip and a span off " & arr(h, 3)
End Sub
Código que, com base nos valores aleatórios das variáveis globais gerados pelo Solver, cria no SolidWorks diferentes modelos meia-asa e aplica simulações sobre as mesmas. Otimizado para ser flexível às possíveis variações das variáveis globais.
ATENÇÃO: desde que as variáveis indchordtip, indenvergadura, indchordroot, indlift e StressArray sejam declaradas globalmente, este código deverá funcionar quando chamado por outros códigos que não aquele que se encontra à esquerda.
ATENÇÃO (2) : para que o código funcione, todavia, é sempre necessário ter, no SolidWorks, uma parte previamente aberta em que esteja ativo o Add-In de Simulação
ATENÇÃO (3): assume-se que o material da asa é E.P.S., um material que não existe na biblioteca pré-definida do SolidWorks. Para que o código funcione, é necessário criar o material em questão ou substituí-lo, e a respetiva pasta onde se encontra, na linha de código apropriada
Dim OSw As SldWorks.SldWorks
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swFeatMgr As SldWorks.FeatureManager
Dim swPlane As SldWorks.RefPlane
Dim instance As ICWResults
Dim swStudy As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swFeature As Object
Dim chordroot As Double
Dim chordtip As Double
Dim lift As Double
Dim x As Double, y As Double, z As Double
Dim envergadura As Double
Dim swSketch As SldWorks.Sketch
Dim partTitle1 As String
Sub opensolidworkswithsolver()
chordroot = indchordroot * 1000
chordtip = indchordtip * 1000
envergadura = indenvergadura
lift = indlift
Set OSw = CreateObject("sldworks.Application")
OSw.Visible = True
' Initialize SolidWorks application and active document
Set swModel = OSw.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2024\templates\Part.prtdot", 0, 0, 0)
Set Part = OSw.ActiveDocpartTitle1 = Part.GetTitle
' Start of the curve with the scale applied (chordroot)
Part.InsertCurveFileBegin
x = 0.001 * chordroot: y = 0 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00095042 * chordroot: y = 0.00001245 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00090089 * chordroot: y = 0.00002398 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00085127 * chordroot: y = 0.00003555 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00080153 * chordroot: y = 0.00004693 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00075163 * chordroot: y = 0.000058 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00070159 * chordroot: y = 0.00006847 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00065139 * chordroot: y = 0.00007809 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00060105 * chordroot: y = 0.00008665 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00055058 * chordroot: y = 0.00009393 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.0005 * chordroot: y = 0.00009974 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00044932 * chordroot: y = 0.00010384 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00039857 * chordroot: y = 0.00010598 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00034778 * chordroot: y = 0.00010587 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.000297 * chordroot: y = 0.00010331 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00024625 * chordroot: y = 0.0000983 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00019558 * chordroot: y = 0.00009066 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00014504 * chordroot: y = 0.0000801 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00009473 * chordroot: y = 0.00006578 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00006973 * chordroot: y = 0.00005667 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00004492 * chordroot: y = 0.0000456 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.0000205 * chordroot: y = 0.00003129 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00000866 * chordroot: y = 0.00002159 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00000418 * chordroot: y = 0.00001634 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00000205 * chordroot: y = 0.00001317 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0 * chordroot: y = 0 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)
boolstatus = Part.InsertCurveFileEnd()
' Início da segunda curva com aplicação da escala (chordroot)
Part.InsertCurveFileBeginx = 0 * chordroot: y = 0 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00000795 * chordroot: y = -0.00001017 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00001082 * chordroot: y = -0.00001214 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00001634 * chordroot: y = -0.00001517 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.0000295 * chordroot: y = -0.00002013 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00005508 * chordroot: y = -0.00002664 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00008027 * chordroot: y = -0.00003123 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00010527 * chordroot: y = -0.00003476 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00015496 * chordroot: y = -0.00003972 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00020442 * chordroot: y = -0.0000429 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00025375 * chordroot: y = -0.0000446 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.000303 * chordroot: y = -0.00004499 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00035222 * chordroot: y = -0.00004407 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00040143 * chordroot: y = -0.00004172 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00045068 * chordroot: y = -0.00003814 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.0005 * chordroot: y = -0.00003356 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00054942 * chordroot: y = -0.00002823 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00059895 * chordroot: y = -0.00002239 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00064861 * chordroot: y = -0.00001629 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00069841 * chordroot: y = -0.00001015 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00074837 * chordroot: y = -0.0000043 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00079847 * chordroot: y = 0.00000083 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00084873 * chordroot: y = 0.00000483 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00089911 * chordroot: y = 0.00000704 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00094958 * chordroot: y = 0.00000651 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.001 * chordroot: y = 0 * chordroot: z = 0 * chordroot
boolstatus = Part.InsertCurveFilePoint(x, y, z)
boolstatus = Part.InsertCurveFileEnd()
' Named view and zoom to fit
Part.ShowNamedView2 "*Trimetric", 8
Part.ViewZoomtofit2
' Create a new sketch on the Front Plane
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
' Convert each curve to a sketch entity
boolstatus = Part.Extension.SelectByID2("Curve1", "REFERENCECURVES", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Curve2", "REFERENCECURVES", 0, 0, 0, True, 0, Nothing, 0)
Part.SketchManager.SketchUseEdge3 False, False ' Convert curves to sketch entities
' Exit sketch
Part.SketchManager.InsertSketch False
' Start of the curve with the scale applied (chordtip)
Part.InsertCurveFileBegin
x = 0.001 * chordtip: y = 0 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00095042 * chordtip: y = 0.00001245 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00090089 * chordtip: y = 0.00002398 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00085127 * chordtip: y = 0.00003555 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00080153 * chordtip: y = 0.00004693 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00075163 * chordtip: y = 0.000058 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00070159 * chordtip: y = 0.00006847 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00065139 * chordtip: y = 0.00007809 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00060105 * chordtip: y = 0.00008665 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00055058 * chordtip: y = 0.00009393 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.0005 * chordtip: y = 0.00009974 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00044932 * chordtip: y = 0.00010384 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00039857 * chordtip: y = 0.00010598 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00034778 * chordtip: y = 0.00010587 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.000297 * chordtip: y = 0.00010331 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00024625 * chordtip: y = 0.0000983 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00019558 * chordtip: y = 0.00009066 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00014504 * chordtip: y = 0.0000801 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00009473 * chordtip: y = 0.00006578 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00006973 * chordtip: y = 0.00005667 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00004492 * chordtip: y = 0.0000456 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.0000205 * chordtip: y = 0.00003129 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00000866 * chordtip: y = 0.00002159 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00000418 * chordtip: y = 0.00001634 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00000205 * chordtip: y = 0.00001317 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0 * chordtip: y = 0 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
boolstatus = Part.InsertCurveFileEnd()Part.InsertCurveFileBegin
x = 0 * chordtip: y = 0 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00000795 * chordtip: y = -0.00001017 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00001082 * chordtip: y = -0.00001214 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00001634 * chordtip: y = -0.00001517 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.0000295 * chordtip: y = -0.00002013 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00005508 * chordtip: y = -0.00002664 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)x = 0.00008027 * chordtip: y = -0.00003123 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00010527 * chordtip: y = -0.00003476 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00015496 * chordtip: y = -0.00003972 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00020442 * chordtip: y = -0.0000429 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00025375 * chordtip: y = -0.0000446 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.000303 * chordtip: y = -0.00004499 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00035222 * chordtip: y = -0.00004407 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00040143 * chordtip: y = -0.00004172 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00045068 * chordtip: y = -0.00003814 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.0005 * chordtip: y = -0.00003356 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00054942 * chordtip: y = -0.00002823 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00059895 * chordtip: y = -0.00002239 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00064861 * chordtip: y = -0.00001629 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00069841 * chordtip: y = -0.00001015 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00074837 * chordtip: y = -0.0000043 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00079847 * chordtip: y = 0.00000083 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00084873 * chordtip: y = 0.00000483 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00089911 * chordtip: y = 0.00000704 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.00094958 * chordtip: y = 0.00000651 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
x = 0.001 * chordtip: y = 0 * chordtip: z = envergadura * 0.5
boolstatus = Part.InsertCurveFilePoint(x, y, z)
boolstatus = Part.InsertCurveFileEnd()
Set swFeatMgr = swModel.FeatureManager
' Create the second plane offset from Front Plane
boolstatus = swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Set swPlane = swFeatMgr.InsertRefPlane(8, envergadura * 0.5, 0, 0, 0, 0)
' Create offset plane 1
' Select the new plane
boolstatus = Part.Extension.SelectByID2(swPlane.Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
' create a sketch on the selected plane
Part.SketchManager.InsertSketch True
' Convert each curve to a sketch entity
boolstatus = Part.Extension.SelectByID2("Curve3", "REFERENCECURVES", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Curve4", "REFERENCECURVES", 0, 0, 0, True, 0, Nothing, 0)
Part.SketchManager.SketchUseEdge3 False, False
' Convert curves to sketch entities
' Exit sketch
Part.SketchManager.InsertSketch False
' Create the loft
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 3, True, 1, Nothing, 0)
Part.FeatureManager.InsertProtrusionBlend False, True, False, 1, 0, 0, 1, 1, True, True, False, 0, 0, 0, True, True, Trueboolstatus = Part.Extension.SelectByID2("PLANE1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
' Create a new sketch
Part.SketchManager.InsertSketch True
' Draw a vertical line starting from the origin
Set myLine = Part.SketchManager.CreateLine(0, 0, 0, 0, 0.02, 0)
Part.SketchManager.InsertSketch
Falseboolstatus = Part.Extension.SelectByID2("Line1@Sketch3", "EXTSKETCHSEGMENT", 0, 1.11584498587677E-02, 0, True, 0, Nothing, 0)
boolstatus = Part.InsertAxis2(True)
boolstatus = Part.Extension.SelectByID2("Sketch3", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.BlankSketch
' Initialize Simulation Add-in
Dim COSMOSWORKSObj As Object
Dim CWAddinCallBackObj As Object
'Necessary to already have a part open with the simulation add-in active!!
Set CWAddinCallBackObj = OSw.GetAddInObject("SldWorks.Simulation")
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKSDim motionStudyMgr As Object
Set motionStudyMgr = Part.Extension.GetMotionStudyManager()
Dim ActiveDocObj As Object
Dim StudyManagerObj As Object
Dim LoadsAndRestraintsManagerObj As Object
Dim ErrorCodeObj As Long
Dim ContactManagerObj As Object
Set ActiveDocObj = COSMOSWORKSObj.ActiveDoc()
Set StudyManagerObj = ActiveDocObj.StudyManager()
StudyManagerObj.ActiveStudy = 0
Dim NewStudyName As String
NewStudyName = "Static 1"
Dim CWNewStudy As Object
Set CWNewStudy = StudyManagerObj.CreateNewStudy3(NewStudyName, 0, 0, ErrorCodeObj)
boolstatus = Part.Extension.SelectByID2("Loft1", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
Dim StudyObj As Object
Set StudyObj = StudyManagerObj.GetStudy(0)
If StudyObj Is Nothing Then
Debug.Print "No no no"
Exit Sub
End If
Dim SolidManagerObj As Object
Set SolidManagerObj = StudyObj.SolidManager()
ErrorCodeObj = SolidManagerObj.SetLibraryMaterialToSelectedEntities("Custom Materials", "E.P.S.")
Part.ClearSelection2 TrueDim x_origin As Double
Dim y_origin As Double
x_origin = (chordroot * 0.001) / 2
y_origin = (chordroot * 0.00009974) / 2' Redraw
Part.GraphicsRedraw2
boolstatus = Part.Extension.SelectByRay(x_origin, y_origin, 0, -0.631634233055523, -0.18531998030324, 0.752791272885631, 8.13551995470029E-03, 2, True, 0, 0)' Redraw
Part.GraphicsRedraw2
Set LoadsAndRestraintsManagerObj = StudyObj.LoadsAndRestraintsManager()
Dim DispatchObj1 As Object
Set DispatchObj1 = Part.SelectionManager.GetSelectedObject6(1, -1)
If DispatchObj1 Is Nothing Then
Debug.Print "Failed to get the selected object. Please ensure the face is selected."
Exit Sub
End If
Dim DispArray As Variant
DispArray = Array(DispatchObj1)
Dim CWRestraintObj As Object
Set CWRestraintObj = LoadsAndRestraintsManagerObj.AddRestraint(0, (DispArray), Nothing, ErrorCodeObj)
Part.ClearSelection2 TrueDim x_origin_tip As Double
Dim y_origin_tip As Double
Dim z_origin_tip As Double
x_origin_tip = (chordtip * 0.001) / 2
y_origin_tip = (chordtip * 0.00009974) / 2
z_origin_tip = envergadura * 0.5
Radius = 0.00009974 / 5'Redraw
Part.GraphicsRedraw2
boolstatus = Part.Extension.SelectByRay(x_origin_tip, y_origin_tip, z_origin_tip, -0.277237907064792, -0.228718182991176, -0.933181191224699, Radius, 2, True, 0, 0)' Redraw
Part.GraphicsRedraw2
boolstatus = Part.Extension.SelectByID2("Axis1", "AXIS", -0.161238928176615, 1.21740934029632E-02, 0.896097347894243, True, 0, Nothing, 0)Part.GraphicsRedraw2
' Redraw
Part.GraphicsRedraw2
Set LoadsAndRestraintsManagerObj = StudyObj.LoadsAndRestraintsManager()
Set DispatchObj1 = Part.SelectionManager.GetSelectedObject6(1, -1)
Dim ReferenceGeometryDispatchObj2 As Object
Set ReferenceGeometryDispatchObj2 = Part.SelectionManager.GetSelectedObject6(2, -1)
If ReferenceGeometryDispatchObj2 Is Nothing Then
Debug.Print "Failed to get the reference geometry. Please ensure it is selected."
Exit Sub
End If
DispArray = Array(DispatchObj1)
Dim CWForceObj As Object
Dim DistanceValues As Variant
Dim ForceValues As Variant
Dim ComponentValues As Variant
Dim data(6) As Double
data(0) = 1
data(1) = 1
data(2) = lift
data(3) = 1
data(4) = 1
data(5) = 1
ComponentValues = data
Set CWForceObj = LoadsAndRestraintsManagerObj.AddForce3(0, 0, 0, 0, 0, 0, (DistanceValues), (ForceValues), 0, False, 0, 0, 4, 1, (ComponentValues), False, False, (DispArray), ReferenceGeometryDispatchObj2, False, ErrorCodeObj)
CWForceObj.ForceBeginEdit
CWForceObj.SetForceComponentValues 0, 0, 1, 1, 1, lift
CWForceObj.ForceEndEdit
Part.ClearSelection2 TrueDim MeshObj As Object
Set MeshObj = StudyObj.Mesh()
MeshObj.Quality = 1
MeshObj.UseJacobianCheckForSolids = 2
MeshObj.MesherType = 2
MeshObj.MinElementsInCircle = 8
MeshObj.GrowthRatio = 1.4
MeshObj.SaveSettingsWithoutMeshing = False
MeshObj.Unit = 0
ErrorCodeObj = StudyObj.CreateMesh(0, 40, 2)
ErrorCodeObj = StudyObj.RunAnalysis()
Dim ResultsObj As Object
Set ResultsObj = StudyObj.Results()
If ResultsObj Is Nothing Then
Debug.Print , "Failed to get results object"
Exit Sub
End If
Dim Disp As Variant
Dim Stress As Variant
Disp = ResultsObj.GetMinMaxDisplacement(3, 1, Nothing, 0, ErrorCodeObj)
Stress = ResultsObj.GetMinMaxStress(9, 0, 1, Nothing, 3, ErrorCodeObj)
StressArray = Stress
DisplacementArray = Disp
Set StudyManagerObj = Nothing
Set ActiveDocObj = Nothing
Set CWAddinCallBackObj = Nothing
Set COSMOSWORKSObj = NothingOSw.CloseDoc partTitle1
End Sub