Add Reference Points Read From CSV File
Originally Published inFor your convenience and my own future reference, here is a summary of a recent conversation ↗ with Dermott Mcmeel and a pointer to his video of the resulting add-in in action ↗.
Question: I’m using this wicked tutorial ↗ as a basis for a plug-in that will read info out of a CSV file. However, it’s a few years old and from what I gather some of the definitions have been redefined our outdated. I’ve done the ‘First Revit API plug-in tutorial’ and am stoked about my success. But I’m new to VB and C#, so I was wondering if anyone has updated info? Or could point out changes and where updated info might be found?
Answer: I converted the VB code to read a CSV file and generate Revit reference points ↗ to C# for you:
string filepath = "insert file path here";
if( File.Exists( filepath ) )
{
StreamReader s = new StreamReader(
filepath );
while( -1 != s.Peek() )
{
string line = s.ReadLine();
string[] data = line.Split(
new char[] { ',' } );
XYZ p = app.Create.NewXYZ(
double.Parse( data[0] ),
double.Parse( data[1] ),
double.Parse( data[2] ) );
ReferencePoint rp = doc.FamilyCreate
.NewReferencePoint( p );
}
}
Response: The code is very much appreciated. I am however having some trouble pasting it into the right context…
I’ve tried some remedial trouble shooting, but as I fix one error it creates another one.
I pasted the code straight into a blank C# class library template (as per Revit API tutorial 1) but get lots of errors – I assume I’m making a stupid mistake in the syntax but can’t figure it out. Any help appreciated… and again thanks for the helping hand.
Answer: Please work through one of the getting started tutorials first, before even thinking about CSV:
Then you will have a reliable working skeleton in place and almost certainly gotten a better hang of it.
Response: Thanks for all your help!
See the results:
Revit API for CSV reading ↗ from Dermott Mcmeel ↗ on Vimeo ↗.
Answer: For the sake of completeness, here is ReadCsvPoints.zip containing Jeremy’s C# version (and complete Visual Studio solution with add-in manifest) of an add-in to read point data from a CSV file and generate Revit reference points from it, and a snapshot of Dermott’s WIP C# code (work in progress).
Many thanks to Dermott for the interesting topic, his research, and sharing the code!