Hello everyone,
I'm looking to create a macro that would allow me to change an existing text in a SolidWorks blueprint.
So far my Google searches haven't been successful, and the SolidWorks macro recorder isn't much help either.
Nor can we say that the SolidWorks APIs are a provided, accurate and accessible literature.
Do you have an example or an idea to guide me a little?
Thank you in advance
Thank you
But I had already found these two codes, nothing to do with what I want to do
Can you say more in this case or show the note you want to change and where?
But in fact it's a simple text on the flat background where it says "AAA" and I want to change this text to "BBB" with a macro no matter where it is.
If I know the object name which is: "Plan detail331@fond object1"
Here's how to edit the text of a note via the name of that note, if I understood correctly:
https://help.solidworks.com/2020/English/api/sldworksapi/Get_Note_By_Name_Example_VB.htm
1 Like
Well here is a piece of code that works, on the other hand I now have to make it recognize the formats because the name of the note is not identical on each drawing format.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Dim sNoteText As String
Dim nTextCount As Long
Sun i As Long
Dim NoteDescript As String
Set swApp = Application.SldWorks 'CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView ' This is the drawing template
While Not swView Is Nothing
Set swNote = swView.GetFirstNote
While Not swNote Is Nothing
If swNote.GetName = "Objet de détail160" Then
NoteDescript = "$PRPSHEET:" & Chr(34) & "DESCRIPTION_EN" & Chr(34)
swNote.SetTextAtIndex 1, NoteDescript
End If
'If swNote.IsCompoundNote Then
' nTextCount = swNote.GetTextCount
' For i = 1 To nTextCount
' sNoteText = swNote.GetTextAtIndex(i)
' DoReplaceString sNoteText
' swNote.SetTextAtIndex i, sNoteText
' Next i
'Else
' sNoteText = swNote.GetText
' DoReplaceString sNoteText
' swNote.SetText sNoteText
'End If
Set swNote = swNote.GetNext
Wend
Set swView = swView.GetNextView
Wend
End Sub
If the content is identical or has the same base, prefer recognition via content, if this is not possible, effectively see for recognition via a list of names.
Knowing that the name is more risky in general than the content.
1 Like
Hello
Is the note bound to a file property or is it just an unattached object?
1 Like