Date notation from Excel to Revit parameter

Tried to find some similar topics, but couldn’t find a proper solution.

I’m trying to import data from a Excel-file that has been partially exported from Revit before. That part I understand, got a simple script for that.

The last columns (J to O) are filled with information from consultants. All seems to work fine, except for the fact that same cells can contain a date. Excel then automatically changes the cell notation from standard to date. When this value is imported in the parameter, it looks like the values from the watch node on the right: MM/DD/YYYY hh:mm:ss. What I’m trying to achieve is the following notation: DD-MM-YYYY. So: 31-12-2016 or 01-01-2017 in this instance.

Is there some workaround available, or is this the best solution I can get? I’m not that much into Python to make my own script, so a little advice would be appreciated.

Excel to NCD.dyn (18.7 KB)

Hi @Arjan

You could use String.Replace node to replace “/” with “-”. For your hours and seconds you can use “String.Remove” and startindex and count. Good Luck!

Hi @Arjan

Two choices based on first look:

  1. Change the system settings (assuming Excel formatting is controlled by the system formatting) to have the date with “-” instead of “/”
  2. Use “True” for the “Read as Strings” (That way, you can use the String based nodes of Dynamo to further refine or replace the data within Dynamo)

Hope that helps!

Oops! @Chandrasekar_Rajaman and i replied same time. Now you got many choices :slight_smile:

1 Like

It took some time for me to respond, but thanks for sharing your opinions!

@Kulkul I’ll give it a go, but I’ll need some additional filtering: not all cells contain a date, it might also be a text (string). Also, I’ll have to flip the day and month from MM/DD to DD/MM. Most simple hack for the time being: Use an apostrophe before the date in the cell. Using this still gives a clean notation in Excel, but prevents it to read that cell as a date.

@Chandrasekar_Rajaman

  1. I checked the system setting, and it’s set the way how I want it to appear: dd-MM-yy.
  2. Also set read as strings to true, the only difference I notice is in the first watch-node (see my first post), the result is the same as when the output flows through the “string from object” node. If I try to import the value as a date, the Element.SetParameterByName node turns yellow:

Warning: Element.SetParameterByName operation failed.
The best overloaded method match for ‘Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(Autodesk.Revit.DB.Parameter, double)’ has some invalid arguments

My best guess: Dynamo doesn’t use (or can’t use) the system setting for date and time.

@Arjan One of the possible way is to split the strings using “String.Split” node and then join them using “string.join”.

@Arjan See if this helps…

dt=DateTime.Components(dt1);
dt2=dt["day"]+"/"+dt["month"]+"/"+dt["year"];

2 Likes

@Vikram_Subbaiah When I copy the code I get the following warning:

Warning: No function called Components on a System.DateTime that takes DateTime could be found

or

Warning: Multiple definitions for ‘DateTime’ are found as DSCore.DateTime, Analyze.Render.DateTime, System.DateTime
Multiple definitions for ‘DateTime’ are found as DSCore.DateTime, Analyze.Render.DateTime, System.DateTime
Multiple definitions for ‘DateTime’ are found as DSCore.DateTime, Analyze.Render.DateTime, System.DateTime

I’m using the most recent version of Dynamo (1.2.1.3083) and Revit (2017.1)

@Arjan Not sure if this is the issue, but I’m using the latest available daily build (1.2.2)

See if you can find the node corresponding to the script …

Hi Arjan,

try this - (if you’re still stuck there :stuck_out_tongue: )

Regards,
ap