几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 06:42 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】initiate a browse for file function

initiate a browse for file function
i have a routine that inserts a part into the assembly and creates mates to the reference items in the assembly. that all works great.
the problem is, i can't seem to find the code that allows the user to browse for a file to insert.
i'm sure this is easy, but i just can't seem to find it on my own.
-wes
wes mosier
cswp in '03 & '08
.forefrontstudios.com
2009 premium x64 bit
example from total vb source book
you might also want to check out the getopenfilename function inside solidworks.
i'll get you eh steve, if it's the last thing i dooooo!
josh ... yes
yes, that's exactly the direction i want to go. i just don't think i'm far along enough to know all the syntax yet. i'm pretty sure that i'm on the right track, i just don't know how to get there.
i'm not going to pretend i know much about this yet, so that being said...
this is my first attempt at making a macro and while i'm impressed by my progress today, i'm realizing i might be getting over my head with this. here's what i've got so far, if anyone wants to keep throwing out ideas on what i need to fix, i'd greatly appreciate it.
i want to browse for a file, then insert it into my current assembly, and create these specific mates automatically. that's it... pretty basic. or so i thought. hehe
the mating commands work great, i just can't seem to get it to browse for a file then add that file value to the mate commands.
i don't believe i'm using the getopenfilename format correct. i looked it up in sw api help, but it isn't giving a beginner like me much direction.
here's what i've got...
' ******************************************************************************
' c:\docume~1\wesley\locals~1\temp\swx3484\macro1.swb - macro recorded on 02/20/09 by wesley
' ******************************************************************************
dim swapp as object
dim instance as isldworks
dim part as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim fn as object
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set fn = instance.getopenfilename("", "", "", 0, "", "")
boolstatus = part.addcomponent("c:\documents and settings\wesley\desktop\assem4.sldasm", 0.371960453795, 0.1385881313041, -0.2904331929878)
boolstatus = part.extension.selectbyid2("front plane@assem4-20@vessel assem test", "plane", 0, 0, 0, false, 0, nothing, 0)
boolstatus = part.extension.selectbyid2("axis1", "axis", 0, 0, 0, true, 0, nothing, 0)
set part = swapp.activedoc
part.addmate 0, 2, 0, 0.0979002957672, 0
part.clearselection2 true
dim myfeature as object
set myfeature = part.featuremanager.insertfeaturetreefolder2(swfeaturetreefoldertype_e.swfeaturetreefolder_containing)
part.clearselection2 true
boolstatus = part.extension.selectbyid2("front plane@assem4-20@vessel assem test", "plane", 0, 0, 0, false, 0, nothing, 0)
boolstatus = part.extension.selectbyid2("front plane", "plane", 0, 0, 0, true, 0, nothing, 0)
set part = swapp.activedoc
part.addmate 6, 2, 0, 0.06326275636025, 45
part.clearselection2 true
set myfeature = part.featuremanager.insertfeaturetreefolder2(swfeaturetreefoldertype_e.swfeaturetreefolder_containing)
part.clearselection2 true
boolstatus = part.extension.selectbyid2("top plane@assem4-20@vessel assem test", "plane", 0, 0, 0, false, 0, nothing, 0)
answer option explicit
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim part as sldworks.partdoc
dim assy as sldworks.assemblydoc
dim boolstatus as boolean
dim longwarnings as long, longerror as long
dim swcomp as sldworks.component2
dim refmodel as sldworks.modeldoc2
dim filter as string
dim filename as string
dim fileconfig as string
dim filedispname as string
dim fileoptions as long
dim sdoctype as string
dim swconfig as sldworks.configuration
dim swrootcomp as sldworks.component2
set swapp = application.sldworks
' this following string has three filters associated with it; note the use
' of the | character between filters
filter = "solidworks files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|filter name (*.fil)|*.fil|all files (*.*)|*.*"
filename = swapp.getopenfilename("file to attach", "", filter, fileoptions, fileconfig, filedispname)
' in the dialog, click the down-arrow associated with files to type to see the filters
' dialogfiles of type down arrow key
set swmodel = swapp.activedoc
if swmodel.gettype <> swdocassembly then
msgbox "open assembly first"
exit sub
end if
if ucase(swmodel.getpathname) = ucase(filename) then
msgbox "can't open same file"
exit sub
end if
set assy = swmodel
select case ucase(right(filename, 6))
case "sldasm"
sdoctype = swdocassembly
case "sldprt"
sdoctype = swdocpart
case else
msgbox "wrong type"
exit sub
end select
swapp.documentvisible false, sdoctype
set refmodel = swapp.opendoc6(filename, sdoctype, swopendocoptions_silent, fileconfig, longerror, longwarnings)
set swcomp = assy.addcomponent4(filedispname, fileconfig, 0, 0, 0)
swapp.documentvisible true, sdoctype
set swconfig = swmodel.getactiveconfiguration
set swrootcomp = swconfig.getrootcomponent
boolstatus = assy.extension.selectbyid2("front plane@" & swcomp.name2 & "@" & swrootcomp.name2, "plane", 0, 0, 0, false, 0, nothing, 0)
boolstatus = assy.extension.selectbyid2("axis1", "axis", 0, 0, 0, true, 0, nothing, 0)
assy.addmate 0, 2, 0, 0, 0
assy.clearselection2 true
end sub
wow
that is amazing! it's exactly what i was trying to do, and you just whipped it up for me??!!
thanks!!!!
now i can see that i was pretty far off.
again, thanks a lot!!!
wes mosier
cswp in '03 & '08
.forefrontstudios.com
2009 premium x64 bit
i like the cfiledialog class that ivana inserted above, i did not know it existed. is there a similar class for browsing and selecting just a folder?
dan miel
' example code for modshellfiledisk
'
' to try this example, do the following:
' 1. create a new form
' 2. create a command button named 'cmdbrowsefolder'
' 3. paste all the code from this example to the new form's module.
'*********************************************
' form1.frm
'*********************************************
private sub cmdbrowsefolder_click()
dim strpath as string
' example code for browseforfolder
strpath = browseforfolder( _
me.hwnd, _
"select a folder", _
mcstrexamplepath)
msgbox "the folder you selected is: " & strpath
end sub
'*********************************************
' module : modshellfiledisk
' description : routines for working with the windows
' source : total vb sourcebook 6
'
'*********************************************
option explicit
private const csidl_desktop = &h0
private const bif_returnonlyfsdirs = &h1
private type browseinfo
howner as long
pidlroot as long
pszdisplayname as string
lpsztitle as string
ulflags as long
lpfn as long
lparam as long
limage as long
end type
private declare function shgetpathfromidlist _
lib "shell32.dll" _
alias "shgetpathfromidlista" _
(byval pidl as long, _
byval pszpath as string) _
as long
private declare function shbrowseforfolder _
lib "shell32.dll" _
alias "shbrowseforfoldera" _
(lpbrowseinfo as browseinfo) _
as long
private declare function shgetspecialfolderlocation _
lib "shell32.dll" _
(byval hwndowner as long, _
byval nfolder as long, _
pidl as itemidlist) _
as long
private type shitemid
cb as long
abid as byte
end type
private type itemidlist
mkid as shitemid
end type
public function browseforfolder( _
lnghwnd as long, _
strmessage as string, _
optional strdefault as string) _
as string
' comments : prompts the user for the location of an
' existing directory
' parameters: lnghwnd - handle to window to serve as
' the parent for the dialog. use a form's
' hwnd property for example
' strmessage - prompt message to display on the
' dialog
' strdefault - value to return if the user
' hits 'cancel' to close the dialog
' returns : the path the user selected
' source : total vb sourcebook 6
'
dim bifolder as browseinfo
dim idllist as itemidlist
dim lngidlptr as long
dim lngresult as long
dim strpath as string
on error goto proc_err
' get the location of the user's desktop
shgetspecialfolderlocation lnghwnd, csidl_desktop, idllist
' set browseinfo options
with bifolder
.howner = lnghwnd
.pidlroot = idllist.mkid.cb
.lpsztitle = strmessage
.ulflags = bif_returnonlyfsdirs
end with
' show the browse for folder dialog
lngidlptr = shbrowseforfolder(bifolder)
' get the path indicated in the id list
strpath = space$(260)
lngresult = shgetpathfromidlist( _
byval lngidlptr, byval strpath)
if lngresult <> 0 then
strpath = left$(strpath, instr(1, strpath, vbnullchar) - 1)
else
' user hit 'cancel', use default
strpath = strdefault
end if
browseforfolder = strpath
proc_exit:
exit function
proc_err:
msgbox "error: " & err.number & ". " & err.description, , _
"browseforfolder"
resume proc_exit
end function
edited: 02/24/2009 at 04:57 pm by ivana kolin
thanks ivana
i am swamped at the moment but will be taking a look at this soon.
dan miel
ivana
i am trying the code for the folder browser but i keep getting a error message:
"compile error:method or data member not found" and the me.hwnd is high lighted. do you know what i'm doing wrong?
thanks
dan miel
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】dll学习(资料收集) huangyhg vc编程 0 2008-05-17 09:24 PM
OpenCSG-1.0.2 sample yogy vc编程 2 2007-07-22 04:43 PM
文件系统的操作 cad DirectDWG 0 2007-01-28 04:26 PM


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


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