Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Balloon order HELP SW2008 SP3.1

Status
Not open for further replies.

adn1975

Mechanical
Nov 3, 2006
26
0
0
US
Is there a way, on a stacked balloon, to put the item numbers in order? SW orders them default by the order you select the components. I would like to re-order so they are ascending numerically without having to pick them in order.
 
Replies continue below

Recommended for you

Not that I can see. If this is really important to you it could be done with a macro. However, the macro would work by looking at the balloon values and what they are attached to, deleting all the balloons, and re-selecting them in the proper order.

-handleman, CSWP (The new, easy test)
 
Yuck, this one's sort of messy. Maybe I'll clean it up one day. This deletes all the balloons in the stack except for the lowest numbered balloon. This preserves the balloon location, stack direction, size, fonts, etc. It then adds to stack all the ones it didn't delete, in the order that they should appear.

Code:
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swNote As SldWorks.Note
Dim swBstack As SldWorks.BalloonStack
Dim swSelMgr As SldWorks.SelectionMgr
Dim bStackDir As Long
Dim bStackFit As Long
Dim StackMembers As Variant
Dim bLength As Long
Dim aStackText() As String
Dim AttachedEnts As Variant
Dim aStackEnts() As SldWorks.Entity
Dim CurTextPoint As Variant
Dim LowStackNum As Long

Dim i As Long
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager

If swSelMgr.GetSelectedObjectCount <> 1 Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelNOTES Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

Set swNote = swSelMgr.GetSelectedObject6(1, -1)
swDoc.ClearSelection2 True
If swNote.IsStackedBalloon = False Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

Set swBstack = swNote.GetBalloonStack
StackMembers = swBstack.Stack
bStackDir = swBstack.Direction
bLength = swBstack.Length
bStackFit = swBstack.Master.GetBalloonSize
CurTextPoint = swBstack.Master.GetTextPoint2

ReDim aStackText(1, 0)
aStackText(0, 0) = swBstack.Master.GetText
aStackText(1, 0) = "0"

ReDim aStackEnts(0)
AttachedEnts = swBstack.Master.GetAnnotation.GetAttachedEntities
Set aStackEnts(0) = AttachedEnts(0)

For i = 1 To (UBound(StackMembers) + 1)
    ReDim Preserve aStackText(1, i)
    Set swNote = StackMembers(i - 1)
    aStackText(0, i) = swNote.GetText
    aStackText(1, i) = i
    
    ReDim Preserve aStackEnts(i)
    AttachedEnts = StackMembers(i - 1).GetAnnotation.GetAttachedEntities
    Set aStackEnts(i) = AttachedEnts(0)
Next i

'Debug.Print "Pre-sort"
'For i = 0 To UBound(aStackText, 2)
'    Debug.Print aStackText(0, i), aStackText(1, i)
'Next i
aSort aStackText

LowStackNum = aStackText(1, 0)
If LowStackNum <> 0 Then
    swBstack.Master.GetAnnotation.Select False
End If
For i = 0 To UBound(StackMembers)
    If i + 1 <> LowStackNum Then
        StackMembers(i).GetAnnotation.Select True
    End If
Next i
swDoc.DeleteSelection False
'Debug.Print "Post-sort"
'For i = 0 To UBound(aStackText, 2)
'    Debug.Print aStackText(0, i), aStackText(1, i)
'Next i


For i = 1 To UBound(aStackText, 2)
    aStackEnts(CLng(aStackText(1, i))).Select False
    swBstack.AddTo swBalloonTextItemNumber, "", swBalloonTextItemNumber, ""
Next i

swDoc.EditRebuild3
End Sub

Private Sub aSort(ByRef myArray As Variant)
Dim tmpVal1 As String
Dim tmpVal2 As String
Dim bMoved As Boolean
Dim i As Long

bMoved = True

While bMoved
    bMoved = False
    For i = 1 To UBound(myArray, 2)
        If myArray(0, i) < myArray(0, i - 1) Then
            bMoved = True
            tmpVal1 = myArray(0, i - 1)
            tmpVal2 = myArray(1, i - 1)
            myArray(0, i - 1) = myArray(0, i)
            myArray(1, i - 1) = myArray(1, i)
            myArray(0, i) = tmpVal1
            myArray(1, i) = tmpVal2
            Exit For
        End If
    Next i
