几何尺寸与公差论坛

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

【转帖】sw2009 api sldworks.activatedoc290 causes background sw to become vis

[复制链接]
发表于 2009-4-12 22:34:56 | 显示全部楼层 |阅读模式
sw2009 api sldworks.activatedoc2() causes background sw to become visible
hello,
my vb.net program is running sw in the background, no problem initially, as sw stay invisible while it opens some files and outputs .dxf, .pdf versions ,etc.
...but then when the activatedoc2(....) method is called on an assembly, all of a sudden sw becomes visible in the backgound.
i have used
sldworks.usercontrol = false
sldworks.visible = false
...right at the beginning of my code, and sw does stay invisible for quite a good portion of the processing, but when the activatedoc2 () method is called to activate an assembly, sw suddenly makes itself visible?
code below:
imports solidworks.interop.sldworks
imports solidworks.interop.swconst
imports solidworks.interop.swpublished
imports solidworks.interop.swconst.swuserpreferenceintegervalue_e
imports solidworks.interop.swconst.swdocumenttypes_e
imports solidworks.interop.swconst.swopendocoptions_e
imports solidworks.interop.swconst.swsaveasoptions_e
imports solidworks.interop.swconst.swloadexternalreferences_e
imports solidworks.interop.swconst.swpromptalwaysnever_e
imports solidworks.interop.swconst.swuserpreferencetoggle_e
imports system
imports system.io
module module1
dim app as sldworks
dim log as streamwriter
sub main(byval cmdargs() as string)
dim model as modeldoc2
dim filename as string
dim topmodel as modeldoc2
dim errs as long
dim warns as long
dim retval as long
dim argnum as integer
dim logname as string = "c:\swexport.log"
if file.exists(logname) then
file.delete(logname)
end if
log = file.createtext(logname)
if cmdargs.length < 1 then
console.writeline("usage: swexport filename")
log.writeline("swexportfailure")
log.close()
exit sub
end if
' app = new sldworks
app = createobject("sldworks.application")
dim ret as boolean
' set user preferences.
ret = app.setuserpreferenceintegervalue(swloadexternalreferences, swloadexternalreferences_none)
ret = app.setuserpreferenceintegervalue(swperformanceassemrebuildonload, swresponsenever)
ret = app.setuserpreferenceintegervalue(swlargeasmmodeautoactivate, swresponsenever)
app.setuserpreferencetoggle(swedrawingsokaytomeasure, true)
'app = createobject("sldworks.application", "dbremne0d10eng.eng.emc.com")
'app = getobject("sldworks.application")
app.usercontrol = false
app.visible = false
app.loadaddin("c:\program files\bluebeam software\pushbutton pdf\solidworkslt\bbsldwkspdflt.dll")
'console.writeline("attempted to load pdf addin. status " + retval.tostring)
filename = cmdargs(0)
dim blankstring as string = string.empty
' determine document type based on file extension.
dim fileext as string
dim doctype as long
fileext = right(filename, 6)
select case fileext
case "sldprt"
doctype = swdocpart
case "sldasm"
doctype = swdocassembly
case "slddrw"
doctype = swdocdrawing
end select
' open document.
log.writeline("opening " + filename)
log.flush()
console.writeline("opening " + filename)
model = app.opendoc6( _
filename, _
doctype, _
swopendocoptions_silent, _
blankstring, _
errs, _
warns _
)
if model is nothing then
log.writeline("unable to open " + filename)
log.flush()
console.writeline("unable to open " + filename)
log.writeline("swexportfailure")
log.close()
cleanup()
exit sub
end if
log.writeline("opened " + filename)
log.flush()
topmodel = model
' export the document to the appropriate format.
exportdoc(model)
' if the document is a drawing, export the models associated with each
' view of each sheet.
if doctype = swdocdrawing then
exportdrwrefs(model)
end if
log.writeline("swexportsuccess")
log.close()
' release memory.
' app.quitdoc(topmodel.gettitle)
app.closealldocuments(true)
topmodel = nothing
cleanup()
end sub
sub exportdoc(byval model as modeldoc2)
dim doctype as long = model.gettype
dim errs as long
app.usercontrol = false
app.visible = false
app.activatedoc2(model.gettitle, true, errs) ' activate model
app.usercontrol = false
app.visible = false
' export appropriate files.
select case doctype
case swdocpart
exportmodel(model, "step")
'exportmodel(model, "igs")
exportmodel(model, "stl")
exportmodel(model, "eprt")
case swdocassembly
exportmodel(model, "step")
exportmodel(model, "easm")
'exportmodel(model, "igs")
case swdocdrawing
exportmodel(model, "pdf")
exportmodel(model, "dxf")
exportmodel(model, "edrw")
end select
end sub
sub exportmodel(byval model as modeldoc2, byval format as string)
dim spathroot as string
dim spathname as string
dim retval as boolean
dim errs as long
dim warns as long
spathroot = model.getpathname ' get path and file name
spathroot = left(spathroot, len(spathroot) - 6) ' strip file extension
spathname = spathroot + format ' add new file extension
log.writeline("writing " + spathname)
log.flush()
console.writeline("writing " + spathname)
' export model.
retval = model.saveas4( _
spathname, _
0, _
swsaveasoptions_silent, _
errs, _
warns _
)
log.writeline("status " + retval.tostring)
log.flush()
console.writeline("status " + retval.tostring)
end sub
sub exportdrwrefs(byval model as modeldoc2)
model.visible = false
' collect the models referenced by this drawing.
dim drwrefs as new hashtable
dim drawing as drawingdoc = model
dim sheetnames as object = drawing.getsheetnames
dim i as integer
for i = 0 to ubound(sheetnames) ' traverse drawing sheets
drawing.activatesheet(sheetnames(i))
dim view as solidworks.interop.sldworks.view
view = drawing.getfirstview
while not view is nothing ' traverse sheet views
model = view.referenceddocument ' get model referenced by view
if not model is nothing then
console.writeline("found drawing model " + model.gettitle + _
" in " + view.name)
' add models to hash to get unique file names.
if not drwrefs.containskey(model.gettitle) then
drwrefs.add(model.gettitle, model)
end if
end if
view = view.getnextview
end while
next
' export drawing references.
dim enumerator as idictionaryenumerator = drwrefs.getenumerator()
while enumerator.movenext()
exportdoc(enumerator.value)
end while
end sub
sub cleanup()
app.exitapp()
app = nothing
gc.collect()
end sub
end module
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 18:41 , Processed in 0.036670 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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