Advertisement
Guest User

Untitled

a guest
Jan 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Dim swApp              As Object
  4. Dim Part               As Object
  5. Dim skSegment          As Object
  6. Dim boolstatus         As Boolean
  7. Dim longstatus         As Long
  8.  
  9. Dim tabx(1000)         As Double
  10. Dim taby(1000)         As Double
  11. Dim tabz(1000)         As Double
  12.  
  13. Dim length             As Double
  14. Dim boole              As Boolean
  15. Dim n                  As Integer
  16. Dim radius             As Double
  17. Dim securityradius     As Double
  18. Dim dist               As Double
  19.  
  20. Dim MatrixVolume       As Integer
  21. Dim FibersVolume       As Integer
  22. Dim MatrixVolumeFract  As Double
  23. Dim FibersVolumeFract  As Double
  24. Dim MatrixVolumeFractP As Integer
  25. Dim FibersVolumeFractP As Integer
  26. Dim EffectiveTC        As Double
  27. Dim err                As Long
  28. Dim war                As Long
  29. Dim bool               As Boolean
  30. Dim name               As String
  31. Dim swmodel            As Object
  32. Dim chemin_dossier     As String
  33.  
  34.  
  35. Private Sub LengthTextBox_Enter()
  36.  
  37. 'Delete indication text
  38. If LengthTextBox.Value = "Length of RVE" Then
  39. LengthTextBox.Value = ""
  40. End If
  41.  
  42. End Sub
  43.  
  44. Private Sub RadiusTextBox_Enter()
  45.  
  46. 'Delete indication text
  47. If RadiusTextBox.Value = "Radius of inclusions" Then
  48. RadiusTextBox.Value = ""
  49. End If
  50.  
  51. End Sub
  52.  
  53. Private Sub NumbersTextBox_Enter()
  54.  
  55. 'Delete indication text
  56. If NumbersTextBox.Value = "Numbers of inclusions" Then
  57. NumbersTextBox.Value = ""
  58. End If
  59.  
  60. End Sub
  61.  
  62. Private Sub CalculateButton_Click()
  63.  
  64. If LengthTextBox.Value = "Length of RVE" Or LengthTextBox.Value = "" Or RadiusTextBox.Value = "Radius of inclusions" Or RadiusTextBox.Value = "" Or NumbersTextBox.Value = "Numbers of inclusions" Or NumbersTextBox.Value = "" Then
  65. MsgBox "Please fill all the fields !", vbCritical, "Error"
  66. Else
  67.  
  68. 'Show calculate zone
  69. UserForm1.Height = 489.75
  70.  
  71. 'Calculate volume fraction
  72. MatrixVolume = LengthTextBox.Value * LengthTextBox.Value * LengthTextBox.Value
  73. FibersVolume = (4 * Atn(1)) * (RadiusTextBox.Value ^ 2) * LengthTextBox.Value * NumbersTextBox.Value
  74.  
  75. FibersVolumeFract = FibersVolume / MatrixVolume
  76. MatrixVolumeFract = 1 - FibersVolumeFract
  77.  
  78. MatrixVolumeFractP = MatrixVolumeFract * 100
  79. FibersVolumeFractP = FibersVolumeFract * 100
  80.  
  81. MatrixV.Caption = MatrixVolume
  82. FibersV.Caption = FibersVolume
  83. MatrixVF.Caption = MatrixVolumeFractP
  84. FibersVF.Caption = FibersVolumeFractP
  85.  
  86. 'Calculate decimal thermal conductivity and round at 2
  87. EffectiveTC = (TCF.Value * FibersVolumeFract) + (TCM.Value * MatrixVolumeFract)
  88. ETC.Caption = Int(EffectiveTC * 10 ^ 2 + 1 / 2) / 10 ^ 2
  89.  
  90. End If
  91.  
  92. End Sub
  93.  
  94. Private Sub GenerateButton_Click()
  95.  
  96. 'Enregistrement
  97. 'identifier le chemin du dossier
  98. chemin_dossier = "C:\Users\Kader\Desktop\test"
  99. 'vérifier l'existence du dossier et le créer
  100. If Dir(chemin_dossier, vbDirectory) <> vbNullString Then
  101.     'dossier exuste
  102.    'ne rien faire
  103. Else
  104.     'dossier n'existe pas, le créer
  105.    MkDir (chemin_dossier)
  106. End If
  107.  
  108. If LengthTextBox.Value = "Length of RVE" Or LengthTextBox.Value = "" Or RadiusTextBox.Value = "Radius of inclusions" Or RadiusTextBox.Value = "" Or NumbersTextBox.Value = "Numbers of inclusions" Or NumbersTextBox.Value = "" Then
  109. MsgBox "Please fill all the fields !", vbCritical, "Error"
  110. Else
  111.  
  112. 'open new part
  113. Set swApp = Application.SldWorks
  114. Set Part = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2018\templates\Pièce.prtdot", 0, 0, 0)
  115.  
  116. '3D sketch
  117. Part.SketchManager.Insert3DSketch (True)
  118.  
  119. 'number of cylinder
  120. n = NumbersTextBox.Value
  121.  
  122. 'length and radius
  123. length = LengthTextBox.Value / 1000
  124. radius = RadiusTextBox.Value / 1000
  125. securityradius = radius * 1.2
  126.  
  127. 'random generate and no overlap
  128. Dim i, j As Integer
  129. For i = 1 To n
  130. Randomize Timer
  131. tabx(i) = Rnd * (length - securityradius * 2) + securityradius  'x position
  132. taby(i) = Rnd * (length - securityradius * 2) + securityradius  'y position
  133. boole = 0
  134. If (i <> 1) Then
  135. For j = 1 To i - 1
  136. dist = Sqrt((tabx(i) - tabx(j)) ^ 2 + (taby(i) - taby(j)) ^ 2)
  137. If (dist < 2.2 * radius) Then boole = 1
  138. Next j
  139. End If
  140.  
  141. 'add point
  142. If (boole = 0) Then
  143. Dim skPoint As Object
  144. Set skPoint = Part.SketchManager.CreatePoint(tabx(i), taby(i), tabz(i))
  145. 'MsgBox tabx(i) & " " & taby(i) & " " & tabz(i)
  146. Else
  147. i = i - 1
  148. End If
  149. Next i
  150.  
  151. 'circle insertion
  152. Set Part = swApp.ActiveDoc
  153. Part.SketchManager.InsertSketch True
  154. boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
  155. Part.ClearSelection2 True
  156. Dim skSegment As Object
  157. Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, radius, 0#, 0#)
  158.  
  159. 'circle extrusion
  160. Dim myFeature As Object
  161. Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, length, length, False, False, False, False, 0.01, 0.01, False, False, False, False, True, True, True, 0, 0, False)
  162.  
  163. 'repetition by sketch
  164. boolstatus = Part.Extension.SelectByID2("Esquisse3D1", "SKETCH", 0, 0, 0, False, 64, Nothing, 0)
  165. boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", 0, 0, 0, True, 256, Nothing, 0)
  166. Part.FeatureManager.FeatureSketchDrivenPattern True, False
  167.  
  168. 'delete the first revolution
  169. boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
  170. Set myFeature = Part.FeatureManager.InsertDeleteBody2(False)
  171.  
  172. 'hide the 3D sketch
  173. boolstatus = Part.Extension.SelectByID2("Esquisse3D1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
  174. Part.BlankSketch
  175. ' Save As REV
  176. longstatus = Part.SaveAs3("C:\Users\Kader\Desktop\test\RVE.SLDPRT", 0, 2)
  177.  
  178. Set swmodel = swApp.ActiveDoc
  179. name = "RVE"
  180. bool = swmodel.Extension.SaveAs(name + ".sldprt", 0, 1, Nothing, err, war)
  181.  
  182. End If
  183.  
  184. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  185.  
  186. ' CUBE
  187.  
  188. ' New Document part
  189. Set Part = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2018\templates\Pièce.prtdot", 0, 0, 0)
  190.  
  191. boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
  192. Dim vSkLines As Variant
  193. vSkLines = Part.SketchManager.CreateCornerRectangle(0, 0, 0, 0.01, 0.01, 0)
  194.  
  195. 'Dim myFeature As Object
  196. Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 6, 0, length, length, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
  197. Part.ClearSelection2 True
  198. ' Save As CUBE
  199. longstatus = Part.SaveAs3("C:\Users\Kader\Desktop\test\CUBE.SLDPRT", 0, 2)
  200.  
  201. Set swmodel = swApp.ActiveDoc
  202. name = "CUBE"
  203. bool = swmodel.Extension.SaveAs(name + ".sldprt", 0, 1, Nothing, err, war)
  204.  
  205. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  206.  
  207. ' Ass
  208.  
  209. ' New Document
  210. Set swApp = Application.SldWorks
  211. Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\Assemblage.asmdot", 0, 0, 0)
  212.  
  213. ' Insert Component CUBE
  214. Dim swInsertedComponent As Component2
  215. Set swInsertedComponent = Part.AddComponent5("C:\Users\Kader\Desktop\test\CUBE.SLDPRT", 0, "", False, "", 0, 0, 0)
  216. 'swApp.CloseDoc "C:\Users\Kader\Desktop\test vba\CUBE.SLDPRT"
  217.  
  218. ' Insert Component REV
  219. Set swInsertedComponent = Part.AddComponent5("C:\Users\Kader\Desktop\test\RVE.SLDPRT", 0, "", False, "", 0, 0, 0)
  220. 'swApp.CloseDoc "C:\Users\Kader\Desktop\test vba\REV.SLDPRT"
  221.  
  222. ' Named View
  223. Part.ShowNamedView2 "*Isométrique", 7
  224. Part.ViewZoomtofit2
  225.  
  226. ' Save As CUBE
  227. longstatus = Part.SaveAs3("C:\Users\Kader\Desktop\test\Projet7.sldasm", 0, 2)
  228.  
  229. Set swmodel = swApp.ActiveDoc
  230. name = "Projet7"
  231. bool = swmodel.Extension.SaveAs(name + ".sldasm", 0, 1, Nothing, err, war)
  232.  
  233.  
  234. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement