public sub addipartoccurrence()
' open the factory document invisible.
dim ofactorydoc as partdocument
set ofactorydoc = thisapplication.documents.open("w:\commesse\aia\15030_modifica zona lavatrici\assieme2.c02.ipt", false)
' set a reference to the component definition.
dim ocompdef as partcomponentdefinition
set ocompdef = ofactorydoc.componentdefinition
' make sure we have an ipart factory.
if ocompdef.isipartfactory = false then
msgbox "chosen document is not a factory.", vbexclamation
exit sub
end if
' set a reference to the factory.
dim oipartfactory as ipartfactory
set oipartfactory = ocompdef.ipartfactory
' get the number of rows in the factory.
dim inumrows as integer
inumrows = oipartfactory.tablerows.count
' create a new assembly document
dim odoc as assemblydocument
set odoc = thisapplication.documents.add(kassemblydocumentobject, , true)
dim ooccs as componentoccurrences
set ooccs = odoc.componentdefinition.occurrences
dim opos as matrix
set opos = thisapplication.transientgeometry.creatematrix
dim ostep as double
ostep = 0#
dim irow as long
' add an occurrence for each member in the factory.
for irow = 1 to inumrows
ostep = ostep + 10
' add a translation along x axis
opos.settranslation thisapplication.transientgeometry.createvector(ostep, ostep, 0)
dim oocc as componentoccurrence
set oocc = ooccs.addipartmember("w:\commesse\aia\15030_modifica zona lavatrici\assieme2.c02.ipt", opos, irow)
next
odoc.save
dim orefdoc as document
for each orefdoc in odoc.referenceddocuments
call exporttostep(orefdoc)
next
end sub
public sub exporttostep(odoc as document)
dim exportpath as string
exportpath = "c:\stp\"
' get the step translator add-in.
dim osteptranslator as translatoraddin
set osteptranslator = thisapplication.applicationaddins.itembyid("{90af7f40-0c01-11d5-8e83-0010b541cd80}")
if osteptranslator is nothing then
msgbox "could not access step translator."
exit sub
end if
dim ocontext as translationcontext
set ocontext = thisapplication.transientobjects.createtranslationcontext
dim ooptions as namevaluemap
set ooptions = thisapplication.transientobjects.createnamevaluemap
if osteptranslator.hassavecopyasoptions(thisapplication.activedocument, ocontext, ooptions) then
' set application protocol.
' 2 = ap 203 - configuration controlled design
' 3 = ap 214 - automotive design
ooptions.value("applicationprotocoltype") = 3
' other options...
'ooptions.value("author") = ""
'ooptions.value("authorization") = ""
'ooptions.value("description") = ""
'ooptions.value("organization") = ""
ocontext.type = kfilebrowseiomechanism
dim odata as datamedium
set odata = thisapplication.transientobjects.createdatamedium
'format file name
dim fnamepos as long
'postion of last back slash
fnamepos = instrrev(odoc.fullfilename, "\", -1)
dim docfname as string
'file name with extension
docfname = strings.right(odoc.fullfilename, len(odoc.fullfilename) - fnamepos)
'file name without extension
dim shortname as string
shortname = strings.left(docfname, len(docfname) - 4)
odata.filename = exportpath & shortname & ".stp"
call osteptranslator.savecopyas(odoc, ocontext, ooptions, odata)
end if
end sub