Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to update symbol flags in drawing 1

Status
Not open for further replies.

MattBD

Bioengineer
Jan 26, 2007
62
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
 
Replies continue below

Recommended for you

I realise it's probably a company standard, but do you really need to have the tag numbers notes kept sequential? They are just a means of easily making reference to a note. A unique symbol or shape would do the same thing.

[cheers]
SW07-SP3.1
SW06-SP5.1
 
Do I need it? No.
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.
 
I was not suggesting that #27 be placed between #3 and #4. I agree that would be very frustrating and counter-productive.

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, .....



[cheers]
SW07-SP3.1
SW06-SP5.1
 
I like that scheme better, and can bring it up. I can always put *DELETED* on the line where a note was to indicate that it was removed from the 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.
 
Just to confirm - you want to increment the flag symbol for all selected notes and/or dimensions. This flag symbol is a symbol from the Symbol Library, and it shows up as a text string such as "<C#P-44>" in the dimension text properties. Let me know if I understand correctly.

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).
 
That's it, handleman. The option to decrement would be good too. Parsing the text shouldn't be too difficult, as I'm used to string handling (at least in Python, I hope VB is just as intuitive).

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?
 
Yes... sort of. Here is a sample for the flag text syntax for all flag types (at least the ones on my machine):

Code:
<C#-1>
<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 swApp As SldWorks.SldWorks
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor