|
api question
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
find a job or post a job opening
if your form's name is
naerwensuserform
then your code would be:
code
naerwensuserform.show
-handleman, cswp (the new, easy test)
of course, first you need to create the user form...
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.
windows api is only needed to browse for folders or to enable multi-selection. browsing for single files can be accomplished with solidworks api's getopenfilename function.
-handleman, cswp (the new, easy test)
my api kung fu is getting dated.
all,
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 ... re
you can manipulate objects on the form from a code module. you can also write functions/subs in a module and call them from a form. it really depends on what you need to do with your code. in the case of your example, where you are opening a document and closing it, that is just fine to do in the form. your entire "userform_click()" routine does nothing, by the way. you can delete it. also, the two lines containing opendoc6 both do the same thing. keep the one that begins "set part =" and delete the other one.
-handleman, cswp (the new, easy test) |
|