Community
InfraWorks Forum
Welcome to Autodesk’s InfraWorks Forums. Share your knowledge, ask questions, and explore popular InfraWorks topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creation date scripting through CSV

17 REPLIES 17
Reply
Message 1 of 18
scott.fleming27
964 Views, 17 Replies

Creation date scripting through CSV

I am attempting to apply a creation date through a '.CSV' connection to either a point of interest or city furniture component.

 

The script is running but I cannot figure out the text for the ?? below:

 

write.CREATION_DATE = ( ?? [3]);

 

 

Full script:

 

 

function UpdateCITY_FURNITUREData() {
var db = app.ActiveModelDb;
var sset = app.ActiveSelectionSet;
if (sset.QueryCount() < 1) {
alert("Please select one or more City Furniture and try again.");
return;
}
var tableName = "CITY_FURNITURE";
var filter = sset.GetFilter(db.TableIndex("CITY_FURNITURE"));
var table = db.Table("CITY_FURNITURE");
var extent = table.QueryExtent(filter);

table.StartQuery(filter);
table.BeginWriteBatch();

var read;
var write = table.GetWriteRow();
while (read = table.Next()) {
var coords = file.ReadFile("P:/Glasgow/BLC/ARCH/370311 - CPR/02-Drawings/2.00-BIM/01-WIP/Infraworks_Data/Script File.csv");
var coordsa = coords.split("\n");
for (var i = 0; i < coordsa.length; i++) {
var txta = coordsa[i].split(",");
if (txta.length < 4) // Number of columns in the CSV file
continue;
// If the name of the building is euqal to the record
// found in the CSV file then...
if (read.NAME == (txta[0])) { // 0 is the first column - A
write.CREATION_DATE = (dt[3]); // Scale X Updated
// (4th column - D)
table.UpdateFeature(write, read.ID); // Update the model
write.Invalidate();
}
}
}
table.CommitWriteBatch();
table.EndQuery();
app.InvalidateTileCache(db.TableIndex(tableName), extent);
return true;
}

UpdateCITY_FURNITUREData();

17 REPLIES 17
Message 2 of 18

@scott.fleming27, I understand what you are trying to do here and InfraWorks JS can probably get this done the way you want but that takes good scripting skills which most users lack. I think InfraWorks 360 should provide a capability of adding multiple Data Sources to features. That way you could use a specific key to connect your CSV file (or even other GIS data sources) to your Furniture Items and populate the creation dates.

 

Please vote on this idea if you also support this.

John de Leeuw
Senior Consultant

Community Ambassador - Twitter - LinkedIn

Message 3 of 18
Matt__W
in reply to: scott.fleming27

'dt' needs to be 'txta' if the data you're trying to apply to the CREATION_DATE is in the fourth column of the CSV.



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 4 of 18
scott.fleming27
in reply to: Matt__W

I had this as 'txta' Matt, and the script will work for other options such as "Description" etc. (basic text options) but for the creation date this does not have any affect .........hence why I hoping that changing the 'txta' from text to a date command would work

This is one of my first times scripting, although I get the ideal generally, I can't get my head round this one!

Thanks,

Scott
Message 5 of 18
Matt__W
in reply to: scott.fleming27

Can you post a screenshot of the first few columns/rows so I can see how the data is formatted?



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 6 of 18

Thanks John, the script works for most properties just not creation date. This is why I am trying to script it differently

Thanks,

Scott
Message 7 of 18
Matt__W
in reply to: scott.fleming27

After looking at it a bit more, you may need to convert the text string (for the date value) to a date. I don't have time right now to dive into it but let me Google it for you.  Smiley Very Happy

 

See if you can come up with a solution. If not, would a set of custom properties be an option? You could add anything you want and format the fields to your liking.



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 8 of 18
scott.fleming27
in reply to: Matt__W

Thanks for that Matt haha

Custom properties will not be linked to an actual date and therefore the model time feature, I will look into the script some more!
Message 9 of 18
Matt__W
in reply to: scott.fleming27

Any luck with this? I've been playing around with all sorts of stuff (date parsing, formats, etc) but still no luck. Might have to call in the big guns and ask for help. @elliott.rosenfeld, got any ideas on how to input a value for the Creation Date of an object?



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 10 of 18
elliott.rosenfeld
in reply to: Matt__W

Hi Matt, all:

 

Good discussion here! I'll play around with this today and get back to you. I have also sent this discussion to one of our resident JS experts, so hopefully we can find a solution very soon.

 

Best,

Elliott


Principal Specialist, Infrastructure
Message 11 of 18

Thanks for the help all.

 

We have managed to figure it out with the help of the JS guys in our office. We have dates appearing in the properties when running the script (see image). Result!

 

The date appears to be considering the time as well and therefore reads it as a day before, we will sort that out and I shall share the script when refined.

 

Thanks

 

Scott 

Message 12 of 18

Awesome! Glad to hear it! I'd like to hear more about your solution if possible. Are you willing to share your script so we can look it over?

..also, i just heard back from a colleague, who provided me this information, in case it's still handy for anyone reading this:

 

"I was able to write a date to the property CREATION_DATE by using a JS date object. The user should be able to split the string variable which contains the complete date/time which is read from the CSV file and convert it to a date by
    var d = new Date(year, month, day, time, minutes, seconds)
  and then assign d to the CREATION_DATE property

 

To improve performance, it would probably be better to first read the name out of the CSV file, create a filter out of it and then query the database table using this filter, which should return a single feature only.  But depending on the (small?) number of CityFurniture assets, this might not be necessary."

Thanks!

Elliott


Principal Specialist, Infrastructure
Message 13 of 18
Matt__W
in reply to: elliott.rosenfeld

Ahhh!!!  I was soooo close with the code I was messing around with.  🙂

Thanks for posting @elliott.rosenfeld. Just need to keep in mind that the months are stored in a list format with the first item being [0]. 0 = January, 1 = February, 2 = March, 3 = April and so on and so forth.

 

 

var d = new Date("2016", ("08" -1), "10");
write.CREATION_DATE = (d);
// Returns 10-Aug-2016

 



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 14 of 18

Thanks Matt!

 

Just to keep everyone in the loop for future reference, the issue we seem to be having is time zone, where the model defaults at 00:00:00 but at some point in the process it resorts back to 23:00:00 on the day before due to time zone. being -1hour

 

Trying to work out the solution just now in the script, we could obviously specify the time in the script and this would solve it but we really don't want to have our excel and then the .csv with time data displayed as it is unnecessary in 99% of projects.

 

Thanks,

 

Scott

 

 

Message 15 of 18
Matt__W
in reply to: scott.fleming27

If you can post your JS code maybe we can help you figure it out. More eyes are (almost) always better.



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Message 16 of 18
scott.fleming27
in reply to: Matt__W

We have worked out a better way to to write the date and it will work without any further coding or format.

If you put the date in your CSV file as 2016/08/30.

With slashes not dashes (as it appears in infraworks) and also in a backwards format then this somehow links!
Message 17 of 18

All,

 

I have proposed this for the AU 2017 conference, please vote for me and I will share all!

 

Proposal is called "The Land Before Time - The Infraworks 360 feature we have all been missing."

 

Thanks in advance if you do vote!

 

Cheers,

 

Scott

Message 18 of 18
Matt__W
in reply to: scott.fleming27

@scott.fleming27very cool and good luck. I just voted for it. And feel free to use this script to automate the exporting of images (if you're using bookmarks).

https://knowledge.autodesk.com/community/article/21911

 



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report