• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

automatic creation ipart members and export step

3olo

Guest
Hello.
I've made some ipart parts from which I'll generate a few thousand components each.
This is not a problem, already done,the problem is that I should make each step in order to be able to share it with other modelers.
I currently put all the parts generated in a set and fatigue I built an ilogic rule that converts all the components of this together in step format.
I ask politely if someone is able to write a rule that generates all the members of the ipart and then automatically exposes each of these generated members in step.
I'm a little VB hardware and I can't.
You'd do me a great pleasure.
Thank you very much in advance
 
you are lucky because one of the examples in the programming guide does what you ask
(help ina alto a dx > community resources > programming guide > index, search ipartfactory object, at the bottom of the page links to examples.
If you already have ilogic rudiments you should have no problem
Code:
public sub addipartoccurrence()
    ' open the factory document invisible.
    dim ofactorydoc as partdocument
    set ofactorydoc = thisapplication.documents.open("c:\temp\ipartfactory.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("c:\temp\ipartfactory.ipt ", opos, irow)
    next
end sub
or better, it doesn't do exactly what you want but with your rule already made you are fine... this program puts together all the elements of an ipart
 
grandissimo! grazie mille! in realtà sono ancora molto neanderthal con ilogic e uso questa regola per esportare tutte le parti di un assieme in iges ,l'ho trovata su un forum che non mi ricordo al momento,ma funziona alla perfezione

'define the open document
dim opendoc as document
opendoc = thisdoc.document

'define folder to create files in
ofolder = "c:\temp\igs files"

'check for the destination folder and create it if it does not exist
if not system.io.directory.exists(ofolder) then
system.io.directory.createdirectory(ofolder)
end if

'look at all of the files referenced in the open document
dim docfile as document
for each docfile in opendoc.allreferenceddocuments
'format file name
dim fnamepos as long
'postion of last back slash
fnamepos = instrrev(docfile.fullfilename, "\", -1)
dim docfname as string
'file name with extension
docfname = right(docfile.fullfilename, len(docfile.fullfilename) - fnamepos)
'file name without extension
shortname = left(docfname, len(docfname) -4)

' get the iges translator add-in.
dim oigestranslator as translatoraddin
oigestranslator = thisapplication.applicationaddins.itembyid _
("{90af7f44-0c01-11d5-8e83-0010b541cd80}")
dim ocontext as translationcontext
ocontext = thisapplication.transientobjects.createtranslationcontext
dim ooptions as namevaluemap
ooptions = thisapplication.transientobjects.createnamevaluemap
if oigestranslator.hassavecopyasoptions(docfile, ocontext, ooptions) then
' set geometry type for wireframe.
' 0 = surfaces, 1 = solids, 2 = wireframe
'ooptions.value("geometrytype") = 1
' to set other translator values:
' ooptions.value("solidfacetype") = n
' 0 = nurbs, 1 = analytic
' ooptions.value("surfacetype") = n
' 0 = 143(bounded), 1 = 144(trimmed)
ocontext.type = iomechanismenum.kfilebrowseiomechanism
dim odata as datamedium
odata = thisapplication.transientobjects.createdatamedium
'set file path for igs file
odata.filename = ofolder & "\" & shortname & ".igs"
oigestranslator.savecopyas(docfile, ocontext, ooptions, odata)
end if
next


secondo te basta che lo ce la aggiungo sotto nella stessa regola che hai postato tu per fare quello che chiedo? al momento mi esporta in iges, ma se volessi esportare in step come potrei fare?non mi piace molto iges perché sono files più pesanti di quelli in formato step. ti ringrazio ancora
 
I have a couple of examples, I think it works. . .
Code:
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
 
Thank you very, very kind, I'm in the office and then I'll let you know. Thank you very much for your help
 
Good morning, I tried it, but first inventor gave me a message that all sub and function instructions should be placed after sub main(), then I renamed it sub main.
When I restarted it inventor gave me the message that the instructions let and set are no longer supported.... boh! where am I wrong? I create the rule from the ilogic menu of inventor and then I start it, I have to make it turn somehow?
 
was not an ilogic rule but a vba program (which is compatible with ilogic); from the messages you think you can simply try to remove the set instruction (they are before assignments of variables, like "set opposite = ...")
 
Thank you very much, but I managed to make it turn using the built-in editor in inventor. It's like a splinter. Thanks again
 
I congratulate you on the use of programming. However under the inventor tools (from the start menu) there is programming operations.
between scheduled operations you can use "convert files", then select the starting ipts and as the arrival file the step. then give the way and do all of it.
Hi.
 
hi, the problem is that the ipt is only one, but the members of such ipt are thousands, being an ipart. By converting that file there I don't do anything about it, it's all its members that must be generated and converted at the same time. the macro published above does just that
 
hi, the problem is that the ipt is only one, but the members of such ipt are thousands, being an ipart. By converting that file there I don't do anything about it, it's all its members that must be generated and converted at the same time. the macro published above does just that
open the ipt and open the ipart list on the browser (do not enter the edit window but simply view members on the browser node). then select all members > button dx > generates files. you find all the ipts in the subfolder that you create under the basic ipt. then automatically make the steps of that folder.
 
are two roads, but the macro does everything at once
In fact, mine was not a criticism and I complimented you.
I simply added a second manual way for those who are not programmer and who knows that turning between the possibilities of planned operations someone does not find the answer already made to his problem.
 
we would miss it! thank you! among other things plan operations I use to convert groups of tables usually, I didn't think it could come back useful also for exports! can come back very useful your point, so maybe one who has so many ipts to convert can do everything so. a thousand, every point is more than well accepted. Thanks again
 
I reopen the thread because I would like to ask for help to make a small improvement to the macro: currently this macro generates all the members of the ipart then creates a set, puts all the members generated in that set, stops asking you where to save this together and with what name, then generates all the steps of the members. I wanted to ask if someone can automatically save the axieme by setting a default name, so just throw the macro and he arranges from start to finish without blocking.
Thank you very much
 
hi 3eolo, could you tell me how you made it work through vba editor?? ? ?
with some image of where you upload the program. I indicated 3eolo because it was he wrote that it worked through vba editor
but whoever knows how to disappoint me and accept

Thank you very much

I tried to load this little program from the internet1616566763493.webpbut I'm wrong
and if the load with ilogic gives me the same error cited by 3elo more on
"Good morning, I tried it, but first inventor gave me a message that all sub and function instructions should be placed after sub main(), then I renamed it sub main."
 
to me in the English version works:
Code:
public sub createsmtest()
    dim asmdoc as assemblydocument
    set asmdoc = thisapplication.activedocument
    
    dim occ as componentoccurrence
    for each occ in asmdoc.componentdefinition.occurrences
        dim partdoc as partdocument
        set partdoc = occ.definition.document
        
        ' make the part document visible.
        partdoc.views.add
        
        ' convert it to a sheet metal type.
        partdoc.subtype = "{9c464203-9bae-11d3-8bad-0060b0ce6bb4}"
        
        dim smdef as sheetmetalcomponentdefinition
        set smdef = partdoc.componentdefinition
        
        ' unfold the part.  this will activate the flat pattern environment.
        'smdef.unfold (ho tolto)
        
        ' exit the flat pattern environment.
        'smdef.flatpattern.exitedit (ho tolto)
        
        ' close and save the document.  this will close the view but it will
        ' actually remain open because the assembly is still referencing it.
        call partdoc.close(true)
    next
end sub
if you know how to set the thickness ok. if not after the vba macro try to use the ilogic rule as explained here:
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top