parsing DateTime to user data property value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I had some issues yesterday where I could not understand why one of my plugins failed. I found out that parsing a DateTime with year 1899 causes a exception.
My question is : Is there is a lower limits at year 1900? If there is I recommend that you add this limitation to the documentation for the API.
ComApi.InwOpState10 state;
state = ComApiBridge.ComApiBridge.State;
//InwOaPath ToInwOaPath(ModelItem modelItem);
ComApi.InwOaPath3 oPath = (ComApi.InwOaPath3)ComApiBridge.ComApiBridge.ToInwOaPath(MI);
// get properties collection of the path
ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true);
// create new property category (new tab in the properties dialog)
ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null);
//CurrentValue is a DateTime with year 1899 - DateTime.TryParse handles this fine but the code crashses when the DateTime is handled over to Navisworks - this code works for all dates >1899
if (CurrentValue.GetType() == typeof(DateTime))
{
DateTime MyDate;
if (DateTime.TryParse(CurrentValue.ToString(), out MyDate))
{
MyProp.value = MyDate;
}
newPvec.Properties().Add(MyProp);
// add the new property category to the path
propn.SetUserDefined(ndx, MyPropertyTabName, MyPropertyTab_InteralName, newPvec);
Ulrik
