ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/Commun.vb
Revision: 48
Committed: Wed Aug 22 21:18:12 2007 UTC (17 years, 8 months ago) by bournival
File size: 57763 byte(s)
Log Message:
On passe aux nouveaux .dll

File Contents

# Content
1 Imports SolidWorks.Interop
2 Imports SolidWorks.Interop.swconst
3 Imports SolidWorks.Interop.swpublished
4
5 Module Commun
6
7 Public Const Pi As Double = 3.1415926535897931
8 Public Epsilon As Double = 0.000000001 'à changer en fonction du type d'unité utilisé
9
10 Public Imax As Double = 1 ' valeur maximale de l'inertie.
11 Public Amax As Double = 1000 ' et de l'aire
12
13 Public NBAreteDoublon As Integer ' sais pas où d'autre ne peut mémoriser ce nombre...
14
15 Public swApp As SldWorks.SldWorks
16 Public swPart As SldWorks.PartDoc
17 Public swModel As SldWorks.ModelDoc2
18
19 Public lst_AreteVolume As New Collections.ObjectModel.Collection(Of SlyAreteVol) ' liste de courbes appartenant au volume
20 Public lst_AreteCoque As New Collections.ObjectModel.Collection(Of SlyAreteCoque) ' liste de courbes appartenant aux coques
21 Public lst_AretePoutre As New Collections.ObjectModel.Collection(Of SlyAretePoutre) ' liste de courbe libres
22 Public lst_FaceVolume As New Collections.ObjectModel.Collection(Of SlyFaceVolume) ' liste de faces appartenant au volume
23 Public lst_FaceCoque As New Collections.ObjectModel.Collection(Of SlyFaceCoque) ' liste de face libres
24 Public lst_SommetVolume As New Collections.ObjectModel.Collection(Of SlySommetVolume)
25 Public lst_SommetCoque As New Collections.ObjectModel.Collection(Of SlySommetCoque)
26 Public lst_sommetPoutre As New Collections.ObjectModel.Collection(Of SlySommetPoutre)
27
28 'Public lst_MiniPoutre As New Collection
29 Public lst_AreteDoublon As New Collection
30
31 'Public Structure AretesDoublon
32 ' Dim AreteVol As EncapArete
33 ' Dim AreteCoque As EncapArete
34 'End Structure
35
36
37 Public Structure sectionPoutre
38 Dim nom As String
39 Dim I1 As Double
40 Dim I2 As Double
41 Dim D1 As Double
42 Dim D2 As Double
43 Dim D3 As Double
44 Dim D4 As Double
45 Dim D5 As Double
46 Dim D6 As Double
47 Dim Aire As Double
48 End Structure
49
50
51 Public Enum tipe_e
52 Volume = 0
53 coque = 1
54 poutre = 2
55 MiniPoutre = 3
56 End Enum
57
58
59
60 'Public Sub Preparer_pour_Magic()
61 ' ' routine qui (en en appelant d'autres) génère les SlyClasses finales (avec les conditions aux limites
62 ' ' mais elle n'enregistre pas les infos dans les propriétés des entités.
63
64 ' Dim TypeAnno As Long
65 ' Dim Anno As SldWorks.Annotation
66 ' Dim Note As SldWorks.Note
67 ' Dim swEnt As SldWorks.Entity
68 ' Dim vAttEntArr As Object
69 ' Dim reponse As Integer
70 ' Dim textAnno As String
71 ' Dim lst_cal As New Collection
72 ' Dim i As Integer
73 ' Dim e As Integer
74
75
76 ' Call Commun.GenererListes()
77 'puisque l'on relit les annotations, il faut effacer les anciennes,
78 'Dim s1 As SlyAreteVol
79 'For Each s1 In lst_AreteVolume
80 ' s1.ResetCL()
81 'Next
82 'Dim s2 As SlyAreteCoque
83 'For Each s2 In lst_AreteCoque
84 ' s2.ResetCL()
85 'Next
86 'Dim s3 As SlyAretePoutre
87 'For Each s3 In lst_AretePoutre
88 ' s3.ResetCL()
89 'Next
90 'Dim s4 As SlyFaceVol
91 'For Each s4 In lst_FaceVolume
92 ' s4.ResetCL()
93 'Next
94 'Dim s5 As SlyFaceCoque
95 'For Each s5 In lst_FaceCoque
96 ' s5.ResetCL()
97 'Next
98 'Dim s6 As SlySommetVolume
99 'For Each s6 In lst_SommetVolume
100 ' s6.ResetCL()
101 'Next
102 'Dim s7 As SlySommetCoque
103 'For Each s7 In lst_SommetCoque
104 ' s7.ResetCL()
105 'Next
106 'Dim s8 As SlySommetPoutre
107 'For Each s8 In lst_sommetPoutre
108 ' s8.ResetCL()
109 'Next
110
111 'Anno = swModel.GetFirstAnnotation2
112
113 'Do While Not Anno Is Nothing
114 ' TypeAnno = Anno.GetType
115 ' If TypeAnno = 6 Then
116
117 ' Note = Anno.IGetSpecificAnnotation
118 ' vAttEntArr = Anno.GetAttachedEntities2
119
120 ' For e = 0 To UBound(vAttEntArr)
121
122 ' swEnt = vAttEntArr(e) ' 0 si on a juste une entité.
123
124 ' textAnno = Note.GetText
125 ' Select Case Mid(textAnno, 1, 3)
126 ' Case "Fx,", "Fy,", "Fz,", "Mx,", "My,", "Mz,", "Px,", "Py,", "Pz,", "Pn,", "Al,", "Au,", "Ar,", "Ux,", "Uy,", "Uz,", "Rx,", "Ry,", "Rz,", "Da,", "Dx,", "Dy,", "Dz,"
127 ' 'MsgBox "On a une bonne entité"
128
129 ' Dim cl As New CaL
130 ' 'cl.swEnt = swEnt
131 ' 'cl.TypeCL = Mid(Note.GetText, 1, 2)
132 ' For i = 4 To Len(textAnno) ' changer les virgules en point pour le val
133 ' If Mid(textAnno, i, 1) = "," Then Mid(textAnno, i, 1) = "."
134 ' Next i
135 ' 'cl.valeur = Val(Right(textAnno, Len(textAnno) - 3))
136
137 ' Dim enti As Object
138 ' enti = trouver(swEnt)
139 ' enti.addCaL(Mid(textAnno, 1, 2), Val(Right(textAnno, Len(textAnno) - 3)))
140 ' Case Else
141 ' reponse = MsgBox(" Une annotation a un texte qui n'est pas reconnu, " & Chr(13) & " si " & Note.GetText & Chr(13) & "doit être une condition limite alors il doit être modifié.", 65, "Condition aux limite non reconnue")
142 ' If reponse = 3 Then Exit Sub
143 ' End Select
144 ' Next e
145
146 ' End If
147
148 ' Anno = Anno.GetNext3
149 'Loop
150
151
152 ' maintenant on met des attributs sur les entités en fonction des conditions aux limites...
153
154 'For Each s1 In lst_AreteVolume
155 ' s1.MettreAttributPourConditionLimite()
156 'Next
157
158 'For Each s2 In lst_AreteCoque
159 ' s2.MettreAttributPourConditionLimite()
160 'Next
161
162 'For Each s3 In lst_AretePoutre
163 ' s3.MettreAttributPourConditionLimite()
164 'Next
165
166 'For Each s4 In lst_FaceVolume
167 ' s4.MettreAttributPourConditionLimite()
168 'Next
169
170 'For Each s5 In lst_FaceCoque
171 ' s5.MettreAttributPourConditionLimite()
172 'Next
173
174 'For Each s6 In lst_SommetVolume
175 ' s6.MettreAttributPourConditionLimite()
176 'Next
177
178 'For Each s7 In lst_SommetCoque
179 ' s7.MettreAttributPourConditionLimite()
180 'Next
181
182 'For Each s8 In lst_sommetPoutre
183 ' s8.MettreAttributPourConditionLimite()
184 'Next
185
186
187 ' End Sub
188
189 Public Sub GenererListes(Optional ByVal ChercheAttribut As Boolean = True)
190 ' sub qui créé les entités Sly... et le met dans les listes
191
192 Dim vBodies As Object
193 Dim swBody As SldWorks.Body2
194 Dim v As Integer
195 Dim swFace As SldWorks.Face2
196 Dim swLoop As SldWorks.Loop2
197 Dim swCoArete As SldWorks.CoEdge
198 Dim swArete As SldWorks.Edge
199 Dim swSommet1 As SldWorks.Vertex
200 Dim swSommet2 As SldWorks.Vertex
201 'Dim nouveau As Boolean ' bit qui dit si on est entrain d'updater (false) ou si on recommence du début (true)
202
203 ' on doit commencer par vider les listes, sinon on peut travailler sur les listes d'un autre fichier...
204 ' ne vérifie plus si on update ou si on recommence, ce n'est plus nécessaire.
205 Intersections.RegisterAttribut()
206
207 videliste()
208 Call SuperFace.reinitialiser() ' remet les compteurs à 0
209 Call SuperArete.reinitialiser()
210 Call SuperSommet.reinitialiser()
211
212 vBodies = swPart.GetBodies2(swconst.swBodyType_e.swSolidBody, True)
213 If Not vBodies Is Nothing Then
214 For v = 0 To UBound(vBodies)
215 swBody = vBodies(v)
216 swFace = swBody.GetFirstFace
217
218 Do While Not swFace Is Nothing
219 If trouver(swFace, tipe_e.Volume) Is Nothing Then
220 Dim slyface As New SlyFaceVolume(swFace)
221 lst_FaceVolume.Add(slyface)
222 End If
223
224
225 swLoop = swFace.GetFirstLoop
226 Do While Not swLoop Is Nothing
227
228 swCoArete = swLoop.GetFirstCoEdge
229 Dim coa As Integer
230 For coa = 0 To swLoop.GetEdgeCount - 1
231
232 swArete = swCoArete.GetEdge
233 If (Not Ignorer(swArete)) Then
234 If trouver(swArete, tipe_e.Volume, True) Is Nothing Then
235 Dim slyArete As New SlyAreteVol(swArete)
236 lst_AreteVolume.Add(slyArete)
237 End If
238
239 swSommet1 = swArete.GetStartVertex
240 If IsNothing(swSommet1) Then
241 'MsgBox("On a une courbe sans sommet")
242 Else
243 If (trouver(swSommet1, tipe_e.Volume) Is Nothing) Then
244 Dim slySommet As New SlySommetVolume(swSommet1)
245 lst_SommetVolume.Add(slySommet)
246 End If
247
248 swSommet2 = swArete.GetEndVertex
249 If (trouver(swSommet2, tipe_e.Volume) Is Nothing) Then
250 Dim slySommet As New SlySommetVolume(swSommet2)
251 lst_SommetVolume.Add(slySommet)
252 End If
253 End If
254
255 swCoArete = swCoArete.GetNext
256 End If
257 Next coa ' fin de loop sur les coaretes
258
259 swLoop = swLoop.GetNext
260 Loop ' fin loop sur loop
261
262 swFace = swFace.GetNextFace()
263 Loop ' fin loop sur faces
264 Next v ' next volume
265 End If ' s'il y a un corps (ou plus) on entre dans la boucle, sinon on continue sur les coques et poutres
266
267
268
269 ' on fait le tour des features pour avoir les poutres et les coques
270 Dim feat As SldWorks.Feature
271 Dim vSupprime As Object
272 Dim bSupprime As Boolean
273 Dim ent As SldWorks.Entity
274 Dim attr As SldWorks.Attribute
275
276
277 feat = swPart.FirstFeature
278
279 Do While Not feat Is Nothing
280
281 vSupprime = feat.IsSuppressed
282 bSupprime = CBool(vSupprime)
283 If Not bSupprime Then ' on vérifie que l'entité est pas supprimée
284
285 Select Case feat.GetTypeName
286 Case "CompositeCurve", "3DSplineCurve", "Helix" 'le feature est une courbe libre
287
288 Dim refCourbe As SldWorks.ReferenceCurve
289
290 refCourbe = feat.GetSpecificFeature2
291 swArete = refCourbe.GetFirstSegment
292 Do While Not swArete Is Nothing
293
294 If (Not Ignorer(swArete)) Then
295 Dim slyArete As SlyAretePoutre
296 slyArete = trouver(swArete, tipe_e.poutre)
297
298 If slyArete Is Nothing Then
299 slyArete = New SlyAretePoutre(swArete)
300 lst_AretePoutre.Add(slyArete)
301 End If
302
303 swSommet1 = swArete.GetStartVertex
304 If IsNothing(swSommet1) Then
305 'MsgBox("On a une courbe sans sommet")
306 Else
307 If trouver(swSommet1, tipe_e.poutre) Is Nothing Then
308 Dim slySommet As New SlySommetPoutre(swSommet1)
309 lst_sommetPoutre.Add(slySommet)
310 End If
311
312 swSommet2 = swArete.GetEndVertex
313 If trouver(swSommet2, tipe_e.poutre) Is Nothing Then
314 Dim slySommet As New SlySommetPoutre(swSommet2)
315 lst_sommetPoutre.Add(slySommet)
316 End If
317 End If
318
319 ' on cherche s'il n'y aurait pas un attribut sur la poutre
320 'If ChercheAttribut Then
321 Try
322 ent = swArete
323 attr = ent.FindAttribute(Intersections.DefAttrRCP1, 0)
324 slyArete.swAttribute = attr
325 If Left(attr.GetName, 4) = "Mini" Then swArete.Display(2, 1, 0, 1, True) Else swArete.Display(2, 0, 1, 0, True)
326 'Dim xyz() As Double
327 'xyz = slyarete.GetPoint3
328 'slyarete.X3 = xyz(0)
329 'slyarete.y3 = xyz(1)
330 'slyarete.z3 = xyz(2)
331 Catch ex As Exception
332 MsgBox("Une poutre sans attributs est détectée dans le modèle!")
333 End Try
334
335 End If
336
337 swArete = Nothing
338 swArete = refCourbe.GetNextSegment
339
340 Loop
341
342
343 Case "PLine", "ExtruRefSurface", "RevolvRefSurf", " SweepRefSurface", "BlendRefSurface", "OffsetRefSurface", "ExtendRefSurface", "PlanarSurface", "RadiateRefSurface", "MidRefSurface", "FillRefSurface"
344 ' le feature est une surface libre, certains types de surface n'ont pas été gardés car
345 ' leur face appartient à un autre feature ou parce qu'il sont impossible à retrouver dans un multimodèle
346
347
348 ' Attention, si c'est une PLine ça peut prendre un volume
349
350 Dim body As SldWorks.Body2
351 Dim vFaces As Object
352 Dim vf As Object
353 Dim slyFace As SlyFaceCoque
354
355 vFaces = feat.GetFaces
356 If Not vFaces Is Nothing Then
357 For Each vf In vFaces
358 swFace = vf
359 body = swFace.GetBody
360
361
362 If Not (body.GetType = swconst.swBodyType_e.swSolidBody) Then ' si le body est quelquechose de solide alors on a le feature Pline d'un solide....
363
364 slyFace = trouver(swFace, tipe_e.coque)
365 If slyFace Is Nothing Then
366
367 slyFace = New SlyFaceCoque(swFace)
368 lst_FaceCoque.Add(slyFace)
369 End If
370
371
372 ' ***** détection des attributs des coques
373 attr = Nothing
374 If ChercheAttribut Then
375 Try
376 ent = swFace
377 attr = ent.FindAttribute(Intersections.DefAttrRCCoque, 0)
378 slyFace.swAttribute = attr
379 Catch ex As Exception
380 MsgBox("Une coque sans attributs est détectée dans le modèle!")
381 End Try
382
383 If IsNothing(attr) Then ' on a trouvé un attribut de coque
384 'il n'y a pas encore d'attributs sur cette coque.
385 'MsgBox("Le putain d'attribut n'a pas été détecté!")
386 End If
387 End If
388
389 swLoop = swFace.GetFirstLoop
390 Do While Not swLoop Is Nothing
391 swCoArete = swLoop.GetFirstCoEdge
392 Dim coa As Integer
393 For coa = 0 To swLoop.GetEdgeCount - 1
394
395 swArete = swCoArete.GetEdge
396
397 If (Not Ignorer(swArete)) Then
398 If trouver(swArete, tipe_e.coque) Is Nothing Then
399 Dim slyArete As New SlyAreteCoque(swArete)
400 lst_AreteCoque.Add(slyArete)
401 End If
402
403 swSommet1 = swArete.GetStartVertex
404 If IsNothing(swSommet1) Then
405 'MsgBox("On a une courbe sans sommet")
406 Else
407 If trouver(swSommet1, tipe_e.coque) Is Nothing Then
408 Dim slySommet As New SlySommetCoque(swSommet1)
409 lst_SommetCoque.Add(slySommet)
410 End If
411
412 swSommet2 = swArete.GetEndVertex
413 If trouver(swSommet2, tipe_e.coque) Is Nothing Then
414 Dim slySommet As New SlySommetCoque(swSommet2)
415 lst_SommetCoque.Add(slySommet)
416 End If
417 End If
418
419 swCoArete = swCoArete.GetNext
420 End If
421 Next coa ' fin de loop sur les coaretes
422
423 swLoop = swLoop.GetNext
424 Loop ' fin loop sur loop
425 Else
426 'MsgBox("On vient de retirer une PLine appartenant à un volume!", MsgBoxStyle.Exclamation)
427 End If
428 Next vf
429 End If
430
431 Case Else ' n'est pas un feature intéressant...
432 ' rien
433 End Select
434 End If ' fin du if sur la suppression du feature
435 feat = feat.GetNextFeature
436 Loop
437
438 End Sub
439
440 Public Sub MettreNoms()
441 ' place les noms des SlyClasses sur les entités puis sauvegarde
442
443 'Debug.Write(" Title = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoTitle))
444 'Debug.Write(" Subject = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoSubject))
445 'Debug.Write(" Author = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoAuthor))
446 'Debug.Write(" Keywords = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoKeywords))
447 'Debug.Write(" Comment = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoComment))
448 'Debug.Write(" SavedBy = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoSavedBy))
449 'Debug.Write(" CreateDate = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoCreateDate))
450 'Debug.Write(" SaveDate = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoSaveDate))
451 'Debug.Write(" CreateDate2 = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoCreateDate2))
452 'Debug.Write(" SaveDate2 = " + swModel.SummaryInfo(SwConst.swSummInfoField_e.swSumInfoSaveDate2))
453 Static saveModel As SldWorks.ModelDoc2
454 Static passe As Boolean = False
455
456 If (swModel Is saveModel) And (passe = True) Then
457 Exit Sub ' faudrait pas passer 2 fois dans le mettrenoms...
458 Else
459 saveModel = swModel
460 End If
461 passe = True
462
463
464 'VideNom() ' on commence par enlever les noms (on suppose qu'il n'y en a pas déjà...)
465
466 Dim s1 As SlyAreteVol
467 For Each s1 In lst_AreteVolume
468 s1.SaveNom()
469 Next
470
471 Dim s2 As SlyAreteCoque
472 For Each s2 In lst_AreteCoque
473 s2.SaveNom()
474 Next
475
476 Dim s3 As SlyAretePoutre
477 For Each s3 In lst_AretePoutre
478 s3.SaveNom()
479 Next
480
481 Dim s4 As SlyFaceVolume
482 For Each s4 In lst_FaceVolume
483 s4.SaveNom()
484 Next
485
486 Dim s5 As SlyFaceCoque
487 For Each s5 In lst_FaceCoque
488 s5.SaveNom()
489 Next
490
491 Dim s6 As SlySommetVolume
492 For Each s6 In lst_SommetVolume
493 s6.SaveNom()
494 Next
495
496 Dim s7 As SlySommetCoque
497 For Each s7 In lst_SommetCoque
498 s7.SaveNom()
499 Next
500
501 Dim s8 As SlySommetPoutre
502 For Each s8 In lst_sommetPoutre
503 s8.SaveNom()
504 Next
505
506 End Sub
507
508 Public Sub videliste(Of T)(ByRef liste As Collections.Generic.List(Of T))
509 liste.Clear()
510 End Sub
511
512
513 Public Sub videliste()
514 lst_AreteVolume.Clear()
515 lst_AreteCoque.Clear()
516 lst_AretePoutre.Clear()
517 lst_FaceVolume.Clear()
518 lst_FaceCoque.Clear()
519 lst_SommetVolume.Clear()
520 lst_SommetCoque.Clear()
521 lst_SommetCoque.Clear()
522 lst_sommetPoutre.Clear()
523
524 End Sub
525
526 Public Function getNom(ByRef swEnt As SldWorks.Entity) As String
527 getNom = swPart.GetEntityName(swEnt)
528 End Function
529
530 Public Function getNom(ByRef swFace As SldWorks.Face2) As String
531 Dim swEnt As SldWorks.Entity
532 swEnt = swFace
533 getNom = swPart.GetEntityName(swEnt)
534 End Function
535
536 Public Function getNom(ByRef swArete As SldWorks.Edge) As String
537 Dim swEnt As SldWorks.Entity
538 swEnt = swArete
539 getNom = swPart.GetEntityName(swEnt)
540 End Function
541
542 Public Function getNom(ByRef swSommet As SldWorks.Vertex) As String
543 Dim swEnt As SldWorks.Entity
544 swEnt = swSommet
545 getNom = swPart.GetEntityName(swEnt)
546 End Function
547
548 Public Sub GererDossiers(ByRef nomDossier As String, ByRef NomFeature As String)
549 ' déplace un feature dans un dossier ( et créé le dossier si ce n'est pas déjà fait)
550
551
552 Static copienom As String
553 Dim swFeat As SldWorks.Feature
554 Dim ok As Boolean
555 Dim j As Integer
556
557 If Not StrComp(nomDossier, copienom) Then
558 ' on commence par vérifier qu'il n'est pas déjà créé
559
560 swFeat = swModel.FirstFeature
561
562 Do While Not swFeat Is Nothing
563 If swFeat.GetTypeName = "FtrFolder" And swFeat.Name = nomDossier Then GoTo suite
564 swFeat = swFeat.GetNextFeature
565 Loop
566
567 'on mémorise tout ce qui est sélectionné
568 Dim lst_selection As New Collection
569 Dim selMgr As SldWorks.SelectionMgr
570 selMgr = swModel.SelectionManager
571
572 For j = 1 To selMgr.GetSelectedObjectCount
573 lst_selection.Add(selMgr.GetSelectedObject5(j))
574 Next j
575 swModel.ClearSelection2(True)
576
577
578 Dim folder As SldWorks.Feature
579 Dim featMgr As SldWorks.FeatureManager
580 featMgr = swModel.FeatureManager
581 swModel.ClearSelection2(True)
582
583 ' on doit mettre le folder à la fin sinon le feature risque d'être avant un parent
584 j = 0
585 swFeat = swModel.FeatureByPositionReverse(0)
586 While Not ok
587 j = j + 1
588 If swFeat.GetTypeName = "ProfileFeature" Or swFeat.GetTypeName = "3DProfileFeature" Then swFeat = swModel.FeatureByPositionReverse(j) Else ok = True
589 End While
590 swFeat.Select(False)
591 folder = featMgr.InsertFeatureTreeFolder2(1)
592 If Not folder Is Nothing Then folder.Name = nomDossier
593 folder = Nothing
594 swPart.ReorderFeature(nomDossier, swFeat.Name)
595
596 folder = Nothing
597
598 ' on resélectionne les objets
599 swModel.ClearSelection2(True)
600 For j = 1 To lst_selection.Count
601 lst_selection.Item(j).select(True)
602 Next j
603
604 swPart.ReorderFeature(NomFeature, nomDossier)
605 End If
606
607 '1 - le dossier est créé ou a déjà été créé.
608 '2 - on redéplace le dossier à la fin.
609 suite:
610 swFeat = swModel.FeatureByPositionReverse(0)
611 swFeat.Select(False)
612 j = 0
613 While Not ok
614 j = j + 1
615 If swFeat.GetTypeName = "ProfileFeature" Or swFeat.GetTypeName = "3DProfileFeature" Then swFeat = swModel.FeatureByPositionReverse(j) Else ok = True
616 End While
617 swPart.ReorderFeature(nomDossier, swFeat.Name)
618 ' 3- on déplace le feature dans le dossier
619
620 swPart.ReorderFeature(NomFeature, nomDossier)
621 'swModel.EditRebuild3()
622
623
624 End Sub
625
626 Public Function trouver(ByRef swface As SldWorks.Face2, ByRef tipe As Commun.tipe_e) As Object
627 Dim face As SldWorks.Face2
628
629 Select Case tipe
630 Case tipe_e.Volume
631 Dim sface As SlyFaceVolume
632 For Each sface In lst_FaceVolume
633 'If swface Is sface.swFace Then trouver = sface : Exit Function
634
635 For Each face In sface.lst_Faces
636 If face Is swface Then Return sface
637 Next
638
639 Next sface
640
641 Case tipe_e.coque
642 Dim sface As SlyFaceCoque
643 For Each sface In lst_FaceCoque
644 'If swface Is sface.swFace Then trouver = sface : Exit Function
645 For Each face In sface.lst_Faces
646 If face Is swface Then Return sface
647 Next
648 Next sface
649 End Select
650 Return Nothing ' devrait pas passer par ici...
651 End Function
652
653 Public Function trouver(ByRef swEnt As SldWorks.Entity) As Object
654 Dim face As SldWorks.Face2
655 Select Case swEnt.GetType()
656 Case swconst.swSelectType_e.swSelFACES
657 Dim swface As SldWorks.Face2
658 Dim f As SlyFaceVolume
659 swface = swEnt
660 For Each f In lst_FaceVolume
661 'If f.SwFace Is swface Then Return f
662 For Each face In f.lst_Faces
663 If face Is swface Then Return f
664 Next
665 Next
666 Dim f2 As SlyFaceCoque
667 For Each f2 In lst_FaceCoque
668 'If f2.swFace Is swface Then Return f2
669 For Each face In f2.lst_Faces
670 If face Is swface Then Return f2
671 Next
672 Next
673
674
675 Case swconst.swSelectType_e.swSelEDGES
676 Dim swArete As SldWorks.Edge
677 swArete = swEnt
678 Dim test As Object
679 test = Commun.trouver(swArete, tipe_e.Volume)
680 If Not test Is Nothing Then Return test
681 test = Commun.trouver(swArete, tipe_e.coque)
682 If Not test Is Nothing Then Return test
683 test = Commun.trouver(swArete, tipe_e.poutre)
684 If Not test Is Nothing Then Return test
685
686
687
688 Case swconst.swSelectType_e.swSelVERTICES
689 Dim swSommet As SldWorks.Vertex
690 swSommet = swEnt
691
692 Dim s1 As SlySommetVolume
693 For Each s1 In lst_SommetVolume
694 If s1.swSommet Is swSommet Then Return s1
695 Next
696
697 Dim s2 As SlySommetCoque
698 For Each s2 In lst_SommetCoque
699 If s2.swSommet Is swSommet Then Return s2
700 Next
701
702 Dim s3 As SlySommetPoutre
703 For Each s3 In lst_sommetPoutre
704 If s3.swSommet Is swSommet Then Return s3
705 Next
706
707 End Select
708
709 MsgBox("Entité non trouvée, dans commun.trouver")
710 Return Nothing
711 End Function
712
713 ''' <summary>
714 ''' Function qui trouve et retourne le pointeur d'une SlyArete arète si elle existe déjà
715 ''' </summary>
716 ''' <param name="swArete">L'arète à retrouver</param>
717 ''' <param name="tipe">De quel type d'arrète il sagit</param>
718 ''' <param name="Genlist">Une option pour accélérer le calcul dans certaines circonstances</param>
719 ''' <returns>Le pointeur sur l'entité ou Nothing si elle est pas trouvée</returns>
720 ''' <remarks></remarks>
721 Public Function trouver(ByRef swArete As SldWorks.Edge, ByRef tipe As Commun.tipe_e, Optional ByRef Genlist As Boolean = False) As Object
722
723 Select Case tipe
724 Case tipe_e.Volume
725 Dim s As SlyAreteVol
726 For Each s In lst_AreteVolume
727 If swArete Is s.swArete Then Return s
728 Next s
729
730 ' ok, si on est ici c'est que l'on a pas trouvé l'arètequi nous intéresse, le pointeur a changé un peu...
731 If Not Genlist Then
732 Dim Testarete As New SuperArete(swArete, True)
733 For Each s In lst_AreteVolume
734 If Testarete.Comparer(s.swArete) Then Return s
735 Next s
736 End If
737
738 Case tipe_e.coque
739 Dim sArete As SlyAreteCoque
740 For Each sArete In lst_AreteCoque
741 If swArete Is sArete.swArete Then trouver = sArete : Exit Function
742 Next sArete
743
744 Case tipe_e.poutre
745 For Each sa As SlyAretePoutre In lst_AretePoutre
746 If sa.swArete Is swArete Then Return sa
747 Next
748
749
750 Case tipe_e.MiniPoutre
751 MsgBox("Erreur, on ne devrait plus passer par ici!")
752 'Dim sArete As SlyAretePoutre
753 'Dim i As Integer
754 'For i = 1 To lst_MiniPoutre.Count
755 ' sArete = lst_MiniPoutre.Item(i)
756 ' If swArete Is sArete.swArete Then trouver = sArete : Exit Function
757 'Next i
758 End Select
759 Return Nothing
760 End Function
761
762 Public Function trouver(ByRef Arete As SuperArete, ByRef tipe As Commun.tipe_e, Optional ByRef Genlist As Boolean = False) As Object
763
764 Select Case tipe
765 Case tipe_e.Volume
766 ' ok, si on est ici c'est que l'on a pas trouvé l'arètequi nous intéresse, le pointeur a changé un peu...
767 If Not Genlist Then
768 Dim s As SlyAreteVol
769 For Each s In lst_AreteVolume
770 If Arete.Comparer(s.swArete) Then Return s
771 Next s
772 End If
773
774 Case tipe_e.coque
775 Dim s As SlyAreteCoque
776 For Each s In lst_AreteCoque
777 If Arete.Comparer(s.swArete) Then Return s
778 Next s
779 End Select
780
781 Return Nothing
782 End Function
783
784 Public Function trouver(ByRef swSommet As SldWorks.Vertex, ByRef tipe As Commun.tipe_e) As Object
785
786 Select Case tipe
787 Case tipe_e.Volume
788 Dim sSommet As SlySommetVolume
789 For Each sSommet In lst_SommetVolume
790 If swSommet Is sSommet.swSommet Then trouver = sSommet : Exit Function
791 Next sSommet
792
793 Case tipe_e.coque
794 Dim sSommet As SlySommetCoque
795 For Each sSommet In lst_SommetCoque
796 If swSommet Is sSommet.swSommet Then trouver = sSommet : Exit Function
797 Next sSommet
798
799 Case tipe_e.poutre
800 Dim sSommet As SlySommetPoutre
801 For Each sSommet In lst_sommetPoutre
802 If swSommet Is sSommet.swSommet Then trouver = sSommet : Exit Function
803 Next sSommet
804
805 End Select
806 Return Nothing
807 End Function
808
809 Public Sub VideNom()
810 ' procédure qui retire le nom écrit sur les entités de solidworks
811
812 Dim vNamedEntity As Object = Nothing
813 Dim swEnt As SldWorks.Entity
814 Dim retval As Boolean
815 Dim i As Integer
816
817 'If MsgBox("Essayer de vider les noms?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then Exit Sub
818
819 Try
820 'MsgBox(swPart.MaterialIdName)
821 vNamedEntity = swPart.GetNamedEntities
822 Catch
823 Dim nb As String
824 Try
825 nb = CStr(swPart.GetNamedEntitiesCount())
826 Catch
827 nb = "??"
828 End Try
829
830 MsgBox("Impossibilité d'obtenir la liste des entités déjà nomées. On continue pareil..." & vbCr & "Il y a " & "??" & " entités qui ont un nom", MsgBoxStyle.Exclamation, "Sérieux problème!")
831 End Try
832
833
834 If IsNothing(vNamedEntity) Then Exit Sub
835 For i = 0 To UBound(vNamedEntity)
836 swEnt = vNamedEntity(i)
837 Debug.Write(swPart.GetEntityName(swEnt))
838 retval = swPart.DeleteEntityName(swEnt)
839 If retval = False Then Debug.Write("Incapable d'effacer l'entité: " & swPart.GetEntityName(swEnt)) ' MsgBox(" Incapable d'effacer l'entité: " & swPart.GetEntityName(swEnt), vbCritical, "Problème dans VideNom()")
840 Next i
841 End Sub
842
843 'function qui transfert les coordonnées du modèle en coodronnées pour le sketch
844 Public Function TransfertModelSketch(ByRef sketch As SldWorks.Sketch, ByRef p() As Double) As Double()
845 Dim MathUtil As SldWorks.MathUtility
846 Dim MathP As SldWorks.MathPoint
847 Dim MathTrans As SldWorks.MathTransform
848 Dim p2() As Double
849 MathUtil = swApp.GetMathUtility
850 MathP = MathUtil.CreatePoint(p)
851
852 MathTrans = sketch.ModelToSketchTransform
853 MathP = MathP.MultiplyTransform(MathTrans)
854 p2 = MathP.ArrayData
855 Return p2
856 End Function
857
858
859 Public Function TransfertSketchToModel(ByRef sketch As SldWorks.Sketch, ByRef p() As Double) As Double()
860 Dim MathUtil As SldWorks.MathUtility
861 Dim MathP As SldWorks.MathPoint
862 Dim MathTrans As SldWorks.MathTransform
863 Dim p2() As Double
864 Dim point(2) As Double
865 Dim vPoint As Object
866 MathUtil = swApp.GetMathUtility
867 point(0) = p(0)
868 point(1) = p(1)
869 point(2) = 0
870 vPoint = point
871 MathP = MathUtil.CreatePoint(vPoint)
872
873 MathTrans = sketch.ModelToSketchTransform
874 MathTrans = MathTrans.Inverse
875 MathP = MathP.MultiplyTransform(MathTrans)
876 vPoint = MathP.ArrayData
877 p2 = vPoint
878 Return p2
879 End Function
880
881
882 Public Function DistanceMin(ByRef sCoque As SlyFaceCoque, ByRef sVolume As SlyFaceVolume) As Double
883 Dim swFC As SldWorks.Face2
884 Dim swFV As SldWorks.Face2
885 Dim min As Double = 99999999999999
886 Dim temp As Double
887
888 For Each swFC In sCoque.lst_Faces
889 For Each swFV In sVolume.lst_Faces
890 temp = swModel.ClosestDistance(swFC, swFV, Nothing, Nothing)
891 If temp < min Then min = temp
892 Next
893 Next
894 Return min
895 End Function
896
897
898
899
900 Public Function Distance(ByRef somm As SldWorks.Vertex, ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
901 Dim vpoints As Object
902 Dim dPoint() As Double
903 Dim temp As Double
904 vpoints = somm.GetPoint()
905 dPoint = vpoints
906
907 temp = (dPoint(0) - x) * (dPoint(0) - x) + (dPoint(1) - y) * (dPoint(1) - y) + (dPoint(2) - z) * (dPoint(2) - z)
908 Return Math.Sqrt(temp)
909
910 End Function
911
912 Public Function Distance(ByRef Arete As SldWorks.Edge, ByRef x As Double, ByRef y As Double, ByRef z As Double) As Double
913 Dim vpoints As Object
914 Dim dPoint() As Double
915 Dim temp As Double
916 vpoints = Arete.GetClosestPointOn(x, y, z)
917 dPoint = vpoints
918
919 temp = (dPoint(0) - x) * (dPoint(0) - x) + (dPoint(1) - y) * (dPoint(1) - y) + (dPoint(2) - z) * (dPoint(2) - z)
920
921 Return Math.Sqrt(temp)
922
923 End Function
924
925 Public Function Distance(ByRef Arete As SldWorks.Edge, ByRef P() As Double) As Double
926 Dim vpoints As Object
927 Dim dPoint() As Double
928 Dim temp As Double
929 vpoints = Arete.GetClosestPointOn(P(0), P(1), P(2))
930 dPoint = vpoints
931
932 temp = (dPoint(0) - P(0)) * (dPoint(0) - P(0)) + (dPoint(1) - P(1)) * (dPoint(1) - P(1)) + (dPoint(2) - P(2)) * (dPoint(2) - P(2))
933
934 Return Math.Sqrt(temp)
935
936 End Function
937
938
939 Public Function Distance(ByRef Courbe As SldWorks.Curve, ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
940 Dim vpoints As Object
941 Dim dPoint() As Double
942 Dim temp As Double
943 vpoints = Courbe.GetClosestPointOn(x, y, z)
944 dPoint = vpoints
945
946 temp = (dPoint(0) - x) * (dPoint(0) - x) + (dPoint(1) - y) * (dPoint(1) - y) + (dPoint(2) - z) * (dPoint(2) - z)
947
948 Return Math.Sqrt(temp)
949 End Function
950
951
952 Public Function Distance(ByRef Face As SldWorks.Face2, ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
953 Dim vpoints As Object
954 Dim dPoint() As Double
955 Dim temp As Double
956 vpoints = Face.GetClosestPointOn(x, y, z)
957 dPoint = vpoints
958
959 temp = (dPoint(0) - x) * (dPoint(0) - x) + (dPoint(1) - y) * (dPoint(1) - y) + (dPoint(2) - z) * (dPoint(2) - z)
960
961 Return Math.Sqrt(temp)
962
963 End Function
964
965
966 Public Function Distance(ByRef Face As SldWorks.Face2, ByRef sommet As SldWorks.Vertex) As Double
967 Dim vpoints As Object
968 Dim dPoint() As Double
969 Dim temp As Double
970 Dim x As Double, y As Double, z As Double
971
972
973 vpoints = sommet.GetPoint()
974 dPoint = vpoints
975 x = dPoint(0) : y = dPoint(1) : z = dPoint(2)
976
977 vpoints = Face.GetClosestPointOn(x, y, z)
978 dPoint = vpoints
979
980 temp = (dPoint(0) - x) * (dPoint(0) - x) + (dPoint(1) - y) * (dPoint(1) - y) + (dPoint(2) - z) * (dPoint(2) - z)
981
982 Return Math.Sqrt(temp)
983
984 End Function
985
986
987 Public Function distance(ByRef s1 As SldWorks.Vertex, ByRef s2 As SldWorks.Vertex) As Double
988
989 Dim vpoints As Object
990 Dim dPoint() As Double
991 Dim dPoint2() As Double
992 Dim temp As Double
993
994 vpoints = s1.GetPoint()
995 dPoint = vpoints
996
997 vpoints = s2.GetPoint()
998 dPoint2 = vpoints
999
1000 temp = (dPoint(0) - dPoint2(0)) * (dPoint(0) - dPoint2(0)) + (dPoint(1) - dPoint2(1)) * (dPoint(1) - dPoint2(1)) + (dPoint(2) - dPoint2(2)) * (dPoint(2) - dPoint2(2))
1001 Return Math.Sqrt(temp)
1002
1003 End Function
1004
1005 Public Function Distance(ByRef X1 As Double, ByRef Y1 As Double, ByRef Z1 As Double, ByRef X2 As Double, ByRef Y2 As Double, ByRef Z2 As Double) As Double
1006 Return Math.Sqrt((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2 + (Z2 - Z1) ^ 2)
1007 End Function
1008
1009
1010 Public Function distance(ByRef P1() As Double, ByRef P2() As Double) As Double
1011 If Not UBound(P1) = 2 And Not UBound(P2) = 2 Then MsgBox("Cette fonction de distance ne marche qu'en 3D pour l'instant")
1012 Return Math.Sqrt((P1(0) - P2(0)) ^ 2 + (P1(1) - P2(1)) ^ 2 + (P1(2) - P2(2)) ^ 2)
1013 End Function
1014
1015
1016 Public Function distance(ByRef P1() As Double, ByRef s2 As SldWorks.Vertex) As Double
1017
1018 Dim vpoints As Object
1019 Dim dPoint() As Double
1020 Dim dPoint2() As Double
1021 Dim temp As Double
1022
1023
1024 dPoint = P1
1025
1026 vpoints = s2.GetPoint()
1027 dPoint2 = vpoints
1028
1029 temp = (dPoint(0) - dPoint2(0)) * (dPoint(0) - dPoint2(0)) + (dPoint(1) - dPoint2(1)) * (dPoint(1) - dPoint2(1)) + (dPoint(2) - dPoint2(2)) * (dPoint(2) - dPoint2(2))
1030 Return Math.Sqrt(temp)
1031
1032 End Function
1033
1034 Public Function Distance(ByRef s1 As SlySommetPoutre, ByRef s2 As SlySommetCoque) As Double
1035 Return Distance(s1.swSommet, s2.swSommet)
1036 End Function
1037
1038 Public Function Distance(ByRef s1 As SlySommetPoutre, ByRef s2 As SlySommetVolume) As Double
1039 Return Distance(s1.swSommet, s2.swSommet)
1040 End Function
1041
1042
1043 Public Function Distance(ByRef s1 As SlySommetPoutre, ByRef s2 As SlySommetPoutre) As Double
1044 Return Distance(s1.swSommet, s2.swSommet)
1045 End Function
1046
1047 Public Function GetLongueurArete(ByRef swArete As SldWorks.Edge) As Double
1048 Dim swCourbe As SldWorks.Curve
1049 Dim temp As Object
1050 Dim T1 As Double, T2 As Double
1051 Dim sommet As SldWorks.Vertex
1052 Dim point As Object
1053
1054 swCourbe = swArete.GetCurve
1055
1056 sommet = swArete.GetStartVertex()
1057
1058 If sommet IsNot Nothing Then
1059 point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T1 = temp(0)
1060 sommet = swArete.GetEndVertex() : point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T2 = temp(0)
1061 Return swCourbe.GetLength2(T1, T2)
1062
1063 Else
1064 'l'arète est fermée.
1065 Dim params() As Double
1066 If swCourbe.IsCircle Then
1067 params = swCourbe.CircleParams
1068 Return params(7) * Pi * 2
1069 End If
1070 MsgBox("On demande la longueur d'une courbe fermée qui n'est pas un cercle... ce n'est pas encore programmé car ça ne devrait pas arriver.")
1071 End If
1072
1073 End Function
1074
1075
1076 ''' <summary>
1077 ''' Function qui retourne le paramètreT du milieu de l'arète
1078 ''' </summary>
1079 ''' <param name="swSrete">L'arète en question</param>
1080 ''' <returns>Le paramètre T de l acourbe</returns>
1081 ''' <remarks>Si la courbe est fermée, la fonction retourne auqnd ême le T milieu. i.e. T = pi</remarks>
1082 Public Function GetTMilieu(ByRef swArete As SldWorks.Edge) As Double
1083 Dim swCourbe As SldWorks.Curve
1084 Dim temp As Object
1085 Dim T1 As Double, T2 As Double
1086 Dim sommet As SldWorks.Vertex
1087 Dim point As Object
1088
1089 swCourbe = swArete.GetCurve
1090
1091 sommet = swArete.GetStartVertex()
1092
1093 If sommet IsNot Nothing Then
1094 point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T1 = temp(0)
1095 sommet = swArete.GetEndVertex() : point = sommet.GetPoint() : temp = swArete.GetParameter(point(0), point(1), point(2)) : T2 = temp(0)
1096 Return (T1 + T2) / 2
1097
1098 Else
1099 'l'arète est fermée.
1100 If swCourbe.IsCircle Then
1101 Return Pi
1102 End If
1103 MsgBox("On demande la longueur d'une courbe fermée qui n'est pas un cercle... ce n'est pas encore programmé car ça ne devrait pas arriver.")
1104 End If
1105
1106
1107
1108 End Function
1109
1110 'Procédure qui repère les arètes avec des atributs et leur met une couleur
1111 Public Sub ColorerAretes()
1112 ' on fait le tour des features pour avoir les poutres et les coques
1113 Dim feat As SldWorks.Feature
1114 Dim vSupprime As Object
1115 Dim bSupprime As Boolean
1116 Dim ent As SldWorks.Entity
1117 Dim attr As SldWorks.Attribute
1118 Dim swArete As SldWorks.Edge
1119 'RealConstant.RegisterAttribut()
1120 'RealConstant.RCCode.RegisterAttribut()
1121
1122 swModel.EditRebuild3()
1123
1124 feat = swPart.FirstFeature
1125
1126 Do While Not feat Is Nothing
1127
1128 vSupprime = feat.IsSuppressed
1129 bSupprime = CBool(vSupprime)
1130 If Not bSupprime Then ' on vérifie que l'entité est pas supprimée
1131
1132 Select Case feat.GetTypeName
1133 Case "CompositeCurve", "3DSplineCurve", "Helix" 'le feature est une courbe libre
1134
1135 Dim refCourbe As SldWorks.ReferenceCurve
1136
1137 refCourbe = feat.GetSpecificFeature2
1138 swArete = refCourbe.GetFirstSegment
1139 Do While Not swArete Is Nothing
1140 Try
1141 ent = swArete
1142 attr = ent.FindAttribute(Intersections.DefAttrRCP1, 0)
1143 If Left(attr.GetName, 4) = "Mini" Then swArete.Display(2, 1, 0, 1, True) Else swArete.Display(2, 0, 1, 0, True)
1144 Catch ex As Exception
1145
1146 End Try
1147
1148 swArete = Nothing
1149 swArete = refCourbe.GetNextSegment
1150 Loop
1151 End Select
1152
1153 End If ' fin du if sur la suppression du feature
1154 feat = feat.GetNextFeature
1155 Loop
1156 End Sub
1157
1158 ' procédure de débuggage qui place un point là où on le demande. (avec un sketch3D)
1159 Public Sub MettreUnPoint(ByRef x As Double, ByRef y As Double, ByRef z As Double, Optional ByVal Selection As Boolean = False)
1160 Dim point As SldWorks.SketchPoint
1161 swModel.Insert3DSketch2(True)
1162 point = swModel.CreatePoint2(x, y, z)
1163 swModel.Insert3DSketch2(False)
1164 'swModel.EditRebuild3()
1165 If Selection Then
1166 point.Select2(False, 0)
1167 End If
1168 End Sub
1169
1170 Public Function MettreUnPoint(ByRef Plan As SldWorks.RefPlane, ByRef x As Double, ByRef y As Double, ByRef z As Double) As SldWorks.SketchPoint
1171 Dim swent As SldWorks.Entity
1172 Dim p(2) As Double
1173 p(0) = x
1174 p(1) = y
1175 p(2) = z
1176 swent = Plan
1177 swent.Select4(False, Nothing)
1178 swModel.InsertSketch2(True)
1179 p = Commun.TransfertModelSketch(swModel.GetActiveSketch2(), p)
1180 MettreUnPoint = swModel.CreatePoint2(p(0), p(1), p(2))
1181 swModel.InsertSketch2(False)
1182 swModel.EditRebuild3()
1183 End Function
1184
1185 Public Function MettreUneLigne(ByRef Plan As SldWorks.RefPlane, ByRef x1 As Double, ByRef y1 As Double, ByRef z1 As Double, ByRef x2 As Double, ByRef y2 As Double, ByRef z2 As Double) As SldWorks.SketchSegment
1186 Dim swent As SldWorks.Entity
1187 Dim p(2) As Double, p2(2) As Double
1188 p(0) = x1 : p(1) = y1 : p(2) = z1
1189 p2(0) = x2 : p2(1) = y2 : p2(2) = z2
1190 swent = Plan
1191 swent.Select4(False, Nothing)
1192 swModel.InsertSketch2(True)
1193 p = Commun.TransfertModelSketch(swModel.GetActiveSketch2(), p)
1194 p2 = Commun.TransfertModelSketch(swModel.GetActiveSketch2(), p2)
1195 MettreUneLigne = swModel.CreateLine2(p(0), p(1), p(2), p2(0), p2(1), p2(2))
1196 swModel.InsertSketch2(False)
1197 swModel.EditRebuild3()
1198 End Function
1199
1200 Public Function MettreUneLigne(ByRef face As SldWorks.Face2, ByRef x1 As Double, ByRef y1 As Double, ByRef z1 As Double, ByRef x2 As Double, ByRef y2 As Double, ByRef z2 As Double) As SldWorks.SketchSegment
1201 Dim swent As SldWorks.Entity
1202 Dim p(2) As Double, p2(2) As Double
1203 p(0) = x1 : p(1) = y1 : p(2) = z1
1204 p2(0) = x2 : p2(1) = y2 : p2(2) = z2
1205 swent = face
1206 swent.Select4(False, Nothing)
1207 swModel.InsertSketch2(True)
1208 p = Commun.TransfertModelSketch(swModel.GetActiveSketch2(), p)
1209 p2 = Commun.TransfertModelSketch(swModel.GetActiveSketch2(), p2)
1210 MettreUneLigne = swModel.CreateLine2(p(0), p(1), p(2), p2(0), p2(1), p2(2))
1211 swModel.InsertSketch2(False)
1212 swModel.EditRebuild3()
1213 End Function
1214
1215
1216
1217
1218
1219
1220 Public Sub EffacerAnnoEtCoord()
1221 Dim anno As SldWorks.Annotation
1222 Dim ent As SldWorks.Entity
1223 Dim prochainAnno As SldWorks.Annotation
1224
1225 anno = swModel.GetFirstAnnotation2
1226
1227 Do While Not anno Is Nothing
1228 anno.Select(False)
1229 prochainAnno = anno.GetNext3()
1230 swModel.EditDelete()
1231 anno = prochainAnno
1232 Loop
1233
1234
1235 ' parcours des features pour éliminer les Points3
1236 Dim feat As SldWorks.Feature
1237 Dim nextfeat As SldWorks.Feature
1238 feat = swPart.FirstFeature
1239
1240 Do While Not feat Is Nothing
1241 If feat.GetTypeName = "CoordSys" Then
1242 nextfeat = feat.GetNextFeature
1243 ent = feat
1244 ent.Select2(False, Nothing)
1245 swModel.EditDelete()
1246 feat = nextfeat
1247 Else
1248 feat = feat.GetNextFeature()
1249 End If
1250 Loop
1251
1252
1253 End Sub
1254
1255 Sub MettreAttributPourFaceInterne(ByRef swFaceInterne As SldWorks.Face2)
1256 ' Sub qui place l'attribut de faceinterne sur une face
1257 Dim attr As SldWorks.Attribute
1258 Dim swent As SldWorks.Entity
1259 Static no As Integer = 1
1260 Dim nom2 As String
1261
1262 nom2 = "FaceInterne #" & no
1263 swent = swFaceInterne
1264 attr = swent.FindAttribute(Intersections.DefAttrFaceInterne, 0) ' si l'attribut existe déjà on pointe dessus.
1265
1266 If attr Is Nothing Then attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFaceInterne, nom2, 0, 2) ' 0 = swThisconfig
1267
1268 While attr Is Nothing
1269 nom2 = "FaceInterne" & CStr(no)
1270 attr = Intersections.DefAttrFaceInterne.CreateInstance5(swModel, swFaceInterne, nom2, 0, 0)
1271 no += 1
1272 End While
1273 GererDossiers("FaceInternes", nom2)
1274 no += 1
1275 End Sub
1276
1277 Private Function Ignorer(ByRef swArete As SldWorks.Edge) As Boolean
1278 Dim attr As SldWorks.Attribute
1279 Dim SwEnt As SldWorks.Entity
1280 Dim p As SldWorks.Parameter
1281 SwEnt = swArete
1282 attr = SwEnt.FindAttribute(DefAttrRCP1, 0)
1283 If attr Is Nothing Then Return False
1284 p = attr.GetParameter("D1")
1285 If p.GetDoubleValue = -9 Then Return True Else Return False
1286 End Function
1287
1288 Public Sub GetMidPointSegment(ByVal seg As SldWorks.SketchSegment, ByRef x As Double, ByRef y As Double, ByRef z As Double)
1289 Dim curve As SldWorks.Curve
1290 Dim start As Double
1291 Dim pend As Double
1292 Dim isClosed As Boolean
1293 Dim isPeriodic As Boolean
1294 Dim milieu As Double
1295 Dim vXYZ As Object
1296 Dim xyz(2) As Double
1297
1298 curve = seg.GetCurve
1299 curve.GetEndParams(start, pend, isClosed, isPeriodic)
1300
1301 milieu = (pend + start) / 2
1302
1303 vXYZ = curve.Evaluate(milieu)
1304
1305 xyz = vXYZ
1306
1307 x = xyz(0) : y = xyz(1) : z = xyz(2)
1308
1309 End Sub
1310
1311 Public Sub SelectFaceByName(ByVal Nom As String, Optional ByVal append As Boolean = False)
1312 Dim swent As SldWorks.Entity
1313 swent = swPart.GetEntityByName(Nom, swconst.swSelectType_e.swSelFACES)
1314 swent.Select4(append, Nothing)
1315 End Sub
1316
1317 Public Sub SelectAreteByName(ByVal Nom As String, Optional ByVal append As Boolean = False)
1318 Dim swent As SldWorks.Entity
1319 swent = swPart.GetEntityByName(Nom, swconst.swSelectType_e.swSelEDGES)
1320 swent.Select4(append, Nothing)
1321 End Sub
1322
1323 Public Sub SelectSommetByName(ByVal Nom As String, Optional ByVal append As Boolean = False)
1324 Dim swent As SldWorks.Entity
1325 swent = swPart.GetEntityByName(Nom, swconst.swSelectType_e.swSelVERTICES)
1326 swent.Select4(append, Nothing)
1327 End Sub
1328
1329 Public Function DessineCourbe(ByRef curve As SldWorks.Curve) As SldWorks.SketchSegment
1330 Dim modeler As SldWorks.Modeler
1331 Dim vp1 As Object : Dim P1() As Double
1332 Dim vp2 As Object : Dim P2() As Double
1333 Dim dir(2) As Double
1334 Dim sketchseg As SldWorks.SketchSegment = Nothing
1335 Dim i As Integer
1336 Dim Tmax As Double, Tmin As Double
1337 Dim ajout As Double
1338
1339 Dim isPeriodic As Boolean : Dim isClosed As Boolean
1340
1341 If curve.IsTrimmedCurve Then
1342 If curve.IsLine Then
1343 swModel.Insert3DSketch2(False)
1344 curve.GetEndParams(Tmin, Tmax, isClosed, isPeriodic)
1345 vp1 = curve.Evaluate(Tmin)
1346 vp2 = curve.Evaluate(Tmax)
1347 sketchseg = swModel.CreateLine2(vp1(0), vp1(1), vp1(2), vp2(0), vp2(1), vp2(2))
1348 swModel.Insert3DSketch2(False)
1349 Return sketchseg
1350 End If
1351
1352 Else
1353 curve.GetEndParams(Tmin, Tmax, isClosed, isPeriodic)
1354 modeler = swApp.GetModeler
1355 swModel.Insert3DSketch2(False)
1356 ajout = (Tmax - Tmin) / 100
1357 vp1 = curve.Evaluate(Tmin) : P1 = vp1
1358 For i = 1 To 100
1359 vp2 = curve.Evaluate(Tmin + i * ajout) : P2 = vp2
1360 sketchseg = swModel.CreateLine2(P1(0), P1(1), P1(2), P2(0), P2(1), P2(2))
1361 P1 = P2
1362 Next i
1363 swModel.Insert3DSketch2(False)
1364
1365 'modeler = swApp.GetModeler
1366 'For i = 1 To 100
1367 ' vp2 = curve.Evaluate(Tmin + i * ajout)
1368 ' modeler.CreateLine(vp1, vp2)
1369 ' vp1 = vp2
1370 'Next i
1371 Return sketchseg
1372 End If
1373 Return Nothing
1374 End Function
1375
1376 Function AngleEntre2Faces(ByRef swface1 As SldWorks.Face2, ByRef swface2 As SldWorks.Face2, ByRef P() As Double) As Double
1377 ' function qui trouve l'angle entre 2 faces au point spécifié...
1378 Return AngleEntre2Faces(swface1, swface2, P(0), P(1), P(2))
1379 End Function
1380
1381 Function AngleEntre2Faces(ByRef swface1 As SldWorks.Face2, ByRef swface2 As SldWorks.Face2, ByRef x As Double, ByRef y As Double, ByRef z As Double) As Double
1382 ' function qui trouve l'angle entre 2 faces au point spécifié...
1383 Dim swSurf As SldWorks.Surface
1384 Dim retval As Object
1385 Dim Normale1(2) As Double
1386 Dim Normale2(2) As Double
1387
1388 swSurf = swface1.GetSurface
1389 retval = swSurf.EvaluateAtPoint(x, y, z)
1390 Normale1(0) = retval(0) : Normale1(1) = retval(1) : Normale1(2) = retval(2)
1391
1392 swSurf = swface2.GetSurface
1393 retval = swSurf.EvaluateAtPoint(x, y, z)
1394 Normale2(0) = retval(0) : Normale2(1) = retval(1) : Normale2(2) = retval(2)
1395
1396 Return Outils_Math.Angle2Vecteurs(Normale1, Normale2)
1397 End Function
1398
1399
1400
1401
1402
1403 Public Sub Test()
1404 ' se déclenche quand on apuie sur le bouton 4
1405
1406 Dim lst As New Collections.ObjectModel.Collection(Of SldWorks.Vertex)
1407
1408 Intersections.RegisterAttribut()
1409
1410 swModel.EditRebuild3()
1411 ' on fait le tour des features pour avoir les poutres et les coques
1412 Dim feat As SldWorks.Feature
1413 Dim vSupprime As Object
1414 Dim bSupprime As Boolean
1415 Dim attr As SldWorks.Attribute
1416 Dim swArete As SldWorks.Edge
1417 Dim swSommet1 As SldWorks.Vertex
1418 Dim swSommet2 As SldWorks.Vertex
1419
1420 feat = swPart.FirstFeature
1421
1422 Do While Not feat Is Nothing
1423
1424 vSupprime = feat.IsSuppressed
1425 bSupprime = CBool(vSupprime)
1426 If Not bSupprime Then ' on vérifie que l'entité est pas supprimée
1427
1428 Select Case feat.GetTypeName
1429 Case "CompositeCurve", "3DSplineCurve", "Helix" 'le feature est une courbe libre
1430
1431 Dim refCourbe As SldWorks.ReferenceCurve
1432 refCourbe = feat.GetSpecificFeature2
1433 swArete = refCourbe.GetFirstSegment
1434 Do While Not swArete Is Nothing
1435
1436 If (Not Ignorer(swArete)) Then
1437
1438 swSommet1 = swArete.GetStartVertex
1439 lst.Add(swSommet1)
1440
1441 If IsNothing(swSommet1) Then
1442 'MsgBox("On a une courbe sans sommet")
1443 Else
1444 swSommet2 = swArete.GetEndVertex
1445 lst.Add(swSommet2)
1446 End If
1447 End If
1448
1449 swArete = Nothing
1450 swArete = refCourbe.GetNextSegment
1451
1452 Loop
1453
1454 Case Else ' n'est pas un feature intéressant...
1455 ' rien
1456 End Select
1457 End If ' fin du if sur la suppression du feature
1458 feat = feat.GetNextFeature
1459 Loop
1460
1461
1462 Dim swEnt As SldWorks.Entity
1463 For Each s As SldWorks.Vertex In lst
1464 swEnt = s
1465 attr = swEnt.FindAttribute(DefAttrDoublon, 0)
1466 If Not attr Is Nothing Then
1467 Dim p As SldWorks.Parameter = attr.GetParameter("Maitre")
1468 MsgBox(p.GetStringValue)
1469 End If
1470 Next
1471
1472
1473
1474
1475 End Sub
1476
1477
1478
1479
1480
1481 End Module