This macro allows the extraction of the main constraints of several faces chosen on a part, and then paste them in an Excel sheet. It works on a part type file.
However it is not functional in an assembly, I modified the starting macro, but without success.
Someone would have any idea ?
Thanks !
Pre conditions :
-make sure Excel reference is set on
-Open part document
-Enable simulation extension
-configure two simulation studies
-mesh must be set
-launch the macro !
Post conditions :
-P1/P2/P3 for two studies are recorded in an Excel worksheet
Sub main()
Dim swApp As SldWorks.SldWorks
Dim COSMOSWORKS As CosmosWorksLib.COSMOSWORKS
Dim INIRESULT As CosmosWorksLib.cwResults
Dim FINRESULT As CosmosWorksLib.cwResults
Dim INITIAL As CosmosWorksLib.CWStudy
Dim FINAL As CosmosWorksLib.CWStudy
Dim FACE1 As SldWorks.FACE2
Dim FACE2 As SldWorks.FACE2
Dim FACE3 As SldWorks.FACE2
Dim FACE4 As SldWorks.FACE2
Dim FACE5 As SldWorks.FACE2
Dim TABLEFACE1 As Variant
Dim TABLEFACE2 As Variant
Dim TABLEFACE3 As Variant
Dim TABLEFACE4 As Variant
Dim TABLEFACE5 As Variant
Dim CWObject As Object
Dim AnalyseFEA As Long
Dim ActDoc As Object
Dim StudyMngr As Object
Dim Principale_11() As Variant
Dim Principale_21() As Variant
Dim Principale_31() As Variant
Dim Principale_12() As Variant
Dim Principale_22() As Variant
Dim Principale_32() As Variant
Dim Principale_13() As Variant
Dim Principale_23() As Variant
Dim Principale_33() As Variant
Dim Principale_14() As Variant
Dim Principale_24() As Variant
Dim Principale_34() As Variant
Dim Principale_15() As Variant
Dim Principale_25() As Variant
Dim Principale_35() As Variant
Dim Excel As Excel.Application
Dim classeur As Excel.Workbook
Dim feuille As Excel.Worksheet
Dim i As Variant
Dim n As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'make sure that Simulation extension is on
Set CWObject = swApp.GetAddInObject("SldWorks.Simulation")
Set COSMOSWORKS = CWObject.COSMOSWORKS
Set ActDoc = COSMOSWORKS.ActiveDoc()
Set StudyMngr = ActDoc.StudyManager()
'modify the Excel path file
Set Excel = New Excel.Application
Excel.Visible = True
Set classeur = Excel.Workbooks.Open("C:\Users\irpbdq\Desktop\test.xlsx")
Set feuille = classeur.Sheets("Feuil2")
'GetEntityByname works only for part document
Set FACE1 = swModel.GetEntityByName("FACE1", 2)
Set FACE2 = swModel.GetEntityByName("FACE2", 2)
Set FACE3 = swModel.GetEntityByName("FACE3", 2)
Set FACE4 = swModel.GetEntityByName("FACE4", 2)
Set FACE5 = swModel.GetEntityByName("FACE5", 2)
TABLEFACE1 = Array(FACE1)
TABLEFACE2 = Array(FACE2)
TABLEFACE3 = Array(FACE3)
TABLEFACE4 = Array(FACE4)
TABLEFACE5 = Array(FACE5)
'SERRAGE
Set INITIAL = StudyMngr.GetStudy(0)
AnalyseFEA = INITIAL.RunAnalysis
Set INIRESULT = INITIAL.results
Principale_11 = INIRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_21 = INIRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_31 = INIRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_12 = INIRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_22 = INIRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_32 = INIRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_13 = INIRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_23 = INIRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_33 = INIRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_14 = INIRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_24 = INIRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_34 = INIRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_15 = INIRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
Principale_25 = INIRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
Principale_35 = INIRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
With feuille
i = 0
n = 0
While i < UBound(Principale_11)
.Cells(18 + n, 6).Value = Principale_11(i + 1)
.Cells(18 + n, 7).Value = Principale_21(i + 1)
.Cells(18 + n, 8).Value = Principale_31(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_12)
.Cells(18 + n, 12).Value = Principale_12(i + 1)
.Cells(18 + n, 13).Value = Principale_22(i + 1)
.Cells(18 + n, 14).Value = Principale_32(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_13)
.Cells(18 + n, 18).Value = Principale_13(i + 1)
.Cells(18 + n, 19).Value = Principale_23(i + 1)
.Cells(18 + n, 20).Value = Principale_33(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_14)
.Cells(18 + n, 24).Value = Principale_14(i + 1)
.Cells(18 + n, 25).Value = Principale_24(i + 1)
.Cells(18 + n, 26).Value = Principale_34(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_15)
.Cells(18 + n, 30).Value = Principale_15(i + 1)
.Cells(18 + n, 31).Value = Principale_25(i + 1)
.Cells(18 + n, 32).Value = Principale_35(i + 1)
n = n + 1
i = i + 2
Wend
End With
'SERRAGE+PRESSION
Set FINAL = StudyMngr.GetStudy(1)
AnalyseFEA = FINAL.RunAnalysis
Set FINRESULT = FINAL.results
Principale_11 = FINRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_21 = FINRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_31 = FINRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE1, 3, 0, 0, False, AnalyseFEA)
Principale_12 = FINRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_22 = FINRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_32 = FINRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE2, 3, 0, 0, False, AnalyseFEA)
Principale_13 = FINRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_23 = FINRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_33 = FINRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE3, 3, 0, 0, False, AnalyseFEA)
Principale_14 = FINRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_24 = FINRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_34 = FINRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE4, 3, 0, 0, False, AnalyseFEA)
Principale_15 = FINRESULT.GetStressForEntities3(True, 6, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
Principale_25 = FINRESULT.GetStressForEntities3(True, 7, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
Principale_35 = FINRESULT.GetStressForEntities3(True, 8, 1, Nothing, TABLEFACE5, 3, 0, 0, False, AnalyseFEA)
With feuille
i = 0
n = 0
While i < UBound(Principale_11)
.Cells(18 + n, 9).Value = Principale_11(i + 1)
.Cells(18 + n, 10).Value = Principale_21(i + 1)
.Cells(18 + n, 11).Value = Principale_31(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_12)
.Cells(18 + n, 15).Value = Principale_12(i + 1)
.Cells(18 + n, 16).Value = Principale_22(i + 1)
.Cells(18 + n, 17).Value = Principale_32(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_13)
.Cells(18 + n, 21).Value = Principale_13(i + 1)
.Cells(18 + n, 22).Value = Principale_23(i + 1)
.Cells(18 + n, 23).Value = Principale_33(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_14)
.Cells(18 + n, 27).Value = Principale_14(i + 1)
.Cells(18 + n, 28).Value = Principale_24(i + 1)
.Cells(18 + n, 29).Value = Principale_34(i + 1)
n = n + 1
i = i + 2
Wend
End With
With feuille
i = 0
n = 0
While i < UBound(Principale_15)
.Cells(18 + n, 33).Value = Principale_15(i + 1)
.Cells(18 + n, 34).Value = Principale_25(i + 1)
.Cells(18 + n, 35).Value = Principale_35(i + 1)
n = n + 1
i = i + 2
Wend
End With
End Sub
SolidworksApi/macros