Copy select iProperties from file to file

Copy select iProperties from file to file

kfc10
Participant Participant
410 Views
2 Replies
Message 1 of 3

Copy select iProperties from file to file

kfc10
Participant
Participant

Hello, can anyone help?

 

This code copies all iProperties. I only need to copy some iProperties, not all iProperties.

I only need to copy iProperties named and Value. "test1" and "test2"

 

Sub Main()
Dim oFileName As String = "C:\iLogic_Main\a.ipt"
Dim mojecesta As String = "C:\iLogic_Main\b.iam"
'			mojecesta = ThisDoc.PathAndFileName(True)
Dim copyFrom As Document = ThisApplication.Documents.Open(oFileName, False) 'Document to copy from
Dim copyTo As Document = ThisApplication.Documents.Open(mojecesta, False) 'Document to copy to
CopyEventsPropSet(copyFrom, copyTo)
End Sub

Sub CopyEventsPropSet(CopyFrom As Document, CopyTo As Document)
	Dim refiProps As PropertySet = CopyFrom.PropertySets.Item("Inventor User Defined Properties")
	Dim deriPorps As PropertySet = CopyTo.PropertySets.Item("Inventor User Defined Properties")

		Dim oProp As Inventor.Property
		For Each oProp In refiProps
	
	Dim oProp1 As Inventor.Property
	Dim oProp2 As Inventor.Property
	Try
				deriPorps.Add(oProp.Value, oProp.Name)
	Catch ex As Exception
	End Try
		Next
	CopyFrom.Close(True)
End Sub

kfc10_0-1642277336527.png

I tried it and I don't get it at all.

The attachment is in version 2022

 

0 Likes
Accepted solutions (1)
411 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

this is untested code but I think it will do what you want.

Public Sub Main()

    Dim oFileName As String = "C:\iLogic_Main\a.ipt"
    Dim mojecesta As String = "C:\iLogic_Main\b.iam"

    Dim copyFrom As Document = ThisApplication.Documents.Open(oFileName, False) 'Document to copy from
    Dim copyTo As Document = ThisApplication.Documents.Open(mojecesta, False) 'Document to copy to

    CopyProperty(copyFrom, copyTo, "test1")
    CopyProperty(copyFrom, copyTo, "test2")

    copyFrom.Close(True)

End Sub

Sub CopyProperty(CopyFrom As Document, CopyTo As Document, propertyName As String)
    Dim fromProps As PropertySet = CopyFrom.PropertySets.Item("Inventor User Defined Properties")
    Dim toPorps As PropertySet = CopyTo.PropertySets.Item("Inventor User Defined Properties")

    Dim fromProp As [Property] = fromProps.Item(propertyName)

    Try
        Dim toProp As [Property] = toPorps.Item(propertyName)
        toProp.Value = fromProp.Value
    Catch ex As Exception
        toPorps.Add(fromProp.Value, fromProp.Name)
    End Try

End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

kfc10
Participant
Participant

Yes, everything works. That's great. Thank you very much for your help.

 

0 Likes