Convert all Members of an iAssembly Factory to STP files

Convert all Members of an iAssembly Factory to STP files

rodneyleedav
Participant Participant
2,364 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)
2,365 Views
24 Replies
Replies (24)
Message 21 of 25

KrishR330
Contributor
Contributor

If I run the code, the Step Files are created with File Extension .iam and not with .stp.

Also the Folder "SIMPLIED" is not there and so there no .ipt files as well.

0 Likes
Message 22 of 25

WCrihfield
Mentor
Mentor

Hi @KrishR330.  I'm sorry to hear that.  Did you see any messages or error messages from the code while it was running?  If so, what did they say, in detail.  If no errors showed, then you may need to remove the lines of code with 'SilentOperation' in them.  When that setting is turned on, that forces all messages and dialogs to be ignored, and not show.  While testing new code, trying to get it to work properly, we need to see all those messages and errors, so that there is some feedback, telling us what is going on, or what has happened.  Even error messages can provide some insight about what went wrong, and where in the code it went wrong, usually on the 'More Info' tab.  So, go through that code, and either delete those lines completely, or add an apostrophe at the start of those lines, to turn them into comments that the rule will ignore.  I think those lines we around Line 24 & 25, then again around Lines 43 & 44, if you have not modified the code in any way from my previously attached text file.

 

Also, one other thing you can try is a change in this following line of code (around Line 30):

Dim sMemberFFN As String = sMmbrCacheDir & cDirChar & oRow.DocumentName

...You may need to change that to the following:

Dim sMemberFFN As String = sMmbrCacheDir & cDirChar & oRow.MemberName & ".iam"

The difference is using the DocumentName vs MemberName property of the iAssemblyTableRow object.  The online help for those two properties is not very clear about what they can and will contain.  Since it is possible for the actual member model file on disk to be named differently than the 'Member Name', I was trying to use the DocumentName property's value instead of the MemberName property value, to form the full file name of the 'member' file on disk.  I thought that the DocumentName property would be the more accurate one to use, and assumed that it already includes the file extension, which is why I did not add the file extension after the document name in that file path.  However, it is not clear if the 'DocumentName' property value will always contain the file extension portion or not.  I would need to know for sure to make it work reliably, and the documentation is simply very vague.  If your actual member files (within that cache folder) are always named exactly the same as the member name, then using the second line I suggested above should work OK.

I'm not even sure if this is where the problem is originating from or not, without any other sort of more informational feedback.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 23 of 25

KrishR330
Contributor
Contributor

Hi Wesley,

 

I attached a sample Dummy iAssembly file for you to test run the code. I thought it will be more effective than me messaging you back and forth the errors. Thank you for your time. I am trying to debug the code as well.  Open the file, "Sample Assembly (iAssembly).iam" and run the code.

 

Thank you!

0 Likes
Message 24 of 25

KrishR330
Contributor
Contributor

I want to add additional comments. After you run the code, you will see there will be a folder called, "STEP" created in the "...\Sample iAssembly\Sample Assembly (iAssembly)" folder. All the files are created with wrong file extension (.iam instead of .stp).  If you change the file extension manually back to .stp, the file opens fine and you can manually save it as a simplified .ipt file as well. 

 

Thanks!

0 Likes
Message 25 of 25

KrishR330
Contributor
Contributor

Hi Wesley,

 

I got it now! After debugging your initial code, I am able to fix the issues now. It now creates the Simplified Parts and also STEP Files as desired. Thank you for your help and your time.

 

Krish R

 

 

 

0 Likes