1 |
bournival |
130 |
Imports SolidWorks.Interop
|
2 |
|
|
Imports SolidWorks.Interop.swconst
|
3 |
|
|
Imports SolidWorks.Interop.swpublished
|
4 |
|
|
|
5 |
|
|
Public Class InterPoutreVolume
|
6 |
|
|
Inherits InterAreteFace
|
7 |
|
|
|
8 |
|
|
'Public sFaceVolume As SlyFaceVolume
|
9 |
|
|
'Private BodySweep As sldworks.Body2
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
''' <summary>
|
13 |
|
|
''' Sub qui prend les intersections entre les faces et les volumes et qui coupe les volumes
|
14 |
|
|
''' </summary>
|
15 |
|
|
''' <remarks></remarks>
|
16 |
|
|
Private Sub DecouperPoutreVolume()
|
17 |
|
|
' #2 on procède au découpage de la face
|
18 |
|
|
Dim sVol As SlyFaceVolume
|
19 |
|
|
|
20 |
|
|
For Each sVol In lst_FaceVolume
|
21 |
|
|
If sVol.lst_InterPoutre.Count > 0 Then
|
22 |
|
|
sVol.decouper()
|
23 |
|
|
|
24 |
|
|
' on met-a-jour l'attribut des conditions aux limites
|
25 |
|
|
Dim attr As SldWorks.Attribute
|
26 |
|
|
Dim swent As SldWorks.Entity
|
27 |
|
|
Dim nom3 As String = Nothing
|
28 |
|
|
Dim p As SldWorks.Parameter
|
29 |
|
|
If Not sVol.AttributCL Is Nothing Then
|
30 |
|
|
nom3 = "CL_" & sVol.nom
|
31 |
|
|
swent = sVol.SwFace
|
32 |
|
|
attr = swent.FindAttribute(Intersections.DefAttrConditionLimite, 0) ' si l'attribut existe déjà on pointe dessus.
|
33 |
|
|
|
34 |
|
|
If attr Is Nothing Then attr = Intersections.DefAttrConditionLimite.CreateInstance5(swModel, sVol.SwFace, nom3, 0, 0)
|
35 |
|
|
p = attr.GetParameter("CL")
|
36 |
|
|
p.SetStringValue(sVol.condition)
|
37 |
|
|
|
38 |
|
|
End If
|
39 |
|
|
GererDossiers("Conditions Aux Limites", nom3)
|
40 |
|
|
End If
|
41 |
|
|
|
42 |
|
|
Next
|
43 |
|
|
End Sub
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
'Public Sub DecouperLong()
|
47 |
|
|
' ' on peut avoir une liste de poutres...
|
48 |
|
|
' 'For Each poutre As SlyAretePoutre In Me.lst_sPoutre
|
49 |
|
|
' Dim poutre As SlyAretePoutre = Me.lst_sPoutre.Item(1)
|
50 |
|
|
|
51 |
|
|
' Dim PetitSketch As sldworks.Sketch = Nothing
|
52 |
|
|
' Dim swSketchManager As sldworks.SketchManager = swModel.SketchManager
|
53 |
|
|
' Dim sfaceVol As SlyFaceVolume ' la face du volume
|
54 |
|
|
' Dim swfaceVol As sldworks.Face2
|
55 |
|
|
|
56 |
|
|
' Dim segment As sldworks.Entity = poutre.swArete
|
57 |
|
|
|
58 |
|
|
' swModel.ClearSelection()
|
59 |
|
|
' If swModel.GetActiveSketch2() IsNot Nothing Then MsgBox("Déjà un sketch d'actif???")
|
60 |
|
|
' swModel.Insert3DSketch2(False)
|
61 |
|
|
' segment.Select4(False, Nothing)
|
62 |
|
|
' swSketchManager.SketchUseEdge(False)
|
63 |
|
|
' swModel.Insert3DSketch2(False)
|
64 |
|
|
' swModel.EditRebuild3()
|
65 |
|
|
|
66 |
|
|
' Dim feat As sldworks.Feature = swModel.FeatureByPositionReverse(0)
|
67 |
|
|
' If Not feat.GetTypeName() = "3DProfileFeature" Then MsgBox("Problème ici")
|
68 |
|
|
' PetitSketch = feat.GetSpecificFeature2() ' devrait être un sketch
|
69 |
|
|
|
70 |
|
|
' ' 1 - créer le sweep à partir du sketch
|
71 |
|
|
' Me.GénérerSweep(PetitSketch) ' hahahaha on réutilise la sub !!
|
72 |
|
|
|
73 |
|
|
' ' sélectionner toutes les faces du sweep avec un mark de 16
|
74 |
|
|
' Dim swFaceSweep As sldworks.Face2 = Me.BodySweep.GetFirstFace()
|
75 |
|
|
' Dim swent As sldworks.Entity
|
76 |
|
|
' Dim featmanager As sldworks.FeatureManager
|
77 |
|
|
' Dim faces() As sldworks.Face2
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
' ' ***** Découpage du volume****
|
81 |
|
|
' swModel.EditRebuild3()
|
82 |
|
|
' featmanager = swModel.FeatureManager
|
83 |
|
|
' feat = Nothing
|
84 |
|
|
' sfaceVol = Me.sFaceVolume
|
85 |
|
|
' faces = sfaceVol.GetFaces
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
' For q As Integer = 0 To UBound(faces)
|
89 |
|
|
' swfaceVol = faces(q)
|
90 |
|
|
' ' merde, on a 3 fois la même face??? vérifier que le for each marche bien et/ou que le .ToArray du faces est corect.
|
91 |
|
|
' If swModel.ClosestDistance(swfaceVol, Me.BodySweep, Nothing, Nothing) < Epsilon Then
|
92 |
|
|
|
93 |
|
|
' swModel.ClearSelection2(True)
|
94 |
|
|
' Do While swFaceSweep IsNot Nothing ' les faces coupantes (celles du sweep) ont un mark de 16
|
95 |
|
|
' swent = swFaceSweep : swent.Select2(True, 16)
|
96 |
|
|
' swFaceSweep = swFaceSweep.GetNextFace
|
97 |
|
|
' Loop
|
98 |
|
|
|
99 |
|
|
' swent = swfaceVol : swent.Select2(True, 32)
|
100 |
|
|
' feat = featmanager.InsertSplitLineIntersect(7)
|
101 |
|
|
' If feat IsNot Nothing Then Exit For
|
102 |
|
|
|
103 |
|
|
' End If
|
104 |
|
|
' Next
|
105 |
|
|
|
106 |
|
|
' If feat Is Nothing Then
|
107 |
|
|
' If swApp.SendMsgToUser2("Solidworks est incapable de découper la face du volume, entre " & Me.sFaceVolume.nom & " et " & Me.sFaceVolume.nom & vbCr & " La géométrie est trop compliquée pour solidworks!", swconst.swMessageBoxIcon_e.swMbWarning, swconst.swMessageBoxBtn_e.swMbRetryCancel) = swconst.swMessageBoxResult_e.swMbHitCancel Then Exit Sub
|
108 |
|
|
' End If
|
109 |
|
|
|
110 |
|
|
' Me.BodySweep.HideBody(True)
|
111 |
|
|
|
112 |
|
|
' ' ajout des nouvelles faces
|
113 |
|
|
' Dim vfaces As Object = feat.GetFaces()
|
114 |
|
|
' swModel.EditRebuild3()
|
115 |
|
|
|
116 |
|
|
' For Each swfaceVol In vfaces ' sélectionne les faces découpées.
|
117 |
|
|
' If Not swfaceVol.GetBody Is Me.BodySweep Then
|
118 |
|
|
' sfaceVol.AjouterFace(swfaceVol)
|
119 |
|
|
' 'là on a une connerie, la face originale n'est pas dans la liste des faces de vFaces
|
120 |
|
|
' 'et le pointeur original semble détruit
|
121 |
|
|
' ' puisque ajouterface ne créé pas de doubles, on va chercher des faces que l'on mettra dans la liste
|
122 |
|
|
' ' la grosse face en fera automatiquement partie.
|
123 |
|
|
' Dim obj As Object = swfaceVol.GetEdges
|
124 |
|
|
' Dim aretes As sldworks.Edge = obj(0)
|
125 |
|
|
' Dim oBjfaces As Object = aretes.GetTwoAdjacentFaces2()
|
126 |
|
|
' Dim NewFaces As sldworks.Face2 = oBjfaces(0)
|
127 |
|
|
' sfaceVol.AjouterFace(NewFaces)
|
128 |
|
|
' NewFaces = oBjfaces(1)
|
129 |
|
|
' sfaceVol.AjouterFace(NewFaces)
|
130 |
|
|
' aretes = obj(1)
|
131 |
|
|
' NewFaces = oBjfaces(0)
|
132 |
|
|
' sfaceVol.AjouterFace(NewFaces)
|
133 |
|
|
' NewFaces = oBjfaces(1)
|
134 |
|
|
' sfaceVol.AjouterFace(NewFaces)
|
135 |
|
|
' End If
|
136 |
|
|
' Next
|
137 |
|
|
|
138 |
|
|
' ' il faut trouver les faces internes et les tagger comme des faces de coque(pour les mini-poutres orientées)
|
139 |
|
|
|
140 |
|
|
' 'Next poutre
|
141 |
|
|
'End Sub
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
'Public Sub GénérerSweep(Optional ByRef sketch As sldworks.Sketch = Nothing)
|
146 |
|
|
' ' on peut essayer 2 méthodes, celle du offset des faces et celle du sweep d'un cercle
|
147 |
|
|
' ' celle du offset ne marche pas dans toutes les circonstances...
|
148 |
|
|
' Dim swEnt As SldWorks.Entity
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
' ' 2- Placer un plan à l'extrémité
|
152 |
|
|
' Dim Plan As SldWorks.RefPlane
|
153 |
|
|
|
154 |
|
|
' Dim vSeg As Object 'SldWorks.SketchSegment
|
155 |
|
|
' Dim seg As SldWorks.SketchSegment
|
156 |
|
|
' Dim skPoint As SldWorks.SketchPoint = Nothing
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
' vSeg = sketch.GetSketchSegments() : seg = vSeg(0)
|
160 |
|
|
|
161 |
|
|
' Select Case seg.GetType ' faut faire attention, si le sketch est fermé, ça peut chier des taque pour séelectionner le point
|
162 |
|
|
' Case SwConst.swSketchSegments_e.swSketchLINE
|
163 |
|
|
' Dim skline As SldWorks.SketchLine = seg
|
164 |
|
|
' skPoint = skline.GetStartPoint2()
|
165 |
|
|
|
166 |
|
|
' Case SwConst.swSketchSegments_e.swSketchARC
|
167 |
|
|
' Dim skarc As SldWorks.SketchArc = seg
|
168 |
|
|
' skPoint = skarc.GetStartPoint2()
|
169 |
|
|
' Case SwConst.swSketchSegments_e.swSketchELLIPSE
|
170 |
|
|
' Dim skellipse As SldWorks.SketchEllipse = seg
|
171 |
|
|
' skPoint = skellipse.GetStartPoint2()
|
172 |
|
|
' If skPoint Is Nothing Then
|
173 |
|
|
' ' couper l'ellipse
|
174 |
|
|
' MsgBox("On a pas de startpoint sur cette ellipse")
|
175 |
|
|
' End If
|
176 |
|
|
' Case SwConst.swSketchSegments_e.swSketchSPLINE
|
177 |
|
|
' Dim skSpline As SldWorks.SketchSpline = seg
|
178 |
|
|
' Dim vPoints As Object
|
179 |
|
|
' vPoints = skSpline.GetPoints2()
|
180 |
|
|
' skPoint = vPoints(0)
|
181 |
|
|
' Case SwConst.swSketchSegments_e.swSketchPARABOLA
|
182 |
|
|
' Dim skPara As SldWorks.SketchParabola = seg
|
183 |
|
|
' skPoint = skPara.GetStartPoint2()
|
184 |
|
|
' Case Else
|
185 |
|
|
' MsgBox(" Là y'a un problème! (case else....)")
|
186 |
|
|
' End Select
|
187 |
|
|
|
188 |
|
|
' seg.Select4(False, Nothing)
|
189 |
|
|
' skPoint.Select4(True, Nothing)
|
190 |
|
|
|
191 |
|
|
' Plan = swModel.CreatePlanePerCurveAndPassPoint3(True, False) ' le premier true met l'origine sur le point de la courbe, le second false est pour la visualisation.
|
192 |
|
|
|
193 |
|
|
' ' 3 - on créé un cercle sur le plan
|
194 |
|
|
' Dim rayon As Double
|
195 |
|
|
' Dim sface As SlyFaceVolume = Me.sFaceVolume
|
196 |
|
|
' Dim feat As SldWorks.Feature
|
197 |
|
|
' Dim sketchCercle As SldWorks.Sketch
|
198 |
|
|
' Dim poutre As SlyAretePoutre
|
199 |
|
|
|
200 |
|
|
' rayon = Commun.ENG * Math.Sqrt(3) / 2 ' la bonne distance pour le maillage :-)
|
201 |
|
|
' swEnt = Plan : swEnt.Select4(False, Nothing)
|
202 |
|
|
|
203 |
|
|
' swModel.InsertSketch2(False)
|
204 |
|
|
' swModel.CreateCircle2(rayon / 2, 0, 0, 0, 0, 0)
|
205 |
|
|
' swModel.InsertSketch2(True)
|
206 |
|
|
|
207 |
|
|
' feat = swModel.FeatureByPositionReverse(0)
|
208 |
|
|
' sketchCercle = feat.GetSpecificFeature2()
|
209 |
|
|
|
210 |
|
|
' ' 4 - Sweep
|
211 |
|
|
' Dim swFeatManager As SldWorks.FeatureManager = swModel.FeatureManager
|
212 |
|
|
|
213 |
|
|
' Dim merge As Boolean = False
|
214 |
|
|
|
215 |
|
|
' swEnt = sketchCercle : swEnt.Select2(False, 1)
|
216 |
|
|
' swEnt = sketch : swEnt.Select2(True, 4)
|
217 |
|
|
|
218 |
|
|
' feat = swFeatManager.InsertProtrusionSwept3(False, False, 0, False, False, 1, 1, False, 0, 0, 0, 0, merge, 1, 1, 0, 1) ' merge fait additionner le bnouveau corps... Pas certain du false qui suit.
|
219 |
|
|
|
220 |
|
|
' If feat Is Nothing Then
|
221 |
|
|
' swEnt = sketchCercle : swEnt.Select2(False, 1)
|
222 |
|
|
' swEnt = sketch : swEnt.Select2(True, 4)
|
223 |
|
|
' feat = swFeatManager.InsertProtrusionSwept3(False, False, 0, False, False, 0, 0, False, 0, 0, 0, 0, 0, 1, 1, 0, 1)
|
224 |
|
|
' End If
|
225 |
|
|
|
226 |
|
|
' If feat Is Nothing Then
|
227 |
|
|
' ' il est possible que la coque soit une spline
|
228 |
|
|
' MsgBox("Il est impossible de découper la forme de la courbe, la coque est trop repliée sur elle-même..." & vbCr & "Un rayon de courbure de la section de la coque est inférieur à l'épaisseur de la coque", MsgBoxStyle.Information, "Impossible de découper à un endroit!")
|
229 |
|
|
' ' on pourrait éventuellement appliquer une autre méthode.
|
230 |
|
|
' Exit Sub
|
231 |
|
|
' End If
|
232 |
|
|
|
233 |
|
|
' Dim vfaces As Object = feat.GetFaces
|
234 |
|
|
' Dim swface As SldWorks.Face2 = vfaces(0)
|
235 |
|
|
' Me.BodySweep = swface.GetBody
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
' If Me.BodySweep Is Nothing Then MsgBox(feat.Name)
|
239 |
|
|
|
240 |
|
|
'End Sub
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
Public Sub New()
|
244 |
|
|
|
245 |
|
|
End Sub
|
246 |
|
|
End Class
|