Si je comprend bien, la macro fonctionne sauf pour les tolérances géométriques. Dans ce cas remplace: Set swAnn = swGtol.Gtol par : Set swAnn = swGtol.GetAnnotation
2. Je dois également sélectionner toutes les tables présentent dans ma Mise en plan.
Y a t il une ligne de commande pour identifier toutes les tables?
3.Est t il possible de sélectionner tous les dimensions ,annotations, tolérances, table.... avec la macro que j'utilise ? Ctrl A n est pas pris en compte par l enregistreur de macro.
ElseIf TypeOf swSelObj Is SldWorks.DatumTag Then
Dim swDatum As SldWorks.DatumTag
Set swDatum = swSelObj
Set swAnn = swDatum.GetAnnotation
swAnn.Layer = layerName
2. pour traverser les tables tu peux utiliser GetTableAnnotations
GetTableAnnotations retourne une liste. Il faut ensuite traiter chacune individuellement.
Dim swView As SldWorks.View
Dim swTables As Variant
Dim swTable As Variant
Dim swTableAnn As SldWorks.TableAnnotation
Set swView = swDraw.GetFirstView
If swView.GetTableAnnotationCount > 0 Then
swTables = swView.GetTableAnnotations
For Each swTable In swTables
Set swTableAnn = swTable
Set swAnn = swTableAnn.GetAnnotation
swAnn.Layer = layerName
next
End If
Pour mettre sur un calque spécifique chaque table, annotation, dimension, segment, etc... de chaque feuille et chaque vue, sans avoir à les sélectionner, essaye ca:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim vSheets As Variant
Dim vSheet As Variant
Dim swView As SldWorks.View
Dim swAnn As SldWorks.Annotation
Dim swNote As SldWorks.Note
Dim swDispDim As SldWorks.DisplayDimension
Dim swGtol As SldWorks.Gtol
Dim swDatum As SldWorks.DatumTag
Dim swAnnSFSymbol As SldWorks.SFSymbol
Dim swTables As Variant
Dim swTable As Variant
Dim swTableAnn As SldWorks.TableAnnotation
Dim swSketch As SldWorks.Sketch
Dim vSegs As Variant
Dim vSeg As Variant
Dim swSkSeg As SldWorks.SketchSegment
Dim vPts As Variant
Dim vPt As Variant
Dim swSkPt As SldWorks.SketchPoint
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "Ouvrir une mise en plan"
Exit Sub
End If
If swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
MsgBox "Ouvrir une mise en plan"
Exit Sub
End If
Set swDraw = swModel
vSheets = swDraw.GetSheetNames
For Each vSheet In vSheets
swDraw.ActivateSheet vSheet
Set swView = swDraw.GetFirstView
If swView.GetTableAnnotationCount > 0 Then
swTables = swView.GetTableAnnotations
For Each swTable In swTables
Set swTableAnn = swTable
Set swAnn = swTableAnn.GetAnnotation
swAnn.Layer = "Annotations"
Next
End If
Set swView = swView.GetNextView
While Not swView Is Nothing
Set swNote = swView.GetFirstNote
While Not swNote Is Nothing
Set swAnn = swNote.GetAnnotation
swAnn.Layer = "Annotations"
Set swNote = swNote.GetNext
Wend
Set swDatum = swView.GetFirstDatumTag
While Not swDatum Is Nothing
Set swAnn = swDatum.GetAnnotation
swAnn.Layer = "Annotations"
Set swDatum = swDatum.GetNext
Wend
Set swGtol = swView.GetFirstGTOL
While Not swGtol Is Nothing
Set swAnn = swGtol.GetAnnotation
swAnn.Layer = "Annotations"
Set swGtol = swGtol.GetNextGTOL
Wend
Set swAnnSFSymbol = swView.GetFirstSFSymbol
While Not swAnnSFSymbol Is Nothing
Set swAnn = swAnnSFSymbol.GetAnnotation
swAnn.Layer = "Annotations"
Set swAnnSFSymbol = swAnnSFSymbol.GetNext
Wend
Set swDispDim = swView.GetFirstDisplayDimension5
While Not swDispDim Is Nothing
Set swAnn = swDispDim.GetAnnotation
swAnn.Layer = "Annotations"
Set swDispDim = swDispDim.GetNext5
Wend
Set swSketch = swView.GetSketch
vSegs = swSketch.GetSketchSegments
If Not IsEmpty(vSegs) Then
For Each vSeg In vSegs
Set swSkSeg = vSeg
swSkSeg.Layer = "Dessin"
Next
End If
vPts = swSketch.GetSketchPoints2
If Not IsEmpty(vPts) Then
For Each vPt In vPts
Set swSkPt = vPt
swSkPt.Layer = "Dessin"
Next
End If
Set swView = swView.GetNextView
Wend
Next
swModel.ClearSelection2 True
End Sub