Copy custom iproperties from Assembly- Assembly. Part - Assembly, Part-part

karram
Advocate
Advocate

Copy custom iproperties from Assembly- Assembly. Part - Assembly, Part-part

karram
Advocate
Advocate

Using ilogic how to copy Custom iproperties from one assembly file to another assembly files, One part to another part file and one Assembly to another part file.

 

karram_1-1684732718602.png

 

0 Likes
Reply
Accepted solutions (1)
254 Views
2 Replies
Replies (2)

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @karram . Please try this code:

Sub main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oCM As CommandManager = ThisApplication.CommandManager
		Dim oTm As TransactionManager = ThisApplication.TransactionManager
		Dim oADoc As AssemblyDocument = oDoc
		Dim oCompCopy, oCompPaste As ComponentOccurrence
		Do
			oCompCopy = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component copy params...")
			If oCompCopy Is Nothing Then Exit Sub
			If oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then GoTo Step1Rule
		Loop
		Step1Rule :
		Do
			oCompPaste = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component paste params...")
			If oCompPaste Is Nothing Then Exit Sub
			If oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then GoTo Step2Rule
		Loop
		Step2Rule :
		Dim oCopyDoc As Document = oCompCopy.Definition.Document
		Dim oCopyProperty As PropertySet = oCopyDoc.PropertySets.Item("Inventor User Defined Properties")
		Dim oPasteDoc As Document = oCompPaste.Definition.Document
		Dim oPasteProperty As PropertySet = oPasteDoc.PropertySets.Item("Inventor User Defined Properties")
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "CopingUserProperty")
		Call CreateParamsInAssembly(oPasteProperty, oCopyProperty)
		newTM.End()
		oADoc.Update()
	Else
		MessageBox.Show("Active document is not AssemblyDocument.", "Error!",MessageBoxButtons.OK,MessageBoxIcon.Error)
	End If
End Sub

Private Function CreateParamsInAssembly(oPasteProperty As PropertySet, ByVal oCopyProperty As PropertySet)
	Dim bCreatProp As Boolean
	For Each copyProp As Inventor.Property In oCopyProperty
		bCreatProp = True
		For Each oProp As Inventor.Property In oPasteProperty
			If oProp.Name = copyProp.Name Then
				bCreatProp = False
				oProp.Value = copyProp.Value
			End If
		Next
		If bCreatProp Then
			oPasteProperty.Add(copyProp.Value, copyProp.Name, copyProp.PropId)
		End If
	Next
End Function

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes

karram
Advocate
Advocate

Works perfectly. Thanks

0 Likes