Bonjour, j’ai trouvé comment récupérer dans une macro VBA certaines informations sur les notes ou les bulles dans une mise en plan solidworks, son texte pour l’éditer, sa forme (encadré, triangle etc) et j’aimerais aussi pouvoir détecter le calque auquel elle appartient et éventuellement en changer pour changer la couleur etc.
Merci d’avance
Bonjour,
Cela se fait à l’aide de la gestion des calques.
Regarde ce code, qui me permettait d’insérer une note en rouge:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSketchBlockDef As SldWorks.SketchBlockDefinition
Dim swBlockInst As SldWorks.SketchBlockInstance
Dim swSketchMgr As SldWorks.SketchManager
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSheet As SldWorks.Sheet
Dim mySheet As SldWorks.Sheet
Dim paperSize As swDwgPaperSizes_e
Dim myBlockDefinition As Object
Dim vSheetNames As Variant
Dim bRet As Boolean
Dim i As Long
Dim swMathUtil As SldWorks.MathUtility
Dim swMathPoint As SldWorks.MathPoint
Dim width As Double
Dim height As Double
Dim nPt(2) As Double
Dim vPt As Variant
Dim posX As Double
Dim posY As Double
Dim nomDuBloc As String
Dim swTextFormat As SldWorks.TextFormat
Public X As Double
Public Y As Double
Public str As String
Sub origineAcier()
'On appelle la procédure et on place le texte comme argument
coordonnéeXY "Origine Acier : " + Chr(10) + "Aciéries de l'europe" + Chr(10) + "de l'ouest"
End Sub
Sub contactAlimentaire()
'On appelle la procédure et on place le texte comme argument
coordonnéeXY "Contact Alimentaire"
End Sub
Sub traçabilitéNuance()
'On appelle la procédure et on place le texte comme argument
coordonnéeXY "Traçabilité Nuance"
End Sub
Sub traçabilitéNuanceEtContactAlimentaire()
'On appelle la procédure et on place le texte comme argument
coordonnéeXY "Traçabilité Nuance" + Chr(10) + "Contact Alimentaire"
End Sub
Sub traçabilitéGravureNumPlan()
'On appelle la procédure et on place le texte comme argument
coordonnéeXY "Graver le N° de" + Chr(10) + "plan sur la pièce"
End Sub
Sub coordonnéeXY(str As String)
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
posX = 0.065 'modifier ici le décalage en X par rapport à l'angle en haut à gauche
posY = 0.015 'modifier ici le décalage en Y par rapport à l'angle en haut à gauche
swDraw.ActivateSheet (vSheetNames(i))
Set mySheet = swDraw.GetCurrentSheet
paperSize = mySheet.GetSize(width, height)
posX = width - posX
posY = height - posY
insertionNote swModel, posX, posY, str
swDraw.GraphicsRedraw2
Next i
swDraw.ActivateSheet (swSheet.GetName)
End Sub
Sub insertionNote(swModel As ModelDoc2, X As Double, Y As Double, monBloc As String)
Dim myNote As Note
Dim myAnnotation As Annotation
Dim swTextFormat As SldWorks.TextFormat
Dim boolstatus As Boolean
Set myNote = swModel.InsertNote(monBloc)
If Not myNote Is Nothing Then
boolstatus = myNote.SetBalloon(4, 0)
Set myAnnotation = myNote.GetAnnotation()
If Not myAnnotation Is Nothing Then
boolstatus = myAnnotation.SetPosition(X, Y, 0)
Set swTextFormat = myAnnotation.GetTextFormat(1)
swTextFormat.CharHeight = 0.004
swTextFormat.Bold = True
swTextFormat.Italic = True
boolstatus = myAnnotation.SetTextFormat(1, False, swTextFormat)
End If
End If
ListeCalque swDraw, myAnnotation
End Sub
Sub ListeCalque(swModel As DrawingDoc, myAnnotation As Annotation)
Dim swLayerMgr As SldWorks.LayerMgr
Dim vLayerArr As Variant
Dim vLayer As Variant
Dim swLayer As SldWorks.Layer
Dim noteLayer As Integer
Dim layerExist As Boolean
Set swLayerMgr = swModel.GetLayerManager
vLayerArr = swLayerMgr.GetLayerList
For Each vLayer In vLayerArr
Set swLayer = swLayerMgr.GetLayer(vLayer)
If swLayer.Name = "NotesRouge" Then
layerExist = True
Else
layerExist = False
End If
Next
If layerExist = True Then
myAnnotation.Layer = "NotesRouge"
Else
noteLayer = swLayerMgr.AddLayer("NotesRouge", "Calque pour les notes rouge", RGB(255, 0, 0), 0, 0)
myAnnotation.Layer = "NotesRouge"
End If
End Sub
4 « J'aime »
Merci pour ton aide. J’ai repéré la partie qui m’intéresse dans ton code :
myAnnotation.Layer = « NotesRouge »
Je ne pouvais pas appliquer la méthode directement à ma note, j’ai ajouté
Set myAnnotation = myNote.GetAnnotation()
Et ça marche parfaitement ! Merci beaucoup.
2 « J'aime »
Bonjour,
en ce qui nous concerne nous utilisons plutôt une bibliothèque d’annotations.
C’est un choix