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 |
12 |
> |
Public Sub New() |
13 |
|
|
42 |
– |
Next |
14 |
|
End Sub |
15 |
|
|
16 |
|
|
17 |
< |
'Public Sub DecouperLong() |
18 |
< |
' ' on peut avoir une liste de poutres... |
19 |
< |
' 'For Each poutre As SlyAretePoutre In Me.lst_sPoutre |
20 |
< |
' Dim poutre As SlyAretePoutre = Me.lst_sPoutre.Item(1) |
21 |
< |
|
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 |
17 |
> |
Public Overrides Sub DecouperLong() |
18 |
> |
MyBase.DecouperLong() |
19 |
> |
' on peut avoir une liste de poutres... |
20 |
> |
'For Each poutre As SlyAretePoutre In Me.lst_sPoutre |
21 |
> |
Dim poutre As SlyAretePoutre = Me.lst_sPoutre.Item(1) |
22 |
|
|
23 |
+ |
Dim PetitSketch As sldworks.Sketch = Nothing |
24 |
+ |
Dim swSketchManager As sldworks.SketchManager = swModel.SketchManager |
25 |
+ |
Dim sfaceVol As SlyFaceVolume ' la face du volume |
26 |
+ |
Dim swfaceVol As sldworks.Face2 |
27 |
|
|
28 |
< |
' If Me.BodySweep Is Nothing Then MsgBox(feat.Name) |
28 |
> |
Dim segment As sldworks.Entity = poutre.swArete |
29 |
|
|
30 |
< |
'End Sub |
30 |
> |
swModel.ClearSelection() |
31 |
> |
If swModel.GetActiveSketch2() IsNot Nothing Then MsgBox("Déjà un sketch d'actif???") |
32 |
> |
swModel.Insert3DSketch2(False) |
33 |
> |
segment.Select4(False, Nothing) |
34 |
> |
swSketchManager.SketchUseEdge(False) |
35 |
> |
swModel.Insert3DSketch2(False) |
36 |
> |
swModel.EditRebuild3() |
37 |
|
|
38 |
+ |
Dim feat As sldworks.Feature = swModel.FeatureByPositionReverse(0) |
39 |
+ |
If Not feat.GetTypeName() = "3DProfileFeature" Then MsgBox("Problème ici") |
40 |
+ |
PetitSketch = feat.GetSpecificFeature2() ' devrait être un sketch |
41 |
+ |
|
42 |
+ |
' 1 - créer le sweep à partir du sketch |
43 |
+ |
Me.GénérerSweep(PetitSketch) ' hahahaha on réutilise la sub !! |
44 |
+ |
|
45 |
+ |
' sélectionner toutes les faces du sweep avec un mark de 16 |
46 |
+ |
Dim swFaceSweep As sldworks.Face2 = Me.BodySweep.GetFirstFace() |
47 |
+ |
Dim swent As sldworks.Entity |
48 |
+ |
Dim featmanager As sldworks.FeatureManager |
49 |
+ |
Dim faces() As sldworks.Face2 |
50 |
+ |
|
51 |
+ |
|
52 |
+ |
' ***** Découpage du volume**** |
53 |
+ |
swModel.EditRebuild3() |
54 |
+ |
featmanager = swModel.FeatureManager |
55 |
+ |
feat = Nothing |
56 |
+ |
|
57 |
+ |
|
58 |
+ |
sfaceVol = Me.sFaceVolume |
59 |
+ |
|
60 |
+ |
|
61 |
+ |
faces = sfaceVol.GetFaces |
62 |
|
|
243 |
– |
Public Sub New() |
63 |
|
|
64 |
+ |
For q As Integer = 0 To UBound(faces) |
65 |
+ |
swfaceVol = faces(q) |
66 |
+ |
' 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. |
67 |
+ |
If swModel.ClosestDistance(swfaceVol, Me.BodySweep, Nothing, Nothing) < Epsilon Then |
68 |
+ |
|
69 |
+ |
swModel.ClearSelection2(True) |
70 |
+ |
Do While swFaceSweep IsNot Nothing ' les faces coupantes (celles du sweep) ont un mark de 16 |
71 |
+ |
swent = swFaceSweep : swent.Select2(True, 16) |
72 |
+ |
swFaceSweep = swFaceSweep.GetNextFace |
73 |
+ |
Loop |
74 |
+ |
|
75 |
+ |
swent = swfaceVol : swent.Select2(True, 32) |
76 |
+ |
feat = featmanager.InsertSplitLineIntersect(7) |
77 |
+ |
If feat IsNot Nothing Then Exit For |
78 |
+ |
|
79 |
+ |
End If |
80 |
+ |
Next |
81 |
+ |
|
82 |
+ |
If feat Is Nothing Then |
83 |
+ |
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 |
84 |
+ |
End If |
85 |
+ |
|
86 |
+ |
Me.BodySweep.HideBody(True) |
87 |
+ |
|
88 |
+ |
' ajout des nouvelles faces |
89 |
+ |
Dim vfaces As Object = feat.GetFaces() |
90 |
+ |
swModel.EditRebuild3() |
91 |
+ |
|
92 |
+ |
For Each swfaceVol In vfaces ' sélectionne les faces découpées. |
93 |
+ |
If Not swfaceVol.GetBody Is Me.BodySweep Then |
94 |
+ |
sfaceVol.AjouterFace(swfaceVol) |
95 |
+ |
'là on a une connerie, la face originale n'est pas dans la liste des faces de vFaces |
96 |
+ |
'et le pointeur original semble détruit |
97 |
+ |
' puisque ajouterface ne créé pas de doubles, on va chercher des faces que l'on mettra dans la liste |
98 |
+ |
' la grosse face en fera automatiquement partie. |
99 |
+ |
Dim obj As Object = swfaceVol.GetEdges |
100 |
+ |
Dim aretes As sldworks.Edge = obj(0) |
101 |
+ |
Dim oBjfaces As Object = aretes.GetTwoAdjacentFaces2() |
102 |
+ |
Dim NewFaces As sldworks.Face2 = oBjfaces(0) |
103 |
+ |
sfaceVol.AjouterFace(NewFaces) |
104 |
+ |
NewFaces = oBjfaces(1) |
105 |
+ |
sfaceVol.AjouterFace(NewFaces) |
106 |
+ |
aretes = obj(1) |
107 |
+ |
NewFaces = oBjfaces(0) |
108 |
+ |
sfaceVol.AjouterFace(NewFaces) |
109 |
+ |
NewFaces = oBjfaces(1) |
110 |
+ |
sfaceVol.AjouterFace(NewFaces) |
111 |
+ |
End If |
112 |
+ |
Next |
113 |
+ |
|
114 |
+ |
' il faut trouver les faces internes et les tagger comme des faces de coque(pour les mini-poutres orientées) |
115 |
+ |
|
116 |
+ |
'Next poutre |
117 |
|
End Sub |
118 |
+ |
|
119 |
+ |
|
120 |
+ |
|
121 |
|
End Class |