Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim swApp As Object
- Dim Part As Object
- Dim tabx(1000) As Double
- Dim taby(1000) As Double
- Dim tabz(1000) As Double
- Dim length As Double
- Dim bolle As Boolean
- Dim n As Integer
- Dim rayon As Double
- Dim rayon2 As Double
- Dim nombre As Integer
- Dim dist As Double
- Dim i, j As Integer
- Dim COSMOSWORKSObj As Object
- Dim CWAddinCallBackObj As Object
- Dim swSheetWidth As Double
- Dim swSheetHeight As Double
- Dim swPart As PartDoc
- Dim skSegment As Object
- Dim myDimension As SldWorks.Dimension
- Dim myDisplayDim As Object
- Dim boolstatus As Boolean
- Dim longstatus As Long, longwarnings As Long
- Dim skPoint As Object
- Dim myFeature As Object
- Sub main()
- 'Ouverture d'une nouvelle pièce
- Set swApp = Application.SldWorks
- Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")
- Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
- swSheetWidth = 0
- swSheetHeight = 0
- Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\Pièce.prtdot", 0, swSheetWidth, swSheetHeight)
- Set swPart = Part
- swApp.ActivateDoc2 "Pièce1", False, longstatus
- Set Part = swApp.ActiveDoc
- 'Esquisse 3D
- Part.SketchManager.Insert3DSketch (True)
- Part.SketchManager.AddToDB = True
- 'Nombre de boule
- n = InputBox("Entrer la valeur de n")
- nombre = n
- 'Déclaration longueur et rayons
- length = InputBox("Entrer la valeur de l") / 1000
- rayon = InputBox("Entrer la valeur des particules") / 1000
- rayon2 = rayon * 1.2
- 'Gener. Aléatoire des points
- For i = 1 To n
- Randomize Timer
- tabx(i) = Rnd * (length - rayon2 * 2) + rayon2 'Position x
- taby(i) = Rnd * (length - rayon2 * 2) + rayon2 'Position y
- tabz(i) = length / 2 'Position z
- bolle = 0
- If (i <> 1) Then
- For j = 1 To i - 1
- dist = Sqrt((tabx(i) - tabx(j)) ^ 2 + (taby(i) - taby(j)) ^ 2 + (tabz(i) - tabz(j)) ^ 2)
- If (dist < 2.2 * rayon) Then bolle = 1
- Next j
- End If
- If (bolle = 0) Then
- Set skPoint = Part.SketchManager.CreatePoint(tabx(i), taby(i), tabz(i)) 'Creation du point
- 'MsgBox tabx(i) & " " & taby(i) & " " & tabz(i)
- Else
- i = i - 1
- End If
- Next i
- 'Insertion d'une Cylindre
- Set Part = swApp.ActiveDoc
- Part.SketchManager.InsertSketch True
- boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
- Part.ClearSelection2 True
- Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, rayon, 0#, 0#)
- Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, length, length, False, False, False, False, length, length, False, False, False, False, True, True, True, 0, 0, False)
- 'Répétition par esquisee
- boolstatus = Part.Extension.SelectByID2("Esquisse3D1", "SKETCH", 0, 0, 0, False, 64, Nothing, 0)
- boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", -6.74308053442019E-03, 2.69252183593949E-03, 5.47894052022002E-03, True, 256, Nothing, 0)
- Part.FeatureManager.FeatureSketchDrivenPattern True, False
- boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
- boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
- 'Suppression du première cylindre
- boolstatus = Part.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", -9.00371912371156E-03, 3.2719117743909E-03, 4.32472761337976E-03, True, 0, Nothing, 0)
- Set myFeature = Part.FeatureManager.InsertDeleteBody2(False)
- 'Cacher l'esquisse 3D1
- boolstatus = Part.Extension.SelectByID2("Esquisse3D1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
- Part.BlankSketch
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement