几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 08:59 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】api question

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)
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】question about input boxes yang686526 SolidWorks二次开发 0 2009-04-12 10:09 PM
【转帖】pdmwe api question get configuration from iedmreference5 yang686526 SolidWorks二次开发 0 2009-04-12 10:01 PM


所有的时间均为北京时间。 现在的时间是 04:47 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多