几何尺寸与公差论坛------致力于产品几何量公差标准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, 03:23 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】what am i doing wrong here select view

what am i doing wrong here? select view
i have some code below as part of my macro. if i do not select any view, i want a message box to pop-up stating "must select a view". i am getting an error stating
"run-time error '438': object doesn't support this property or method"
if i select a view, it works.
any ideas what i am doing wrong? am i using the right call for getting the view?
is swselmgr.getselectedobject6 the correct call?
cswp
solidworks office professional 2008, sp 3.1
pc #1:
dell precision t3400, core2duo 2.33ghz, 4gb ram,
nvidia quadro fx 1700
pc #2:
dell precision 380, p4 3.80ghz, 2gb ram,
nvidia quadro fx 1400
use on error resume next
marc
on error resume next
set sw_view = swselmgr.getselectedobject5(1)
if sw_view is nothing = true then
swapp.sendmsgtouser2 "select view.... ", swmbwarning, swmbok
exit sub
end if
on error goto 0
when i run this the first time, it works. but if i select "no" on the dialog box, the macro ends. if i rerun the macro without selecting a view, the view = nothing and the entire macro runs. it skips the part that states "if view is nothing goto fail"
any ideas?
dim swapp as object
dim txtviewname as string
dim swselmgr as sldworks.selectionmgr
dim swmodel as sldworks.modeldoc2
dim swdrawing as sldworks.modeldoc2
sub main()
set swview = nothing
set swapp = application.sldworks
set swdrawing = swapp.activedoc
set swmodel = swapp.activedoc
set swselmgr = swmodel.selectionmanager
on error resume next
set swview = swselmgr.getselectedobject6(1, 0)
msgbox swview
if swview is nothing then
' tell the user that nothing is selected
swapp.sendmsgtouser2 "please select a drawing view.", swmbwarning, swmbok
goto fail
end if
txtviewname = swview.getreferencedmodelname
msgbox "the selected view is " + txtviewname
filename = txtviewname
'sets save path for dxf files
savepath = "n:\dxfnew\"
' sets file extension used for this macro
fext = ".dxf"
dotpos = instrrev(filename, ".")
slashpos = instrrev(filename, "\")
if dotpos <> 0 then ' if contains a dot (extension exists) then chop off extension
filename = mid(filename, slashpos + 1, dotpos - slashpos - 1)
else 'does not contain a dot
filename = right(filename, len(filename) - slashpos)
end if
'get revision for filename
revnum = swdrawing.getcustominfovalue("", "revision")
if revnum < 10 then
revnumfname = "0" + revnum
else
revnumfname = revnum
end if
' sets dxf file full path
filesave = savepath + filename + "_" + revnumfname + fext
iresponse = msgbox("the dxf will be saved to..." + chr(13) + chr(13) + filesave + chr(13) + chr(13) + "is this correct?", vbyesno + vbquestion, "dxf will be saved to...")
if iresponse = vbno then
goto fail
else
end if
fail:
end sub
cswp
solidworks office professional 2008, sp 3.1
pc #1:
dell precision t3400, core2duo 2.33ghz, 4gb ram,
nvidia quadro fx 1700
pc #2:
dell precision 380, p4 3.80ghz, 2gb ram,
nvidia quadro fx 1400
declare
dim sw_view as sldworks.view
marc
originally posted by: marc sylvain
declare
dim sw_view as sldworks.view
marc
yea, i left that out of the last one.
now i get "type mismatch" on
set swview = swselmgr.getselectedobject6(1, 0)
cswp
solidworks office professional 2008, sp 3.1
pc #1:
dell precision t3400, core2duo 2.33ghz, 4gb ram,
nvidia quadro fx 1700
pc #2:
dell precision 380, p4 3.80ghz, 2gb ram,
nvidia quadro fx 1400
answer if you use the on error resume next before set swview = swselmgr.getselectedobject5(1)
the swview =nothing if your selection not equal view
and use the on error goto 0 to reset
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swselmgr = swmodel.selectionmanager
on error resume next
set sw_view = swselmgr.getselectedobject5(1)
if sw_view is nothing = true then
swapp.sendmsgtouser2 "please select a drawing view", swmbwarning, swmbok
exit sub
end if
on error goto 0 'reset on error
originally posted by: marc sylvain
if you use the on error resume next before set swview = swselmgr.getselectedobject5(1)
thanks. seems to work now. i dont understand what was going on before, can you explain why i was getting the "type mismatch" error?
cswp
solidworks office professional 2008, sp 3.1
pc #1:
dell precision t3400, core2duo 2.33ghz, 4gb ram,
nvidia quadro fx 1700
pc #2:
dell precision 380, p4 3.80ghz, 2gb ram,
nvidia quadro fx 1400
if you click in the space on the draft, solidworks select the current sheet but
if you run the macro the selection equal sheet
marc
i have also found that it is more helpful to set the drawing to the model, as in:
set swmodel = swapp.activedoc
set swdrawing = swmodel
that way, there is no chance that swmodel would be different (in property) to swdrawing.
to defeat the wheat, go against the grain.
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】get x,y,z of drawing view vertexedge yang686526 SolidWorks二次开发 0 2009-04-13 11:03 AM
【转帖】drawing view placements yang686526 SolidWorks二次开发 0 2009-04-13 10:35 AM
【转帖】can you modelize a drawing view yang686526 SolidWorks二次开发 0 2009-04-13 09:31 AM
【转帖】c++中动态内存分配引发问题的解决方案(转) huangyhg vc编程 0 2008-10-27 11:37 AM


所有的时间均为北京时间。 现在的时间是 01:45 AM.


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