Change iproperties of ipt and iam

Change iproperties of ipt and iam

jcorrero87
Enthusiast Enthusiast
249 Views
1 Reply
Message 1 of 2

Change iproperties of ipt and iam

jcorrero87
Enthusiast
Enthusiast
  • Hello everyone. I have a question, I don't know if anyone knows of a way to use iLogic to change the value of the iproperties (it is always the same iproperty with the same value) of the ipt and iam of a route and those that are in subfolders that are also on that route. Thank you so much.
0 Likes
250 Views
1 Reply
Reply (1)
Message 2 of 2

piotrekdoro94
Advocate
Advocate

Hi, below there is a code snippet that sets a custom property named todayDate to current date in all the file parts in all the subfolders under specified root path. I use a version of this (without iterating through files) in an add-in to set date in a drawing title block with one click on a custom ribbon button.

 

I haven't tested it excessively but it should work, you might be able to create something slicker with apprentice but I've never done that.

 

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim InventorApp As Inventor.Application
        Dim oPartDoc As PartDocument
        InventorApp = Marshal.GetActiveObject("Inventor.Application")

        Dim txtbx As String = "D:\test"
        Dim invCustomPropertySet As PropertySet
        Dim todayDate As Date

        todayDate = Now

        For Each FileInfo As FileInfo In New DirectoryInfo(txtbx).GetFiles("*", SearchOption.AllDirectories)
            'MsgBox(FileInfo.FullName)
            'MsgBox(FileInfo.Extension)
            If FileInfo.Extension = ".ipt" Then
                InventorApp.Documents.Open(FileInfo.FullName) 'You can use "InventorApp.Documents.Open(FileInfo.FullName, flase) to hide opened documents"
                oPartDoc = InventorApp.ActiveDocument
                invCustomPropertySet = oPartDoc.PropertySets.Item("Inventor User Defined Properties") 'Access custom property set
                'invCustomPropertySet.Add(todayDate, "todayDate") 'Uncomment if you want to create a property instead of updating one
                invCustomPropertySet.Item("todayDate").Value = todayDate 'Set date to now
                oPartDoc.Update()
                oPartDoc.Close()
            End If
        Next

    End Sub
End Class

 

0 Likes