use ModelDoc2::EditBalloonProperties→don't reattach balloon.
Description
This method edits the selected balloon's properties
Syntax (OLE Automation)
retval = ModelDoc2.EditBalloonProperties ( style, size, upperTextStyle, upperText, lowerTextStyle, lowerText )
Input: | (long) style | Style of balloon as defined in swBalloonStyle_e |
Input: | (long) size | Balloon size as defined in swBalloonFit_e |
Input: | (long) upperTextStyle | Upper-text style as defined in swDetailingNoteTextContent_e |
Input: | (BSTR) upperText | Text for the upper-text in this balloon |
Input: | (long) lowerTextStyle | Lower-text style as defined in swDetailingNoteTextContent_e |
Input: | (BSTR) lowerText | Text for the lower-text in this balloon |
Return: | (LPDISPATCH) retval | Pointer to the balloon being edited |
***************************************************************************
2010 SOLIDWORKS API Help - Insert Autoballoons Example (VBA) (AutoBalloon2) http://help.solidworks.com/2010/english/api/sldworksapi/insert_autoballoons_example_vb_autoballoon2_vb.htm
Follow code result is
File = D:\360安全浏览器下载\B\Assem.SLDDRW
DetailingBalloonsDisplayWithBentLeader = False
DetailingBOMBalloonStyle = 1
DetailingBOMBalloonFit = 2
DetailingAutoBalloonLayout = 1
DetailingBalloonBentLeaderLength = 6.25 mm
Drawing View1
No balloons added.
code is
'---------------------------------------------
'
' Preconditions:
' (1) Drawing document is open.
' (2) Drawing view is selected.
'
' Postconditions: If autoballoons have not already been inserted in the
' drawing document and the drawing document is not lightweight,
' then autoballoons are inserted for each resolved component in the
' selected drawing view.
'
'----------------------------------------------
Sub main()
Const swDetailingBalloonLayout_Default As Long = -1
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim vNoteArr As Variant
Dim vNote As Variant
Dim swNote As SldWorks.Note
Dim swAnn As SldWorks.Annotation
Dim vAttachPos As Variant
Dim vAnnPos As Variant
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
bRet = swDraw.ActivateView(swView.Name): Debug.Assert bRet
Debug.Print "File = " & swModel.GetPathName
' Get autoballoon settings
Debug.Print " DetailingBalloonsDisplayWithBentLeader = " & swModel.GetUserPreferenceToggle(swDetailingBalloonsDisplayWithBentLeader)
Debug.Print " DetailingBOMBalloonStyle = " & swModel.GetUserPreferenceIntegerValue(swDetailingBOMBalloonStyle)
Debug.Print " DetailingBOMBalloonFit = " & swModel.GetUserPreferenceIntegerValue(swDetailingBOMBalloonFit)
Debug.Print " DetailingAutoBalloonLayout = " & swModel.GetUserPreferenceIntegerValue(swDetailingAutoBalloonLayout)
Debug.Print " DetailingBalloonBentLeaderLength = " & swModel.GetUserPreferenceDoubleValue(swDetailingBalloonBentLeaderLength) * 1000# & " mm"
Debug.Print ""
Debug.Print " " & swView.Name
vNoteArr = swDraw.AutoBalloon2(swDetailingBalloonLayout_Default, False)
' Returns an empty array if:
' * Balloons already exist in any drawing view on any on sheet in
' the drawing document.
' * Drawing document is lightweight.
' Returns a note for each resolved component in the selected drawing view.
If IsEmpty(vNoteArr) Then
Debug.Print " No balloons added."
Exit Sub
End If
For Each vNote In vNoteArr
Set swNote = vNote
Set swAnn = swNote.GetAnnotation
vAttachPos = swNote.GetAttachPos
vAnnPos = swAnn.GetPosition
Debug.Print " Text = " & swNote.GetText
Debug.Print " Layer = " & swAnn.Layer
Debug.Print " AttachPos = (" & vAttachPos(0) * 1000# & ", " & vAttachPos(1) * 1000# & ", " & vAttachPos(2) * 1000# & ") mm"
Debug.Print " AnnPos = (" & vAnnPos(0) * 1000# & ", " & vAnnPos(1) * 1000# & ", " & vAnnPos(2) * 1000# & ") mm"
'bRet = swAnn.SetPosition(vAnnPos(0) + 0.01, vAnnPos(1), vAnnPos(2))
Next
End Sub
'--------------------------------------
SolidworksApi macros