Wend
End Sub


-handleman, CSWP (The new, easy test)
 
That is correct Handleman....I don't want to re-order the bill, just the balloons. Now after using the software for 9 years, i have to use my first macro....I'm sure i can figure it out, with the help of this forum of course...

Thanks again for all your help.
 
Oops, I sorted by string rather than number. When considered as a string, 13 comes before 3. Below are the changes to sort numerically.

Code:
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swNote As SldWorks.Note
Dim swBstack As SldWorks.BalloonStack
Dim swSelMgr As SldWorks.SelectionMgr
Dim bStackDir As Long
Dim bStackFit As Long
Dim StackMembers As Variant
Dim bLength As Long
Dim aStackText() As String
Dim AttachedEnts As Variant
Dim aStackEnts() As SldWorks.Entity
Dim CurTextPoint As Variant
Dim LowStackNum As Long

Dim i As Long
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager

If swSelMgr.GetSelectedObjectCount <> 1 Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelNOTES Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

Set swNote = swSelMgr.GetSelectedObject6(1, -1)
swDoc.ClearSelection2 True
If swNote.IsStackedBalloon = False Then
    MsgBox "Please select one stacked balloon and try again."
    Exit Sub
End If

Set swBstack = swNote.GetBalloonStack
StackMembers = swBstack.Stack
bStackDir = swBstack.Direction
bLength = swBstack.Length
bStackFit = swBstack.Master.GetBalloonSize
CurTextPoint = swBstack.Master.GetTextPoint2

ReDim aStackText(1, 0)
aStackText(0, 0) = swBstack.Master.GetText
aStackText(1, 0) = "0"

ReDim aStackEnts(0)
AttachedEnts = swBstack.Master.GetAnnotation.GetAttachedEntities
Set aStackEnts(0) = AttachedEnts(0)

For i = 1 To (UBound(StackMembers) + 1)
    ReDim Preserve aStackText(1, i)
    Set swNote = StackMembers(i - 1)
    aStackText(0, i) = swNote.GetText
    aStackText(1, i) = i
    
    ReDim Preserve aStackEnts(i)
    AttachedEnts = StackMembers(i - 1).GetAnnotation.GetAttachedEntities
    Set aStackEnts(i) = AttachedEnts(0)
Next i

'Debug.Print "Pre-sort"
'For i = 0 To UBound(aStackText, 2)
'    Debug.Print aStackText(0, i), aStackText(1, i)
'Next i
aSort aStackText

LowStackNum = aStackText(1, 0)
If LowStackNum <> 0 Then
    swBstack.Master.GetAnnotation.Select False
End If
For i = 0 To UBound(StackMembers)
    If i + 1 <> LowStackNum Then
        StackMembers(i).GetAnnotation.Select True
    End If
Next i
swDoc.DeleteSelection False
'Debug.Print "Post-sort"
'For i = 0 To UBound(aStackText, 2)
'    Debug.Print aStackText(0, i), aStackText(1, i)
'Next i


For i = 1 To UBound(aStackText, 2)
    aStackEnts(CLng(aStackText(1, i))).Select False
    swBstack.AddTo swBalloonTextItemNumber, "", swBalloonTextItemNumber, ""
Next i

swDoc.EditRebuild3
End Sub

Private Sub aSort(ByRef myArray As Variant)
Dim tmpVal1 As String
Dim tmpVal2 As String
Dim bMoved As Boolean
Dim i As Long

bMoved = True

While bMoved
    bMoved = False
    For i = 1 To UBound(myArray, 2)
        If CLng(myArray(0, i)) < CLng(myArray(0, i - 1)) Then
            bMoved = True
            tmpVal1 = myArray(0, i - 1)
            tmpVal2 = myArray(1, i - 1)
            myArray(0, i - 1) = myArray(0, i)
            myArray(1, i - 1) = myArray(1, i)
            myArray(0, i) = tmpVal1
            myArray(1, i) = tmpVal2
            Exit For
        End If
    Next i
Wend
End Sub

-handleman, CSWP (The new, easy test)
 
I prefer to put them in order of assembly also. How ever certain engineers/design approvers, when they can't find anything wrong with the design they tend to pick on ticky tacky things.....

Works great thank you.
 
Status
Not open for further replies.
Back
Top