Add reuse component from main assembly to new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, reading some threads I found this one: Using iLogic to Save As Components in an assembly
And the code in the thread It's what I need, but there's a little problem, I need to "save as" some specific components with a column named "EXPORTAR" (Export) and the cell value is a Yes or No.
Private Function oAsmSaveAs(oDoc As AssemblyDocument,oPath As String)
Dim oFileName As String = oGetFileName(oDoc,oPath)
Dim oNewAsmDoc As AssemblyDocument
If Not System.IO.File.Exists(oFileName) Then
oNewAsmDoc=ThisApplication.Documents.Add(Inventor.DocumentTypeEnum.kAssemblyDocumentObject,,True)
oNewAsmDoc.SaveAs(oFileName, False)
Else
Exit Function
End If
Dim oNewdef As AssemblyComponentDefinition
oNewdef = oNewAsmDoc.ComponentDefinition
Dim oNewCC As ComponentOccurrence
Dim odef As AssemblyComponentDefinition
odef=oDoc.ComponentDefinition
Dim oCC As ComponentOccurrence
Dim oNewPartName As String
For Each oCC In odef.Occurrences
If oCC.Suppressed Then
Else
If oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Dim oPrt As PartDocument
oPrt = oCC.Definition.Document
Dim oProp As String
oProp = oPrt.PropertySets.Item(4).Item("EXPORTAR").Value
' MessageBox.Show(oProp,"Title")
If oProp = True Then
oNewPartName=oGetFileName(oPrt,oPath)
Call oDocSaveAs(oPrt,oNewPartName)
oNewCC = oNewdef.Occurrences.Add(oNewPartName, oCC.Transformation)
oNewCC.Grounded=True
Else
Dim oRComponent As ComponentOccurrence = odef.Occurrences.Add(odef, oCC.Transformation)
End If
ElseIf oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oSubAsm As AssemblyDocument
oSubAsm = oCC.Definition.Document
Call oAsmSaveAs(oSubAsm, oPath)
oNewPartName=oGetFileName(oSubAsm,oPath)
oNewCC = oNewdef.Occurrences.Add(oCC, oCC.Transformation)
oNewCC.Grounded=True
End If
End If
Next
oNewAsmDoc.Close
End Function
In the function above through an If is chosen the component wether or not the component is saved
When executing the rule, exports correctly the components with the "EXPORTAR" cell marked as Yes, but the components with the "No" value aren't wich is I expected. What I'd like to do is to reuse the source component in the new assembly, I try with de Add method
Dim oRComponent As ComponentOccurrence = odef.Occurrences.Add(odef, oCC.Transformation)
But it gives me an error, in my understanding I need to add the oCC but is not working.
Wich would be the correct method to achieve this?
Thanks in advance, regards.