几何尺寸与公差论坛

 找回密码
 注册
查看: 1205|回复: 0

【转帖】what am i doing wrong here select view

[复制链接]
发表于 2009-4-13 15:23:22 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 13:04 , Processed in 0.036042 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表