Hello
I have a plan with several pages that have the same background.
In this background map I have a note where we assign a value manually, different for each page.
In my macro I would like to retrieve the value of this note for each page in order to use it for the page name (I already have the macro to manage the page name). I don't know how to be able to retrieve this value on each page...
thank you in advance
Cédric
Hello
If the note is not linked to any file property but is part of the baseplane template, the ID of the note object must be retrieved in order to process the actions of the note.
1 Like
Hello;
To join @Cyril_f in his reasoning, it would be much simpler if these notes were directly derived from a property of the component being planed.
In this way they will be automatically updated in the sheets, or usable via a macro (which becomes less necessary).
I was with my head under water... Thank you for your answers
It's not possible to link the note to a property of the part, it's an info that you fill in manually in the drawing
On the other hand, I'm interested in knowing how to retrieve the ID of the note object
Hello
You have to loop over all the notes and retrieve the content of the note to find its number and then write a line like this:
if swNote.GetName = "Objet de détailxxx" then ...
For the loop, you have to do something like this:
Set swView = swDraw.GetFirstView
Set swNote = swView.GetFirstNote
Do While Not swNote Is Nothing
If swNote.GetText = "xxx" then debug.print swNote.GetName: stop
Set swNote = swNote.GetNext
Set swView = swView.GetNext
3 Likes
Here I managed to get what I wanted after several attempts!
Here is my complete macro, adapted to our needs: we rename each sheet with the sheet number, and the position number (which can be found in the note). If no note or text in the note is found, then the name of the sheet is not changed
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vSheetNames As Variant
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Dim i As Long
Dim pos, feuilleorigin As Long
Dim FName As Variant
Dim namesArray As Variant
Dim noteFound As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
' Désactiver l'affichage pour accélérer la macro (mode en arrière-plan)
swApp.Visible = False
' get the list of sheets names
vSheetNames = swDraw.GetSheetNames
ReDim namesArray(0)
For i = 0 To UBound(vSheetNames)
' increase the array length and add the sheet name to the list
ReDim Preserve namesArray(UBound(namesArray) + 1) ' increase the array length to put the next value
namesArray(i) = vSheetNames(i)
' temporary rename the sheet to avoid duplicate names (if duplicate, you can not rename)
Set swSheet = swDraw.Sheet(vSheetNames(i))
swSheet.SetName (i)
Next i
' get the list of sheets names
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
' get the original name of the sheet
FName = namesArray(i)
' rename the sheet with the new number and the original part of the name
Set swSheet = swDraw.Sheet(vSheetNames(i))
' activate the sheet to get the current note text
swDraw.ActivateSheet (vSheetNames(i))
Set swView = swDraw.GetFirstView ' This is the drawing template
Set swNote = swView.GetFirstNote
noteFound = False
Do While Not swNote Is Nothing
'Debug.Print swNote.GetName
' Objet de détail15 = nom de la note qui contient la position
' check if the note exists and if it has some text, else do not change the sheet name
If swNote.GetName = "Objet de détail15" And Trim(swNote.GetText) <> "" Then
noteFound = True
Exit Do
End If
Set swNote = swNote.GetNext
Loop
'swSheet.SetName (i + 1 & Mid(FName, pos))
If noteFound = True Then
swSheet.SetName (i + 1 & "-pos" & swNote.GetText)
Else
swSheet.SetName (FName)
End If
Next i
' Réactiver l'affichage pour SolidWorks
swApp.Visible = True
MsgBox "Renumérotation terminée"
End Sub
3 Likes