Bonjour,
Le code fonction parfaitement depuis ma macro, par contre je n'arrive pas à récupérer les valeurs dans ma macro ou j'appelle la fonction.
J'imagine que les donnée sont enregistré dans une array mais comment en rappeler les valeur depuis ma macro?
Option Explicit
Sub main()
Dim swapp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim vComps As Variant
Dim vComp As Variant
Dim Comp As SldWorks.Component2
Dim vEdges As Variant
Dim vEdge As Variant
Dim swEdge As SldWorks.edge
Dim swCurve As SldWorks.Curve
Dim IsClosed As Boolean
Dim pos As String
Dim CurveParam As Variant
Dim Cercle As Class1
Dim monCercle As Class1
Dim Cercles As Collection
Set swapp = Application.SldWorks
Set swModel = swapp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.ActiveDrawingView
If swView Is Nothing Then
MsgBox "Selectionner une vue"
Exit Sub
End If
'Ajout SD pour récuperer les valeures de la Bounding Box
Dim swPartModel As SldWorks.ModelDoc2
Set swPartModel = swView.ReferencedDocument
GetPreciseBoundingBox swPartModel
' Fin de l'ajout
Set Cercles = New Collection
vComps = swView.GetVisibleComponents
For Each vComp In vComps
Set Comp = vComp
vEdges = swView.GetVisibleEntities(Comp, swViewEntityType_e.swViewEntityType_Edge)
For Each vEdge In vEdges
Set swEdge = vEdge
Set swCurve = swEdge.GetCurve
If swCurve.IsCircle Then
swCurve.GetEndParams Empty, Empty, IsClosed, Empty
If IsClosed Then
CurveParam = swCurve.CircleParams
pos = ""
If Round(CurveParam(3), 3) = 0 Then pos = pos & Round(CurveParam(0), 3) & "-"
If Round(CurveParam(4), 3) = 0 Then pos = pos & Round(CurveParam(1), 3) & "-"
If Round(CurveParam(5), 3) = 0 Then pos = pos & Round(CurveParam(2), 3) & "-"
Debug.Print pos
Set Cercle = New Class1
Cercle.pos = pos
Cercle.dia = Round(CurveParam(6), 3)
Set Cercle.edge = swEdge
Cercles.Add Cercle
End If
End If
Next
Next
swModel.ClearSelection2 True
For Each monCercle In Cercles
For Each Cercle In Cercles
Debug.Print Cercle.dia * 1000
If Cercle.pos = monCercle.pos And Cercle.dia < monCercle.dia And monCercle.dia * 1000 < 38 Then
monCercle.edge.Select4 True, Nothing
End If
Next
Next
'Modif SD - on ne cache plus temporairement
'swDraw.HideEdge
swModel.ForceRebuild3 False
'swModel.SetLineColor 255 '
swModel.ClearSelection2 True
End Sub
Function GetPreciseBoundingBox(part As SldWorks.PartDoc) As Variant
Dim dBox(5) As Double
Dim vBodies As Variant
vBodies = part.GetBodies2(swBodyType_e.swSolidBody, True)
Dim minX As Double
Dim minY As Double
Dim minZ As Double
Dim maxX As Double
Dim maxY As Double
Dim maxZ As Double
If Not IsEmpty(vBodies) Then
Dim i As Integer
For i = 0 To UBound(vBodies)
Dim swBody As SldWorks.Body2
Set swBody = vBodies(i)
Dim x As Double
Dim y As Double
Dim z As Double
swBody.GetExtremePoint 1, 0, 0, x, y, z
If i = 0 Or x > maxX Then maxX = x
swBody.GetExtremePoint -1, 0, 0, x, y, z
If i = 0 Or x < minX Then minX = x
swBody.GetExtremePoint 0, 1, 0, x, y, z
If i = 0 Or y > maxY Then maxY = y
swBody.GetExtremePoint 0, -1, 0, x, y, z
If i = 0 Or y < minY Then minY = y
swBody.GetExtremePoint 0, 0, 1, x, y, z
If i = 0 Or z > maxZ Then maxZ = z
swBody.GetExtremePoint 0, 0, -1, x, y, z
If i = 0 Or z < minZ Then minZ = z
Next
End If
dBox(0) = minX: dBox(1) = minY: dBox(2) = minZ
dBox(3) = maxX: dBox(4) = maxY: dBox(5) = maxZ
Debug.Print "minX" & minX
Debug.Print "minY" & minY
Debug.Print "minZ" & minZ
Debug.Print "maxX" & maxX
Debug.Print "maxY" & maxY
Debug.Print "maxZ" & maxZ
GetPreciseBoundingBox = dBox
Debug.Print "essai" & dBox(0)
End Function