Copying IProperties from one part to another based on file name using ILogic

Copying IProperties from one part to another based on file name using ILogic

jordan.bicknellXG55R
Participant Participant
383 Views
3 Replies
Message 1 of 4

Copying IProperties from one part to another based on file name using ILogic

jordan.bicknellXG55R
Participant
Participant

Hi,

 

I am wondering if it is possible to copy IProperties from one part file to another by it's filename using Ilogic.

 

For example, if I have a part named 9501-01-0001 and then a second part which is named 9501-01-0001_Copy.

I'd like to use the first 12 characters of the copied parts file name, (9501-01-0001) to search for the file in the same Project directory then copy its description and set it for the new part. 

 

Is this possible using ILogic?

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

A.Acheson
Mentor
Mentor

Hi @jordan.bicknellXG55R 

 

The following will find a similar file name in the directory, open the file, copy the description to the partfile the rule is launched from. Hopefully that is what you had in mind. Here is the Microsoft help page for Getfiles Function.

Dim partDoc As PartDocument = ThisDoc.Document
Dim projDir as String  = ThisDoc.Path
Dim partFileName As String = ThisDoc.FileName(False)

Dim fileEntries As String() = IO.Directory.GetFiles(projDir, "*.ipt")
Dim foundDoc as PartDocument
For Each fileName As String In fileEntries
    'Check the fullfilename found is not the same as the document your in and that it has the same partial filename 
    If Not fileName = partDoc.FullFileName andAlso fileName.Contains(partFileName) Then
		foundDoc = ThisApplication.Documents.Open(fileName,False)
		Try
			Dim origDescProp as Inventor.Property = partDoc.PropertySets.Item("Design Tracking Properties").Item("Description")		
			Dim foundDescProp as Inventor.Property = foundDoc.PropertySets.Item("Design Tracking Properties").Item("Description")	
			origDescProp.Value = foundDescProp.Value
		Catch ex as Exception
		End Try
    End If
Next

 

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

jordan.bicknellXG55R
Participant
Participant

Hi @A.Acheson,

 

Thank you for your reply. Unfortunately I can't get it to work correctly. When I run the rule nothing is appearing in the parts description.

Also it isn't quiet the method I was after. 

I'd prefer to either use the first 12 characters of the copied parts file name using a "Left" command or an alternative is that the copied part's part number is always the same as the original's file name, (Without the .ipt), Can this be used rather than looking for a similar file name?

 

Kind regards,

 

Jordan

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Hi @jordan.bicknellXG55R 

If possible I would suggest you to try and put together a pseudo code showing an attempt to implement what your requesting. This will help yourself testing with your own data set and to work out a workflow that works in your situation. 

 

I have put together a brief sample to work with the left 12 characters of the filename without extension. There should be enough information here to try either of your suggested filtering methods. If you need help trouble shooting then attach the code your using and a description of what is and isn't working. 

Dim partDoc As PartDocument = ThisDoc.Document
Dim projDir As String  = ThisDoc.Path
Dim fileNameWoExt1 As String = ThisDoc.FileName(False)
Dim shortName1 As String = Left(fileNameWoExt1,12)

Dim fileEntries As String() = IO.Directory.GetFiles(projDir, "*.ipt")
Dim foundDoc As PartDocument
For Each fullFileName As String In fileEntries
	Dim fileNameWoExt2 As String = IO.Path.GetFileNameWithoutExtension(fullFileName)
	Dim shortName2 As String = Left(fileNameWoExt2, 12)

 	'Check the fullfilename found is not the same as the document your in and that it has the same partial filename 
   If Not fullFileName = partDoc.FullFileName AndAlso shortName1 = shortName2 Then
		Logger.Info(fullFileName)

		foundDoc = ThisApplication.Documents.Open(fullFileName,False)
		Try
			Dim origDescProp As Inventor.Property = partDoc.PropertySets.Item("Design Tracking Properties").Item("Description")	
			MessageBox.Show(origDescProp.Value, "Title")

			Dim foundDescProp As Inventor.Property = foundDoc.PropertySets.Item("Design Tracking Properties").Item("Description")	
			MessageBox.Show(foundDescProp.Value, "Title")
			origDescProp.Value = foundDescProp.Value
		Catch ex As Exception
		End Try
    End If
Next

 

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