<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: parsing DateTime to user data property value in Navisworks API Forum</title>
    <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671192#M6079</link>
    <description>" as ComApi.InwOaProperty" will report compile error.&lt;BR /&gt;&lt;BR /&gt;My test result is: when the date is after "1980/1/1 0:00:00", it is ok.&lt;BR /&gt;</description>
    <pubDate>Wed, 10 Jun 2015 08:02:22 GMT</pubDate>
    <dc:creator>Aaron.Lu</dc:creator>
    <dc:date>2015-06-10T08:02:22Z</dc:date>
    <item>
      <title>parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5642914#M6075</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;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&amp;nbsp;1899 causes a exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is : &amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ComApi.InwOpState10 state;&lt;BR /&gt;state = ComApiBridge.ComApiBridge.State;&lt;BR /&gt;//InwOaPath ToInwOaPath(ModelItem modelItem);&lt;BR /&gt;ComApi.InwOaPath3 oPath = (ComApi.InwOaPath3)ComApiBridge.ComApiBridge.ToInwOaPath(MI);&lt;BR /&gt;// get properties collection of the path&lt;BR /&gt;ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true);&lt;BR /&gt;// create new property category (new tab in the properties dialog)&lt;BR /&gt;ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null);&lt;/P&gt;&lt;P&gt;//CurrentValue is a DateTime with year 1899 -&amp;nbsp;&lt;SPAN&gt;DateTime.TryParse handles this fine but the code crashses when the DateTime is handled over to Navisworks - this code works for all dates &amp;gt;1899&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if (CurrentValue.GetType() == typeof(DateTime))&lt;BR /&gt;{&lt;BR /&gt;DateTime MyDate;&lt;BR /&gt;if (DateTime.TryParse(CurrentValue.ToString(), out MyDate))&lt;BR /&gt;{&lt;BR /&gt;MyProp.value = MyDate;&lt;BR /&gt;}&lt;BR /&gt;newPvec.Properties().Add(MyProp);&lt;/P&gt;&lt;P&gt;// add the new property category to the path&lt;BR /&gt;propn.SetUserDefined(ndx, MyPropertyTabName, MyPropertyTab_InteralName, newPvec);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ulrik&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2015 07:46:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5642914#M6075</guid>
      <dc:creator>ulski1</dc:creator>
      <dc:date>2015-05-20T07:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5650496#M6076</link>
      <description>&lt;P&gt;Dear,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I know which line of code throws which kind of exception?&lt;/P&gt;
&lt;P&gt;or did you try the raw code regardless of Navisworks?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried, seems it works. see below;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; &amp;gt; DateTime.Parse("1900-01-01")
1900/1/1 0:00:00
 &amp;gt; DateTime.Parse("1800-01-01")
1800/1/1 0:00:00
 &amp;gt; DateTime dd;
 &amp;gt; DateTime.TryParse("1800-01-01", out dd)
True
 &amp;gt; dd
1800/1/1 0:00:00
 &amp;gt; DateTime.TryParse("1899-01-01", out dd)
True
 &amp;gt; &lt;/PRE&gt;</description>
      <pubDate>Mon, 25 May 2015 02:28:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5650496#M6076</guid>
      <dc:creator>Aaron.Lu</dc:creator>
      <dc:date>2015-05-25T02:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5654723#M6077</link>
      <description>&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;hi,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Sorry, I think you perhaps did not quite understand what I'm trying to do here.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;The Microsoft DateTime Try parser works fine - and why would I complain to a Navisworks api forum about a bug in a Microsoft method anyway?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;My problem can be reproduced this way:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Create a Navisworks User data object&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Set the Navisworks user data value to a Microsoft DateTime object with year 1899.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this(might not compile):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;using ComApiBridge = Autodesk.Navisworks.Api.ComApi;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;ComApi.InwOpState10 state;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;state = ComApiBridge.ComApiBridge.State;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null);//perhaps I should have used "as operator" here?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;ComApi.InwOaProperty MyProp = (ComApi.InwOaProperty)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaProperty, null, null); //perhaps I should have used "as operator" here too?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;MyProp.name = "Test";&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;MyProp.UserName = "Test";&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;MyProp.value = new DateTime(1899, 12, 30, 00, 00, 00);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;newPvec.Properties().Add(MyProp);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;propn.SetUserDefined(ndx, "Testtab", "Testtab", newPvec);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Also maybe I need to use the "as operator" instead of direct casting of a DateTime to a user data value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;something like this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;MyProp.value = new DateTime(1899, 12, 30, 00, 00, 00) as ComApi.InwOaProperty;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;The odd thing is that I do not get an error when setting the value to a DateTime object with year newer than 1899&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;This will work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;MyProp.value = new DateTime(1900, 12, 30, 00, 00, 00);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Ulrik&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 09:19:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5654723#M6077</guid>
      <dc:creator>ulski1</dc:creator>
      <dc:date>2015-05-28T09:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5666265#M6078</link>
      <description>&lt;P&gt;a small update:&lt;/P&gt;
