ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magicsld/Commun.vb
Revision: 40
Committed: Mon Aug 20 21:30:28 2007 UTC (17 years, 9 months ago) by bournival
File size: 57657 byte(s)
Log Message:
Projet de these de Sylvain Bournival. Attention projet VB.

File Contents

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