3olo
Utente Junior
professione: libero professionista
software: inventor 2011,2013, autocad
regione: Trento
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
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