API Question
API Question
(OP)
All,
I have recorded the following macro for use ...
'Global Variable Declarations
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
' Main() call
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.OpenDoc6("C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings)
swApp.OpenDoc6 "C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings
Set Part = swApp.ActivateDoc2("1 inch cam A ear plate.SLDPRT", False, longstatus)
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
Part.Extension.InsertScene "\scenes\02 studio scenes\66 light cards.p2s"
swApp.ActiveDoc.ActiveView.FrameState = 1
Set Part = Nothing
End Sub
... I need to have a UserForm with a browse button on it when the users call this macro.
Can someone please tell me how to call a UserForm?
Thank you,
Naerwen
I have recorded the following macro for use ...
'Global Variable Declarations
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
' Main() call
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.OpenDoc6("C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings)
swApp.OpenDoc6 "C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings
Set Part = swApp.ActivateDoc2("1 inch cam A ear plate.SLDPRT", False, longstatus)
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
Part.Extension.InsertScene "\scenes\02 studio scenes\66 light cards.p2s"
swApp.ActiveDoc.ActiveView.FrameState = 1
Set Part = Nothing
End Sub
... I need to have a UserForm with a browse button on it when the users call this macro.
Can someone please tell me how to call a UserForm?
Thank you,
Naerwen






RE: API Question
NaerwensUserForm
then your code would be:
CODE
-handleman, CSWP (The new, easy test)
RE: API Question
If your are going to browse for folders or files, you will need to use Windows API to gain access to the file dialog objects.
RE: API Question
-handleman, CSWP (The new, easy test)
RE: API Question
RE: API Question
Ok ... so ... Handleman's initial response was good to go and got me to the point where I have a pre-recorded macro that is now tweeked. However, for creating VBAs in solidworks I would like to know what the best practices are ... for instance ... here is the code in the 'Module 1' area of the SW IDE ...
Sub main()
UserForm1.Show
End Sub
... and here is the code for the form that I have created FOR TEST PURPOSES ONLY ...
Private Sub CommandButton1_Click()
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Set swApp = Application.SldWorks
Set Part = swApp.OpenDoc6("C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings)
swApp.OpenDoc6 "C:\Documents and Settings\begas\My Documents\Work-2.0\SolidWorks\SolidworksDrawings\1 INCH CAM\1 inch cam A ear plate.SLDPRT", 1, 0, "", longstatus, longwarnings
Set Part = swApp.ActivateDoc2("1 inch cam A ear plate.SLDPRT", False, longstatus)
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
Part.Extension.InsertScene "\scenes\02 studio scenes\66 light cards.p2s"
swApp.ActiveDoc.ActiveView.FrameState = 1
Set Part = Nothing
End Sub
Private Sub CommandButton2_Click()
Dim swApp As Object
Set swApp = Application.SldWorks
swApp.CloseDoc "1 inch cam A ear plate.SLDPRT"
End Sub
Private Sub UserForm_Click()
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
End Sub
... Is this practice correct??? What I am referring to is the code's structure on 'paper' ... as it were. That is, is this correct ... to force the 'Module 1' area of the IDEs project to call the form and then have the form handle the code ... or should I/ can I manipulate the objects on UserForm1 from the 'Module 1' object in the IDE?
I hope this is not too confusing ... if it is ... remember ... your guys king fu is way better than mine ... for now. =P
Thanks for all the help you two have given thus far. I truly appreciate it.
Naerwen
RE: API Question
-handleman, CSWP (The new, easy test)