Macro to update symbol flags in drawing
Macro to update symbol flags in drawing
(OP)
My company uses flags for all kinds of things in drawings and they are all numbered consecutively, though with different shapes depending on what they're being used for. However, if a feature has its flag removed, or if I want to add another one, I have to go edit each one to raise/lower its number appropriately.
I would like to create a macro to increment/decrement flags on selected dimensions and notes. Can anyone help? I have some programming experience, but very little VB (mostly Python). Even if you can point me to the function calls I'd need to access selected items, find their flags, and edit those, that would be helpful.
Thanks,
Matt
I would like to create a macro to increment/decrement flags on selected dimensions and notes. Can anyone help? I have some programming experience, but very little VB (mostly Python). Even if you can point me to the function calls I'd need to access selected items, find their flags, and edit those, that would be helpful.
Thanks,
Matt






RE: Macro to update symbol flags in drawing
SW07-SP3.1
SW06-SP5.1
RE: Macro to update symbol flags in drawing
Company? Highly preferred.
People tend to read notes/protocols/whatever on a separate sheet and then want to find the referenced item in the drawing. I get "yelled at" when someone can't easily find the symbol attached to the figure. (i.e. if #27 is located between #3 and #4).
I was hoping that one macro could save everyone some frustration.
RE: Macro to update symbol flags in drawing
I interpreted your question as asking how to renumber say, #6 thru #10 if #5 had been deleted. I was asking if a non-sequential (OK my fault; I should have used "non-consecutive") numbers. eg. 1, 2, 3, 4, 6, 7, .....
SW07-SP3.1
SW06-SP5.1
RE: Macro to update symbol flags in drawing
All the same, I still would like to tackle this as a macro exercise, since I've never written one for SW and this sounds like a safe way to start. That way I can be a little more familiar with the API when the time comes that I really need one.
RE: Macro to update symbol flags in drawing
If so, this should be a relatively simple thing to do. The most difficult part will be parsing that text to determine how to increment it (numerically, with a dot, etc).
RE: Macro to update symbol flags in drawing
The user would have to do the work to select the necessary dimensions/notes and then the macro would add or subtract from the number in each flag. Conceptually, it's not difficult. I just don't know my way around the API well enough.
In pseudocode, I think this is the flow I'd want:
-get all selected objects
-pare down to only notes and dimensions with symbol flags
-read each note or dimension string
-find instances of "#-" after "<" in the strings (I hope notes are stored this way internally, like dimensions are)
-find the number between the "-" and the ">" and add/subtract to it
-write the new string in place of the old one
-loop through all notes/dimensions with flags once
Sound about right?
RE: Macro to update symbol flags in drawing
CODE
<C#P-1>
<CL-A>
<CLP-A>
<S#-1>
<S#P-1>
<SLP-A>
<SL-A>
<SC#P-1>
<SC#-1>
<SCLP-A>
<SCL-A>
<T#P-1>
<T#-1>
<TLP-A>
<TL-A>
<FlagNotes-Flag-1>
<FlagNotes#NPer-Flag-1>
<FlagNotes# az-Flag-1>
<FlagNotes#noper-Flag-1>
Here is some code to get you started:
CODE
Dim swDoc As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swNote As SldWorks.Note
Dim i As Long
Dim sIncText As String
Sub IncrementFlags()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager
For i = 1 To swSelMgr.GetSelectedObjectCount
If swSelMgr.GetSelectedObjectType3(i, Empty) = swSelDIMENSIONS Then
Set swDispDim = swSelMgr.GetSelectedObject6(i, Empty)
sIncText = swDispDim.GetText(swDimensionTextPrefix)
swDispDim.SetText swDimensionTextPrefix, FindAndIncFlags(sIncText)
sIncText = swDispDim.GetText(swDimensionTextSuffix)
swDispDim.SetText swDimensionTextSuffix, FindAndIncFlags(sIncText)
sIncText = swDispDim.GetText(swDimensionTextCalloutAbove)
swDispDim.SetText swDimensionTextCalloutAbove, FindAndIncFlags(sIncText)
sIncText = swDispDim.GetText(swDimensionTextCalloutBelow)
swDispDim.SetText swDimensionTextCalloutBelow, FindAndIncFlags(sIncText)
ElseIf swSelMgr.GetSelectedObjectType3(i, Empty) = swSelNOTES Then
Set swNote = swSelMgr.GetSelectedObject6(i, Empty)
sIncText = swNote.GetText
swNote.SetText FindAndIncFlags(sIncText)
End If
Next
swDoc.ClearSelection2 True
swDoc.GraphicsRedraw2
End Sub
Function FindAndIncFlags(OldString As String) As String
'''''''''''''''''''''''''
'write your string parsing code here
'''''''''''''''''''''''''
End Function
This code will read each string from selected dimensions and notes, pass that value to the function "FindAndIncFlags", and put the returned string value back into the dimension/note. The function "FindAndIncFlags" needs to be written to parse the string passed. The string may be zero-length, and may or may not contain any symbol. The string returned by the function should be the same as the string passed to it except that any flags should have been incremented. You can make the text parsing function as robust or as sparse as you want.
Hope this gets you going!