iPart or iAssembly member save as other automation

iPart or iAssembly member save as other automation

j.peterszetapdm
Contributor Contributor
1,477 Views
7 Replies
Message 1 of 8

iPart or iAssembly member save as other automation

j.peterszetapdm
Contributor
Contributor

Hi all, 

I'm not all that up to speed with iLogic but I've cobbled together a rule to generate all members of an iPart/iAssembly factory. This is good but I really want it to also save as another format too like a .sat file or .step and I cant seem to get it to, it will only save the current member.

 

 

' 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
For Each oRow In oFactory.TableRows
	' Generate the member and file, (overwrites member file or creates new file)
	oFactory.CreateMember(oRow)
	' Get document's full file name
    sFname = iProperties.Value("Project", "Part Number") & ".sat"

    ' Do a 'Save Copy As' to SAT format
    oDoc.SaveAs(sFname, True)
Next

 

 

 

 

Anyone able to help get the save as for each member working?

0 Likes
Accepted solutions (1)
1,478 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@j.peterszetapdm ,

 

Hoping that below iLogic code may be helpful to save iAssemblymembers. Similarly, code can be modified for iPart.

 

' 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)
	oMember = oFactory.CreateMember(oRow)
Dim oPath As String
oPath = oMember.ParentFactory.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 Call oReferDoc.SaveAs(oPath & "\" & oName & ".iam", True)

Call oReferDoc.Close Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

j.peterszetapdm
Contributor
Contributor

Hi there, thank you for your help. I've had a go with the code but I am getting an error with line 20

"Error on Line 20 : Expression does not produce a value."

Is there something i could be missing?

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@j.peterszetapdm ,

 

Actually, previous code is for iAssmeblyFactory. Is code is used for iAssembly or iPart?

 

If you provide non confidential iAssmebly file, I can simulate error and correct the same.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 8

j.peterszetapdm
Contributor
Contributor

Thank you, attached is the assembly i am trying to export each memeber out as an obj in this case. I could generate all the members with my code but I couldnt figure out how to export each one as well, it just exported the current member.

0 Likes
Message 6 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@j.peterszetapdm,

 

Try this iLogic code for iAssembly.

 

' 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)
	Call 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 
	
    Call oReferDoc.SaveAs(oPath & "\" & oName & ".iam", True) 
    
    Call oReferDoc.Close
	
	ThisApplication.SilentOperation = False 
	  
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 8

j.peterszetapdm
Contributor
Contributor

Thats got it thank you.

0 Likes
Message 8 of 8

Andrey.Subbotin
Explorer
Explorer

Dear colleagues,

 

Could you please help us with such question: we are using oFactory.CreateMember method 

oMember = oFactory.CreateMember

for processing and saving Assemblymembers (we are using Inventor API to create our own add-in for Inventor), but we use C#. And we get an error, cause it doesn't work. Could you please tell us if this method (oFactory.CreateMember) also could be used for C# or maybe there are some other methods for C#?

0 Likes