Hi,
I used the VBA watch window and I see that when the "Checked Date" is not checked the Expression property of the iProperty is an empty string and when it is checked it has a value. Here is the VBA code that makes the expression a date and after running the code I see the property is then checked.
Public Sub iProperties_Test() ' Get the active document. Dim invDoc As Document Set invDoc = ThisApplication.ActiveDocument ' Get the design tracking property set. Dim invDesignInfo As PropertySet Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties") Dim iProp As Property For Each iProp In invDesignInfo Debug.Print iProp.Value If iProp.Name = "Date Checked" Then Debug.Print iProp.Value iProp.Expression = "6/23/2016" Exit For End If Next iProp End Sub
Thanks,
Wayne
Date properties in Inventor are a bit weird. As Wayne showed you can set the expression to a blank string, but you can also accomplish the same thing by setting the date to a default value; January 1st, 1601.
Thanks Wayne for the reply
when I try to set the expression in a empty string or uncheck the checkbox get a error
You are correct, setting the expression to a blank string does cause an issue. You can try following in VB.NET (I assume that is what you are using). This assumes you have the appropriate Inventor property assigned to the variable prop.
' create a date variable and set it to the default date of Jan 01, 1601 Dim newDate As Date = New Date(1601, 1, 1) ' assign the date the property value prop.Value = newDate 'or set the expression prop.Expression = newDate.ToShortDateString()
If you examine the property after doing this you will see the value set to the default date but the expression will be a blank string.
If you are assigning a specific date to the property it is better to create the date and assign that to the property value, as trying to work with date strings can be problematic since the date format can change from computer to computer.
Thanks
PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(PropertiesForDesignTrackingPropertiesEnum.kDateCheckedDesignTrackingProperties).Expression = newDate.ToShortDateString
For some reason this didn't work for me, but this code works for my needs. If the check box is not checked then the current date is used as the value.
ReadOnly _PropSets As PropertySets
' Checked Date checkbox
If _PropSets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(PropertiesForDesignTrackingPropertiesEnum.kDateCheckedDesignTrackingProperties).Value = #1/1/1601# Then
_PropSets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(PropertiesForDesignTrackingPropertiesEnum.kDateCheckedDesignTrackingProperties).Value = Date.Now()
End If