Hello,
I am trying to create a macro to insert a note (which is linked to a custom model property) on a batch basis. I also need to create one to delete the same note on a batch basis. I've recorded a macro to insert the note, but I have failed to splice it into a macro Deepak created. I consistently have the need to splice a recorded macro into a batch macro, but succeed only half the time.
Can anyone help me understand what mistakes I've made in the following?
Here is my recorded macro:
' ******************************************************************************
' C:\Users\t6\AppData\Local\Temp\swx14600\Macro1.swb - macro recorded on 09/24/14 by T6
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
Dim myNote As Object
Dim myAnnotation As Object
Dim myTextFormat As Object
Set myNote = Part.InsertNote("$PRPSHEET:""Actual OD""")
If Not myNote Is Nothing Then
myNote.Angle = 0
boolstatus = myNote.SetBalloon(0, 0)
Set myAnnotation = myNote.GetAnnotation()
If Not myAnnotation Is Nothing Then
longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)
boolstatus = myAnnotation.SetPosition(0.04737609567901, 0.1793169444444, 0)
boolstatus = myAnnotation.SetTextFormat(0, True, myTextFormat)
End If
End If
Part.ClearSelection2 True
Part.WindowRedraw
End Sub
_____________________
and here is my splice job:
_____________________
' Batch File Open and Save (Update Document Properties)------------------------------08/24/12
' Browse Folder codes: http://www.vbaexpress.com/kb/getarticle.php?kb_id=246
' Macro edited as per requirements from Aaron Felsing on SolidWorks forums: https://forum.solidworks.com/message/310724#310724
' Macro will find all the drawing files in the specified Path/location,
' update the specified Document Properties & save them in the same Path/location.
' This macro is provided as is. No claims, support, refund, safety net, or
' warranties are expressed or implied. By using this macro and/or its code in
' any way whatsoever, the user and any entities which the user represents,
' agree to hold the authors free of any and all liability. Free distribution
' and use of this code in other free works is welcome. If any portion of
' this code is used in other works, credit to the authors must be placed in
' that work within a user viewable location (e.g., macro header). All other
' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
' without the expressed written consent by the authors. Use at your own risk!
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' ------------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim boolstatus As Boolean
Dim sFileName As String, Path As String
Dim longstatus As Long, longwarnings As Long
Dim myNote As Object
Dim myAnnotation As Object
Dim myTextFormat As Object
'Dim Part As swModel
Sub main()
Set swApp = Application.SldWorks
Path = BrowseFolder("Select a Path/Folder")
Path = Path + "C:\\\\"
sFileName = Dir(Path & "*.slddrw")
Do Until sFileName = ""
'Set swModel = swApp.OpenDoc6(Path + sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings)
Set swModel = swApp.OpenDoc6(Path + sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings)
Set myNote = swModel.InsertNote("$PRPSHEET:""Actual OD""")
If Not myNote Is Nothing Then
myNote.Angle = 0
boolstatus = myNote.SetBalloon(0, 0)
Set myAnnotation = myNote.GetAnnotation()
If Not myAnnotation Is Nothing Then
longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)
boolstatus = myAnnotation.SetPosition(0.04737609567901, 0.1793169444444, 0)
boolstatus = myAnnotation.SetTextFormat(0, True, myTextFormat)
End If
swModel.ForceRebuild3 (False)
swModel.Save
swApp.CloseDoc swModel.GetTitle
Set swModel = Nothing
sFileName = Dir
Loop
End Sub
If anyone has any direction, I appreciate it. Also, I regularly run into this-- can anyone speak to the modularity of Macros? Are there any examples of a collection of batch macros, with a "do" section in the middle where recorded sections can be spliced in? Thank you!