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

disconnect ipart members automatically, macro

3olo

Guest
salve,
sbuffando e a fatica sojno riuscito a crearmi una macro in inventor i per la generazione automatica dei membri di una ipart e la relative conversiojne in formato step. la uso con soddisfazione da un po’ e fa tutto da sola. nello specifico:
-genera tutti i membri di un ipart;
-li mette tutti in un assieme pilota e lo salva;
-ltutti tali files vengono esportati in step e messi in una cartella .
spettacolo finora: però ho l’esigenza di creare migliaia di membri , tenere per me l’ipart e fornire solamente i membri ,però il problema è che ovviamente una volta aperti non trovano il collegamento con l’ipart(non essendoci) e danno un messaggio di errore a cui si deve dare ignora. cio’ è molto fastidioso.
vorrei quindi modificare la macro in modo che ogni membro dell’ipart venga scollegato dall’ipart ,in modo da non aver più messaggi.
cercando nella guida di inventor api ho trovato una funzione che forse fa al caso mio:
ipartmember.breaklinktofactory()
description
method that breaks the link to the parent factory and converts the ipart member to a derived part.

dovrebbe essere quest ache mi serve.
però essendo un po’ limitato io con vba non sono in grado di inserirla nella mia macro in modo che funzioni.
c’è qualche buon anima che mi può aiutare? se non riuscite a modificare la macro mi basterebbe averne una nuova in cui magari si scolleghino tutti i componenti inseriti in un assieme.
vi prego aiutatemi che non so più dove sbattere la testa. vi ringrazio tanto in anticipo



public sub addipartoccurrence()
' open the factory document invisible.
dim ofactorydoc as partdocument
set ofactorydoc = thisapplication.documents.open("c:\disegni inventor\prova ipart1.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:\disegni inventor\prova ipart1.ipt", opos, irow)

next

'odoc.save
call odoc.saveas("c:\disegni inventor\assiemecancella.iam", true)

dim orefdoc as document
for each orefdoc in odoc.referenceddocuments
ipartmember.breaklinktofactory (orefdoc)
call exporttostep(orefdoc)

next


end sub

public sub exporttostep(odoc as document)

dim exportpath as string
exportpath = "c:\disegni inventor\stpcanc\"

' 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
 
I think this works. . .
Code:
dim opart as partdocument
for each opart in odoc.referenceddocuments
    opart.componentdefinition.ipartmember.breaklinktofactory
next
 
Thank you so much, where do you take it? before the sub end?
I would say before:
dim orefdoc as document
for each orefdoc in odoc.referenceddocuments
imemberpart.breaklinktofactory (orefdoc)
call exporttostep(orefdoc)

next

from which he eliminates
imemberpart.breaklinktofactory (orefdoc)

do tests on something not vital anyway, from the (just and fast) tests that I did the operation seems the one required but I did not deepen what happens to the iparts with broken connection.. .
 
Very kind! I try and let you know! and if you want to make a macro with this code that opens me a set with within the members of ipart and disconnects me? you could throw down a quick draft? so bypassamdo the part generation and export step.
 
I tried and worked on some iparts, on others not, in the sense that it interrupts the links, but then to make actual changes I should save the created pilot axieme (and all its components of course) however, when I try to save all inventor crashes, probably for the large number of components to be saved.
I thought then to add the "save2" function that is in the inventor bees guide relative to the rescue of the assemblies and related components, but I don't understand how to write it, can you help me?
I tried
odoc.save2( true, ) but nothing
call odoc.save2(true,) nothing even with this
odoc.save2(true,0) nothing

Can you please help me? I would insert between the breaklink and the export of the components, I think it is correct to put it there, but tell me you
 
I don't have much time at this time, if you have patience, I try to give an eye. I don't think crashes are due to the amount of components: inventor would be to be thrown in that case. But I don't know what happens with the disconnected iparts, I use the very few iparts and I have no idea how they behave... You have to study on it.
 
Sorry to interrupt, thank you for your patience!
when you have time if you want to take a look
 

Forum statistics

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

Members online

No members online now.
Back
Top