&lt;P&gt;I found that for some reason the parse to a userdata value also fail if parsing a DateTime object with year 1970 month 1 day 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2015 13:52:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5666265#M6078</guid>
      <dc:creator>ulski1</dc:creator>
      <dc:date>2015-06-05T13:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671192#M6079</link>
      <description>" as ComApi.InwOaProperty" will report compile error.&lt;BR /&gt;&lt;BR /&gt;My test result is: when the date is after "1980/1/1 0:00:00", it is ok.&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jun 2015 08:02:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671192#M6079</guid>
      <dc:creator>Aaron.Lu</dc:creator>
      <dc:date>2015-06-10T08:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671208#M6080</link>
      <description>May I suggest another workaround: store the time with int, like this:&lt;BR /&gt;&lt;BR /&gt;(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds&lt;BR /&gt;&lt;BR /&gt;it will calculate an integer,  after setting property value, in the future, you can get the int value and create a new DateTime from it.</description>
      <pubDate>Wed, 10 Jun 2015 08:27:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671208#M6080</guid>
      <dc:creator>Aaron.Lu</dc:creator>
      <dc:date>2015-06-10T08:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671220#M6081</link>
      <description>&lt;P&gt;the hole point of parsing the date as proper date is to allow the end user to use the find items search feature in Navisworks (search for dates older than etc.). Presenting the end user with an integer is not useful - then I could just a well have cast it as sting and presented that to the user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My guess is that the comapi internally try to create the older Date object instead of a DateTime.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On MSDN there is an advise from Microsoft that states: (see&amp;nbsp;&lt;A href="https://msdn.microsoft.com/en-us/library/3eaydw6e.aspx)" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/3eaydw6e.aspx)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333399"&gt;&lt;EM&gt;&lt;SPAN class="label"&gt;Interop Considerations.&lt;/SPAN&gt;&lt;SPAN style="line-height: 15px;"&gt; If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, keep in mind that date/time types in other environments are not compatible with the Visual Basic &lt;/SPAN&gt;&lt;SPAN class="input"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="line-height: 15px;"&gt; type. If you are passing a date/time argument to such a component, declare it as &lt;/SPAN&gt;&lt;SPAN class="input"&gt;Double&lt;/SPAN&gt;&lt;SPAN style="line-height: 15px;"&gt; instead of &lt;/SPAN&gt;&lt;SPAN class="input"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="line-height: 15px;"&gt; in your new Visual Basic code, and use the conversion methods &lt;/SPAN&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/system.datetime.fromoadate.aspx" target="_blank"&gt;DateTime.FromOADate&lt;/A&gt;&lt;SPAN style="line-height: 15px;"&gt; and &lt;/SPAN&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx" target="_blank"&gt;DateTime.ToOADate&lt;/A&gt;&lt;SPAN style="line-height: 15px;"&gt;.&lt;/SPAN&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so perhaps using form to OADate would allow us to parse a DateTime to the comapi user data value?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 08:37:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671220#M6081</guid>
      <dc:creator>ulski1</dc:creator>
      <dc:date>2015-06-10T08:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671232#M6082</link>
      <description>do you mean changing Navisworks to use OADate or in the plugin?&lt;BR /&gt;if in the plugin, the "search" feature is impossible either?&lt;BR /&gt;&lt;BR /&gt;what about storing strings to properties? I think you must considered it before. but not sure why you did not use it.</description>
      <pubDate>Wed, 10 Jun 2015 08:53:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671232#M6082</guid>
      <dc:creator>Aaron.Lu</dc:creator>
      <dc:date>2015-06-10T08:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: parsing DateTime to user data property value</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671322#M6083</link>
      <description>&lt;P&gt;if I cast a DateTime to string the end user will not be able to do searches using "find items" where he specifies "MyDate"&amp;gt;date &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 10:29:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/parsing-datetime-to-user-data-property-value/m-p/5671322#M6083</guid>
      <dc:creator>ulski1</dc:creator>
      <dc:date>2015-06-10T10:29:11Z</dc:date>
    </item>
  </channel>
</rss>

