-
Re: VBA to check LeaderLineStyle in a Note
Manikandan Babu Apr 13, 2017 8:29 AM (in response to Cad Admin)Hi Cad Admin,
Dim swApp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim swnote As SldWorks.Note
Dim swann As SldWorks.Annotation
Dim swselmgr As SldWorks.SelectionMgr
Sub main()
Set swApp = Application.SldWorks
Set swmodel = swApp.ActiveDoc
Set swselmgr = swmodel.SelectionManager
Set swnote = swselmgr.GetSelectedObject6(1, -1)
Set swann = swnote.GetAnnotation
Debug.Print swann.Leaderlinestyle '6
End Sub
swLineCENTER 4 swLineCHAIN 3 swLineCHAINTHICK 6 swLineCONTINUOUS 0 swLineDEFAULT 7 swLineHIDDEN 1 swLinePHANTOM 2 swLineSTITCH 5 Manikandan
-
Re: VBA to check LeaderLineStyle in a Note
Cad Admin Apr 13, 2017 8:40 AM (in response to Manikandan Babu)How would i check leader vs no leader?
-
Re: VBA to check LeaderLineStyle in a Note
Manikandan Babu Apr 13, 2017 8:44 AM (in response to Cad Admin)Dim swApp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim swnote As SldWorks.Note
Dim swann As SldWorks.Annotation
Dim swselmgr As SldWorks.SelectionMgr
Sub main()
Set swApp = Application.SldWorks
Set swmodel = swApp.ActiveDoc
Set swselmgr = swmodel.SelectionManager
Set swnote = swselmgr.GetSelectedObject6(1, -1)
Set swann = swnote.GetAnnotation
Debug.Print swann.GetLeaderStyle swNO_LEADER 0 = No leader
End Sub
-
Re: VBA to check LeaderLineStyle in a Note
Cad Admin Apr 13, 2017 9:26 AM (in response to Manikandan Babu)Manikandan,
Basically i'm looking to add a leader/no leader check to this ....only want it to process notes with leaders
Option Explicit
Const NumStrings As Long = 3
Dim initString(NumStrings) As String
Dim newString(NumStrings) As String
Private Sub InitStrings()
' Initial strings from drawing
initString(0) = "2012-sm"
initString(1) = "WEIGHT:"
initString(2) = "FINISH:"
' Strings to replace initial strings in drawing
newString(0) = "NEW 2012-sm"
newString(1) = "NEW WEIGHT:"
newString(2) = "NEW FINISH:"
End Sub
Private Sub DoReplaceString(ByRef sNoteText As String)
Dim i As Long
For i = 0 To NumStrings
sNoteText = Replace(sNoteText, initString(i), newString(i), 1, -1, vbTextCompare)
Next i
End Sub
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
Dim i As Long
InitStrings
Set swApp = 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.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
-
Re: VBA to check LeaderLineStyle in a Note
Cad Admin Apr 13, 2017 1:56 PM (in response to Cad Admin)Added the Getleaderstyle check in & works great...
Dim swAnn As SldWorks.Annotation
Dim LeadStyle As String
While Not swNote Is Nothing
If swNote.IsCompoundNote Then
nTextCount = swNote.GetTextCount
For i = 1 To nTextCount
sNoteText = swNote.GetTextAtIndex(i)
Debug.Print "Text = " & sNoteText
DoReplaceString sNoteText
swNote.SetTextAtIndex i, sNoteText
Next i
Debug.Print "Text = " & sNoteText
Else
Set swAnn = swNote.GetAnnotation
LeadStyle = swAnn.GetLeaderStyle
sNoteText = swNote.GetText
If LeadStyle > 0 Then
Debug.Print "Text = " & sNoteText
DoReplaceString sNoteText
swNote.SetText sNoteText
Else
End If
End If
Set swNote = swNote.GetNext
Wend
-
-
-
-