if thisapplication.activedocument.documenttype <> documenttypeenum.kassemblydocumentobject then
messagebox.show("please run this rule from the assembly file.", "ilogic")
exit sub
end if
'define the active document as an assembly file
dim oasmdoc as assemblydocument = thisapplication.activedocument
dim oassydef as assemblycomponentdefinition
oassydef = oasmdoc.componentdefinition
dim obom as bom
obom = oassydef.bom
obom.partsonlyviewenabled = true
'change item("parts only") to item(3) or your language specific description
'if you don't run inventor english
dim obomview as bomview = obom.bomviews.item("parts only")
dim obomrow as bomrow
for each obomrow in obomview.bomrows
'set a reference to the primary componentdefinition of the row
dim ocompdef1 as componentdefinition
ocompdef1 = obomrow.componentdefinitions.item(1)
dim compfulldocumentname as string = ocompdef1.document.fulldocumentname
dim compfilenameonly as string
dim index as integer = compfulldocumentname.lastindexof("\")
compfilenameonly = compfulldocumentname.substring(index+1)
'messagebox.show(compfilenameonly)
dim qty as string
qty = obomrow.totalquantity
iproperties.value(compfilenameonly, "custom", "qty") = qty
next
dim oasmname = oasmdoc.displayname.replace(".iam", "")
'get user input
rusure = messagebox.show ( _
"this will create a dxf file for all of the asembly components that are sheet metal." _
& vblf & "this rule expects that the part file is saved." _
& vblf & " " _
& vblf & "are you sure you want to create dxf for all of the assembly components?" _
& vblf & "this could take a while.", "ilogic - batch output dxfs ",messageboxbuttons.yesno)
if rusure = vbno then
return
end if
opath = thisdoc.path
odatamedium = thisapplication.transientobjects.createdatamedium
ocontext = thisapplication.transientobjects.createtranslationcontext
ocontext.type = iomechanismenum.kfilebrowseiomechanism
ooptions = thisapplication.transientobjects.createnamevaluemap
'get dxf target folder path
ofolder = opath & "\" & oasmname & " - laser"
'check for the dxf folder and create it if it does not exist
if not system.io.directory.exists(ofolder) then
system.io.directory.createdirectory(ofolder)
end if
'- - - - - - - - - - - - -component - - - - - - - - - - - -
'look at the files referenced by the assembly
dim orefdocs as documentsenumerator
orefdocs = oasmdoc.allreferenceddocuments
dim orefdoc as document
'work the the drawing files for the referenced models
'this expects that the model has been saved
for each orefdoc in orefdocs
iptpathname = left(orefdoc.fulldocumentname, len(orefdoc.fulldocumentname) - 3)& "ipt"
'check that model is saved
if(system.io.file.exists(iptpathname)) then
dim odrawdoc as partdocument
odrawdoc = thisapplication.documents.open(iptpathname, false)
ofilename = left(orefdoc.displayname, len(orefdoc.displayname))
ofilename1 = orefdoc.displayname.replace(".ipt", "")
dim ocompdef as sheetmetalcomponentdefinition = odrawdoc.componentdefinition
try
'set the dxf target file name
try
customname =iproperties.value(ofilename, "custom", "qty")
catch
customname ="xxx" 'wert, wenn ipropertie pf_prt_znr nicht existiert
end try
dim material as string = orefdoc.activematerial.displayname
othickness = orefdoc.componentdefinition.thickness.value*10
odatamedium.filename = ofolder & "\" & ofilename1 & " - " & material & " "& othickness &"mm - " & customname & " off.dxf"
ocompdef = odrawdoc.componentdefinition
dim sout as string
sout = "flat pattern dxf?acadversion=2004&outerprofilelayer=iv_outer_pr?ofile"
ocompdef.dataio.writedatatofile( sout, odatamedium.filename)
ocompdef.flatpattern.exitedit
catch
end try
odrawdoc.close
else
end if
next