Message 1 of 8

Not applicable
06-19-2015
07:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello ,
I do mechanical design and use a macro in vba to automate a process of generate iparts members and export them in step format . I hope to explain myself well .
This macro automatically a command to create some components one by one ( thousands ) , these components are then inserted in an assembly that has the extension * .iam and then thanks to this are converted automatically always in * .stp . my problem is that it works perfectly but currently the macro hangs upon creation of the file * .iam , asks me location and name for saving , then starts again . I wanted to ask if you can make the macro a name in the subject with a certainposition automatically ( so then once finished this process no longer need this file * .iam , precisely serves only to macro to convert all files created , usually then delete it ) . In this way I could do from the macro and the pc would all automatically start to finish .
I place the code and I highlight the save point where I would like the file * .iam was named and saved automatically .
Thank you in advance
Public Sub AddiPartOccurrence2()
' Open the factory document invisible.
Dim oFactoryDoc As PartDocument
Set oFactoryDoc = ThisApplication.Documents.Open("D:\chiavetta 21-12\disegni inventor\2\000progetto\parti\tra.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("D:\chiavetta 21-12\disegni inventor\2\000progetto\parti\tra.ipt", oPos, iRow)
Next
oDoc.Save '----------------thisis the Point where it ask me name and path of *.iam!!!
Dim oRefDoc As Document
For Each oRefDoc In oDoc.ReferencedDocuments
Call ExportToSTEP2(oRefDoc)
Next
End Sub
Public Sub ExportToSTEP2(oDoc As Document)
Dim exportPath As String
exportPath = "D:\chiavetta 21-12\disegni inventor\"
' 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") = "Boeing SPA"
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 do mechanical design and use a macro in vba to automate a process of generate iparts members and export them in step format . I hope to explain myself well .
This macro automatically a command to create some components one by one ( thousands ) , these components are then inserted in an assembly that has the extension * .iam and then thanks to this are converted automatically always in * .stp . my problem is that it works perfectly but currently the macro hangs upon creation of the file * .iam , asks me location and name for saving , then starts again . I wanted to ask if you can make the macro a name in the subject with a certainposition automatically ( so then once finished this process no longer need this file * .iam , precisely serves only to macro to convert all files created , usually then delete it ) . In this way I could do from the macro and the pc would all automatically start to finish .
I place the code and I highlight the save point where I would like the file * .iam was named and saved automatically .
Thank you in advance
Public Sub AddiPartOccurrence2()
' Open the factory document invisible.
Dim oFactoryDoc As PartDocument
Set oFactoryDoc = ThisApplication.Documents.Open("D:\chiavetta 21-12\disegni inventor\2\000progetto\parti\tra.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("D:\chiavetta 21-12\disegni inventor\2\000progetto\parti\tra.ipt", oPos, iRow)
Next
oDoc.Save '----------------thisis the Point where it ask me name and path of *.iam!!!
Dim oRefDoc As Document
For Each oRefDoc In oDoc.ReferencedDocuments
Call ExportToSTEP2(oRefDoc)
Next
End Sub
Public Sub ExportToSTEP2(oDoc As Document)
Dim exportPath As String
exportPath = "D:\chiavetta 21-12\disegni inventor\"
' 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") = "Boeing SPA"
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
Solved! Go to Solution.