Add reuse component from main assembly to new

Add reuse component from main assembly to new

1830108CDDDF
Contributor Contributor
259 Views
1 Reply
Message 1 of 2

Add reuse component from main assembly to new

1830108CDDDF
Contributor
Contributor

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.

1830108CDDDF_1-1687217399980.png

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.

 

0 Likes
260 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @1830108CDDDF 

In the adding occurrences I see two mistakes, one is trying to add a componentdefinition with the wrong add method and the other uses the occurrence only. You should either use ".add" for fullfilename or ".AddByComponentDefinition" for componentdefinition

Error lines

Dim oRComponent As ComponentOccurrence = odef.Occurrences.Add(odef, oCC.Transformation)
oNewCC = oNewdef.Occurrences.Add(oCC, oCC.Transformation)

 

I would suggest to change around those lines and report back what further issues your facing. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes