Convert all Members of an iAssembly Factory to STP files

Convert all Members of an iAssembly Factory to STP files

rodneyleedav
Participant Participant
1,945 Views
24 Replies
Message 1 of 25

Convert all Members of an iAssembly Factory to STP files

rodneyleedav
Participant
Participant

I searched the forums and found answers to similar questions but not the exact process I would like to achieve.

 

I have an iAssembly with 720 members in the factory.  I would like to use iLogic to export each member to a *.stp file so I don't have to do it manually.

 

I am unfamiliar with the code but I managed to merge the code from 3 different forum posts to create what I have below.  It will open each factory member, save it as a *.iam assembly, and close it, but it does not export it as a *.stp file. It also ignores the path I specify and creates a new folder with the same name as the assembly.

 

Does anyone have any suggestions on the code changes needed to get this to export each member as a *.stp file?

 

' Set reference to active document.
oDoc = ThisApplication.ActiveDocument

' Check the Document type is an assembly or part
If (oDoc.DocumentType <> kAssemblyDocumentObject And _
   oDoc.DocumentType <> kPartDocumentObject) Then
   MsgBox("Error:Document type is not assembly/part")
   Exit Sub
End If

Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 
Dim initRowIndex As Integer
Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory

Dim oRow As iAssemblyTableRow
Dim oMember As iAssemblyMember 
For Each oRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)

	Dim oPath As String 
	oPath = oFactory.MemberCacheDir

	Dim oReferDoc As AssemblyDocument 
    oReferDoc = ThisApplication.Documents.Open(oPath & "\" & oRow.MemberName & ".iam", True)
    
    'Dim oName As String
    'oName = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
     
    ThisApplication.SilentOperation = True
	
	' Get the STEP translator Add-In.
	Dim oSTEPTranslator As TranslatorAddIn
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	partNumber = iProperties.Value("Project", "Part Number")

	SavePath = "C:\Users\Inventor\Part Files\Step Files\"
		
	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 = IOMechanismEnum.kFileBrowseIOMechanism
	    Dim oData As DataMedium
	    oData = ThisApplication.TransientObjects.CreateDataMedium
	    oData.FileName = SavePath & partNumber & ".stp"
		oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
	End If
    
    oReferDoc.Close
	
	ThisApplication.SilentOperation = False 
	
Next

 

0 Likes
Accepted solutions (2)
1,946 Views
24 Replies
Replies (24)
Message 2 of 25

WCrihfield
Mentor
Mentor
Accepted solution

Hi @rodneyleedav.  I copied your code, rearranged some of it to be more efficient, deleted some stuff, and corrected some stuff.  There was a lot of code that did not need to be down within the loop, and could have been placed before the loop starts, so I moved it.  In your SaveCopyAs line, you were using ThisApplication.ActiveDocument, which was part of the problem, because that is always the main document that was open when the code first started, not the member document that you opened within the loop.  The line getting Part Number using the iLogic shortcut snippet "iProperties.Value()" was always looking at the main assembly too, instead of the member document within the loop, so I switched it to using the Inventor API route, like you had already been looking into with your oName variable.

Try this version of the code, and see if it works better:

' Set reference to active document.
Dim oDoc As Document = ThisApplication.ActiveDocument
' Check the Document type is an assembly or part
If (oDoc.DocumentType <> kAssemblyDocumentObject And _
   oDoc.DocumentType <> kPartDocumentObject) Then
   MsgBox("Error:Document type is not assembly/part")
   Exit Sub
End If
'<<<< THIS NEXT LINE WILL FAIL IF IT IS A PART >>>>
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 
Dim initRowIndex As Integer
Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
Dim oPath As String = oFactory.MemberCacheDir
Dim SavePath As String = "C:\Users\Inventor\Part Files\Step Files\"

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium

ThisApplication.SilentOperation = True
For Each oRow As iAssemblyTableRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)
	Dim oReferDoc As AssemblyDocument 
    oReferDoc = ThisApplication.Documents.Open(oPath & "\" & oRow.MemberName & ".iam", True)
    Dim partNumber As String
    partNumber = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		
	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") = ""
	    
	    oData.FileName = SavePath & partNumber & ".stp"
		oSTEPTranslator.SaveCopyAs(oReferDoc, oContext, oOptions, oData)
	End If
    oReferDoc.Close
Next
ThisApplication.SilentOperation = False 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 25

rodneyleedav
Participant
Participant

That works perfectly - thank you!

 

It still creates a folder with the same name as the assembly and saves all of the factory member assemblies in it, but it is easy enough to delete that folder after the process is complete.

0 Likes
Message 4 of 25

WCrihfield
Mentor
Mentor

Hi @rodneyleedav.  I'm glad I was able to help.  I just saw something that apparently I did not see before within the code I posted.  In the line of code where it is checking 'HasSaveCopyAsOptions', that is also using 'ThisApplication.ActiveDocument', when it should be using the 'oReferDoc' variable there, just like within the SaveCopyAs line later in that loop.  You should replace that.  I am not really sure why it is creating a sub folder with the assembly's name.  Does the iAssembly member's Part Number contain the name of the main iAssembly, followed by the "\" symbol, then more text that is unique to that member?  If so, you may have to consider removing that "\" symbol, because it is being seen as a directory separator in the file path.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 25

rodneyleedav
Participant
Participant

I replaced the ReferDoc variable as you suggested.  It did not seem to affect the operation of the code but I will keep it for future reference.

 

The iAssembly member's Part Number does not contain the name of the main iAssembly.  It is the 6-digit Part Number followed by .iam just as you would expect it to be named.  If the part number is ABC123, the assembly is named ABC123.iam. 

 

All of the assemblies are saved in a directory named after the main assembly.  If the main assembly is XYZ456.iam, the directory is named XYZ456.  It is all very logical, just not apparent to me in the code. 

 

It is an easy task to delete the assembly folder and all of its contents once the export is complete so I don't mind the creation of the assemblies.

 

Thanks again for fixing my code!  I would not have solved it without your assistance.

 

0 Likes
Message 6 of 25

rodneyleedav
Participant
Participant

Hi @WCrihfield 

 

I shared this with my co-workers and one of them would like to use it for an iPart file. 

 

However, you put in the comments that one line will fail if the file is a part.  Is it possible to add code to allow both iParts and iAssemblies to work?  If not, is it possible to have a separate code that works with iParts only?

 

Thanks for all your assistance!

0 Likes
Message 7 of 25

WCrihfield
Mentor
Mentor

Hi @rodneyleedav.  I can certainly look into it for you.  There were actually several lines of code throughout that rule that would either throw errors or cause problems if it encountered a part, instead of an assembly.  I would suggest having two different rules in this situation...one for parts and one for assemblies.  The alternative would be a much larger rule with multiple sections or routines, such as a Sub Main...End Sub area, then multiple other custom Sub or Function type routines that could be called within the Main routine area, and that can get a little confusing to understand, maintain, or edit if you are just getting started with iLogic coding.  I have multiple projects on my desk right now at work, but I will try to work on this for you as time permits.  It shouldn't be that difficult or time consuming though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 25

WCrihfield
Mentor
Mentor
Accepted solution

Hi @rodneyleedav.  Here is something you can try out.  This code is a bit longer than the other, because I took the time to add in some extra checks and efficiency in there.  These types of edits can be sort of copied from this part version to the assembly version, but not exactly.  For instance the iPartFactory object is different than the iAssemblyFactory object, and IsiPartFactory is not the same as IsiAssemblyFactory, and PartDocument vs AssemblyDocument, and PartComponentDefinition vs AssemblyComponentDefinition, ".ipt" vs ".iam", and such things like that.  A few of the variable names are different in this version too, so watch out for that, if you copy any code from one to the other.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
   MsgBox("Error:Document type is not part", vbCritical, "Wrong Document Type")
   Exit Sub
End If
Dim oPDoc As Document = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oPFactory As iPartFactory = Nothing
If oPDef.IsiPartFactory Then
	oPFactory = oPDef.iPartFactory
ElseIf oPDef.IsiPartMember Then
	oPFactory = oPDef.iPartMember.ParentFactory
End If
If IsNothing(oPFactory) Then
	MsgBox("This Part is not an iPartFactory or an iPartMember.  Exiting.", vbCritical, "")
	Exit Sub
End If
Dim sPath As String = oPFactory.MemberCacheDir
Dim SavePath As String = "C:\Users\Inventor\Part Files\Step Files\"

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oData As DataMedium = oTO.CreateDataMedium

ThisApplication.SilentOperation = True
Dim oDocs As Inventor.Documents = ThisApplication.Documents
Dim oRows As iPartTableRows = oPFactory.TableRows
For Each oRow As iPartTableRow In oRows
	' Generate the member and file, (overwrites member file or creates new file)
	oPFactory.CreateMember(oRow)
	Dim oRefDoc As PartDocument = oDocs.Open(sPath & "\" & oRow.MemberName & ".ipt", True)
    Dim partNumber As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	If oSTEPTranslator.HasSaveCopyAsOptions(oRefDoc, oContext, oOptions) Then
	    ' Set application protocol.
	    ' 2 = AP 203 - Configuration Controlled Design
	    ' 3 = AP 214 - Automotive Design
	    oOptions.Value("ApplicationProtocolType") = 3
	    'oOptions.Value("Author") = ""
	    'oOptions.Value("Authorization") = ""
	    'oOptions.Value("Description") = ""
	    'oOptions.Value("Organization") = ""

		oData.FileName = SavePath & partNumber & ".stp"
		Try
			oSTEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oData)
		Catch
			MsgBox("Error with SaveCopyAs method.", vbExclamation, "")
		End Try
	End If
    oRefDoc.Close
Next
ThisApplication.SilentOperation = False 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 25

rodneyleedav
Participant
Participant

@WCrihfield That works great!  Now we have two rules - one for iParts and the other for Assemblies. Thanks again for all of your assistance!!

0 Likes
Message 10 of 25

rodneyleedav
Participant
Participant

I attempted to edit the Path so it saves in a sub-folder of the path that the assembly is in.  Instead, it creates a subfolder with the same name as the assembly and puts my sub-folder under that.

 

Is there a way to put my sub-folders in the same folder as the assembly?

 

' Check if the file type is correct.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
   MsgBox("Error:Document type is not an assembly", vbCritical, "Wrong Document Type")
   Exit Sub
End If
' Set reference to active document.
Dim oDoc As Document = ThisApplication.ActiveDocument
'<<<< THIS NEXT LINE WILL FAIL IF IT IS A PART >>>>
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 
Dim initRowIndex As Integer
Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
Dim oPath As String = oFactory.MemberCacheDir

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium

ThisApplication.SilentOperation = True
For Each oRow As iAssemblyTableRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)
	Dim oReferDoc As AssemblyDocument 
    oReferDoc = ThisApplication.Documents.Open(oPath & "\" & oRow.MemberName & ".iam", True)
    Dim oPartNumber As String
    oPartNumber = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		
	If oSTEPTranslator.HasSaveCopyAsOptions(oReferDoc, 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") = ""
	    'Set the target file name
	    oData.FileName = oPath & "\Files\STP\" & oPartNumber & ".stp"
		Try
			oSTEPTranslator.SaveCopyAs(oReferDoc, oContext, oOptions, oData)
		Catch
			MsgBox("Error with SaveCopyAs method.", vbExclamation, "")
		End Try
	End If
    oReferDoc.Close
Next
ThisApplication.SilentOperation = False
0 Likes
Message 11 of 25

WCrihfield
Mentor
Mentor

Hi @rodneyleedav.  I'm on my way out right now, but I'm guessing that the oPath variable, whose value is set by oFactory.MemberCacheDir, may already contain a sub folder with the same name as the assembly.  You can make a MsgBox() or MessageBox.Show() line to show you its contents.  If so, you could just set the value of oPath using something like:

ThisDoc.Path

or

System.IO.Path.GetDirectoryName(oDoc.FullFileName)

...and that may eliminate that sub folder.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 25

rodneyleedav
Participant
Participant

Both methods work for the path of the STP file.  However, neither method works for the ReferDoc row.

 

    oReferDoc = ThisApplication.Documents.Open(oPathASMB & "\" & oRow.MemberName & ".iam", True)

I can make it work with two path variables so I may use that unless you have other suggestions.

 

Dim oPathSTP As String = ThisDoc.Path
Dim oPathASMB As String = oFactory.MemberCacheDir

This brings up another thing that could be improved.  Every factory member that it opens gets saved as a *.iam.  Once the process is complete, I manually go to the sub-folder and delete all of the assemblies.  Is there a way to keep them from being saved or delete them when the process is complete?

0 Likes
Message 13 of 25

WCrihfield
Mentor
Mentor

Hi @rodneyleedav.  Well, we can not prevent it from generating the member model files, because those are what is being exported to STP files, so that model file must exist, and be saved, before exporting them to STP files.  However, we could create something like a List(Of String) type variable before the loop begins, then assemble the member model file's path in a String type variable, before we use it to open that model file.  Then add that member model file's FullFileName (stored in that variable) into the List.  So that later, after the loop, we should be able to loop through the FullFileNames in that list, and delete those files, as long as the export processing is done with them.  Does that sound like something you could do yourself, or would you want help with adding that step into your code?  If you would like me to help add it in there, just re-attach your current 'fixed' code, with the two paths, then I can attempt to make it happen.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 25

rodneyleedav
Participant
Participant

It would be useful to have in case we forget to delete the files manually.  The current project creates 700 MB of unneeded assemblies.

 

I would appreciate your input when you have time.  Here is the current code:

 

' Check if the file type is correct.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
   MsgBox("Error:Document type is not an assembly", vbCritical, "Wrong Document Type")
   Exit Sub
End If
' Set reference to active document.
Dim oDoc As Document = ThisApplication.ActiveDocument
'<<<< THIS NEXT LINE WILL FAIL IF IT IS A PART >>>>
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 
Dim initRowIndex As Integer
Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
'Set separate paths for the assemblies and the STP files
Dim oPathSTP As String = ThisDoc.Path
Dim oPathASMB As String = oFactory.MemberCacheDir
MessageBox.Show(oPathSTP)
MessageBox.Show(oPathASMB)

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium

ThisApplication.SilentOperation = True
For Each oRow As iAssemblyTableRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)
	Dim oReferDoc As AssemblyDocument 
    oReferDoc = ThisApplication.Documents.Open(oPathASMB & "\" & oRow.MemberName & ".iam", True)
    Dim oPartNumber As String
    oPartNumber = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		
	If oSTEPTranslator.HasSaveCopyAsOptions(oReferDoc, 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") = ""
	    'Set the target file name
	    oData.FileName = oPathSTP & "\Files\STP\" & oPartNumber & ".stp"
		Try
			oSTEPTranslator.SaveCopyAs(oReferDoc, oContext, oOptions, oData)
		Catch
			MsgBox("Error with SaveCopyAs method.", vbExclamation, "")
		End Try
	End If
    oReferDoc.Close
Next
ThisApplication.SilentOperation = False

 

0 Likes
Message 15 of 25

WCrihfield
Mentor
Mentor

OK.  Here is the edited code.  I added a List(Of String) type variable in there just before the loop starts.  Then just within the loop a couple lines, I get the member file's full file name to a String type variable.  Then I add that to the list, and also use that variable for opening that member document.  Then after the loop is done, I check to make sure it recorded some file names in the list, loop through them, check if the file exists in the system, and if it does, try to delete it.

' Check if the file type is correct.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
   MsgBox("Error:Document type is not an assembly", vbCritical, "Wrong Document Type")
   Exit Sub
End If
' Set reference to active document.
Dim oDoc As Document = ThisApplication.ActiveDocument
'<<<< THIS NEXT LINE WILL FAIL IF IT IS A PART >>>>
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 
Dim initRowIndex As Integer
Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
'Set separate paths for the assemblies and the STP files
Dim oPathSTP As String = ThisDoc.Path
Dim oPathASMB As String = oFactory.MemberCacheDir
MessageBox.Show(oPathSTP)
MessageBox.Show(oPathASMB)

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
Dim oMemberFFNs As New List(Of String)
ThisApplication.SilentOperation = True
For Each oRow As iAssemblyTableRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)
	Dim sMemberFFN As String = oPathASMB & "\" & oRow.MemberName & ".iam"
	oMemberFFNs.Add(sMemberFFN)
	Dim oReferDoc As AssemblyDocument
    oReferDoc = ThisApplication.Documents.Open(sMemberFFN, True)
    Dim oPartNumber As String
    oPartNumber = oReferDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		
	If oSTEPTranslator.HasSaveCopyAsOptions(oReferDoc, 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") = ""
	    'Set the target file name
	    oData.FileName = oPathSTP & "\Files\STP\" & oPartNumber & ".stp"
		Try
			oSTEPTranslator.SaveCopyAs(oReferDoc, oContext, oOptions, oData)
		Catch
			MsgBox("Error with SaveCopyAs method.", vbExclamation, "")
		End Try
	End If
    oReferDoc.Close
Next
If oMemberFFNs.Count > 0 Then
	For Each sFFN In oMemberFFNs
		If System.IO.File.Exists(sFFN) Then
			Try : System.IO.File.Delete(sFFN) : Catch : End Try
		End If
	Next 'sFFN
End If
ThisApplication.SilentOperation = False

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 16 of 25

KrishR330
Contributor
Contributor

Works Great! I was looking for something like that. Thank you.

0 Likes
Message 17 of 25

KrishR330
Contributor
Contributor

Creating STEP files is great using iLogic. However, Is there a way iAssembly members are converted to simplified parts and STEP files are made of those simplified parts. Is there an iLogic code that I can use? Thank you!

0 Likes
Message 18 of 25

WCrihfield
Mentor
Mentor

Hi @KrishR330.  Yes, I believe that the code could potentially create simplified part files of each iAssemblyMember first, then export that simplified part out as a STEP file.  It would require adding a whole extra complex section of code into the mix though.  Plus, there are a lot of settings / options involved in that process, and I don't know which settings / options you would prefer to use.  When you manually create a simplified part file from an assembly, you will see a dialog with these options in it, see following online help link.

Create a Simplified Part from an Assembly 

  • How you want all of those settings / options set?
    • Try to be as detailed with this answer as possible, because there are a lot, and the code needs to be exact.
  • Where should both types of new files be created?
  • How you want both types of new files to be named?
  • Do you want to keep all the original iAssembly member files after this process is finished, or delete them?
  • Do you want to keep all the new simplified to part files after this process is finished, or delete them?

Also, when we export a model file to a STEP file, there are multiple options available in that export process also.

  • How do you want each of the translation to STEP export options set?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 19 of 25

KrishR330
Contributor
Contributor
  • Settings to create Simplified Part:
    1.  Simplify ........... Simplification Drop Down Menu ........... Create Simplified Part ......... Combine Style as .....Maintain each Solid as a Separate Body
    2. The New Component Name same as the iAssembly Member Name
    3. Template as the Standard.ipt
    4. All the Simplified Parts in a New Folder named as "SIMPLIFIED". The Folder "SIMPLIFIED" need to be located in the same location as all the iAssembly Members
    5. The exported Step Files need to be created based on the Simplified parts. The location of those Step Files need to be saved in a New Folder named as "STEP". The Folder "STEP" need to be located in the same location as all the iAssembly Members.
    6.  The STEP File names, the Simplified Part names and the Assembly member names should all be the same.
    7. I still want to keep all the original iAssembly member files, Simplified Parts and the STP files.
    8. ' Set application protocol.
      	    ' 2 = AP 203 - Configuration Controlled Design
      	    ' 3 = AP 214 - Automotive Design
      	    oOptions.Value("ApplicationProtocolType") = 3

I hope I covered everything. If I miss something, please let me know.

 

Thanks,

Krish.

0 Likes
Message 20 of 25

WCrihfield
Mentor
Mentor

Hi @KrishR330.  I created an updated code example for you, which includes a whole new code routine for handling the simplification process.  However, within that code process are several other settings / options than just the one you mentioned.  So, I recommend that you look closely at those lines of code, and try to interpret what they mean.  They mostly control what all types of data will get included or excluded from the source document to the new, simplified document.  Right now, it should exclude all iMateDefinitions and Parameters, but include all sketches, work features, and component occurrences.  I also set it to not remove internal voids.  There was also a line of code in there for removing internal parts and faces which can not be seen from any external view of the final part, but I left that line of code commented out for now.  I also set it to 'suppress' (not break) the link between the source iAssembly member model file and the new simplified part.  This is often recommended for better performance, but may not always be wanted, depending on your needs.  There are 4 additional options/settings when exporting a STEP file, than the one you mentioned, so I left those commended out for now.

 

I attached the new code example as a text file.  I have not tested this locally yet, partly because I generally do not use the iAssembly system, so I recommend trying it out on files that are less important first, to be safe.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes