Create Revit Sheets from Excel

Create Revit Sheets from Excel

Anonymous
Not applicable
5,604 Views
11 Replies
Message 1 of 12

Create Revit Sheets from Excel

Anonymous
Not applicable

Afternoon All,

I have an Excell document with 2 columns and 20 rows. The left column contains names and the right colum contains numbers.

Is it possible to write a plugin to read the data from the excel file (Name and Number) and then create a sheet for each row of data?

 

Are there any SDK samples which might assist with this?

 

Regards

Mike

0 Likes
Accepted solutions (1)
5,605 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Accepted solution

I would recommend starting with using CSV files and not Excel if you're never done it before.  It will be a lot easier to get up and running that way.  Here's a sample I cobbled together using some code from the ScheduleCreation SDK sample and some other stuff I've written in the past.  Tested it in a macro and it seems to work.

 

UIDocument uiDoc = this.ActiveUIDocument;
Document doc = uiDoc.Document;
string fileName;
			
System.Windows.Forms.OpenFileDialog openDlg = new System.Windows.Forms.OpenFileDialog();
openDlg.Title = "Select a file";
openDlg.Filter = "Comma Separated Values (*.csv)|*.csv|Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openDlg.RestoreDirectory = true;

System.Windows.Forms.DialogResult result = openDlg.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
  fileName = openDlg.FileName;
  System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
                
  //Create a filter to get all the title block types.
  FilteredElementCollector collector = new FilteredElementCollector(document);
  collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
  collector.WhereElementIsElementType();
				
  //Get ElementId of first title block type.
  ElementId titleBlockId = collector.FirstElementId();
				
  string csvLine = null;
                
  Transaction t = new Transaction(doc, "Create Sheets");
  t.Start();
  while ((csvLine = sr.ReadLine()) != null)
  {
    char[] separator = new char[] { ',' };
    string[] values = csvLine.Split(separator, StringSplitOptions.None);
    
    // Make sure both values are valid
    if(values[0] != null && values[0].Length > 0 && values[1] != null && values[1].Length > 0 )
    {
      ViewSheet sheet = ViewSheet.Create(doc, tbId);
      sheet.Name = values[1];
      sheet.SheetNumber = values[0];
    }
  }
  t.Commit();
}

 

Message 3 of 12

Anonymous
Not applicable

Thanks for the reply I will try looking at that SDK sample and using a CSV file.

 

0 Likes
Message 4 of 12

Anonymous
Not applicable

Hi miketurpin,

 

Could you confirm if this is resolved ? Or do you need any further help ?

 

Thanks,

 

0 Likes
Message 5 of 12

Anonymous
Not applicable
Partha,
All resolved thanks.
Have accepted as solution.
0 Likes
Message 6 of 12

karthik_dkk
Community Visitor
Community Visitor

hi,

thanks for the script.

can you please explain step by step that how can i run the script...?i dont know VB.net or C#.

I need to create empty sheets of 500 dwgs.

 

thankyou very much..

0 Likes
Message 7 of 12

Anonymous
Not applicable

If you don't know anything about creating macros, you may want to start with the basics of creating a macro.

 

http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-071913D8-214A-45AB-A798-A81653E77F88

 

There's a lot to cover if you've never done it before, but you should be able to copy/paste the code from above into your macro.  I noticed a couple of errors where I wrote the wrong variable name, once writing 'document' instead of the actual variable 'doc', and a second one where i wrote 'tbid' instead of the actual variable named 'titleBlockId'.  

 

You'll also have to add a reference to System.Windows.Forms under the References section in order for it to work.

 

AddReference.png

 

 

0 Likes
Message 8 of 12

Anonymous
Not applicable

might be nice if you closed the if statement, too.

0 Likes
Message 9 of 12

Anonymous
Not applicable

Could you please explain the process ( step by step ) just general, in visual studio and not in macro?

0 Likes
Message 10 of 12

Anonymous
Not applicable
I have not done anything in Revit API for quite some time, sorry.
0 Likes
Message 11 of 12

Anonymous
Not applicable

Thanks for the code

I wanted to try this code by copy and paste and also added the windows form. but the only error I got is this :

 

Task failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86. You may be able to solve the problem by doing one of the following:  1) Install the Microsoft Windows SDK.  2) Install Visual Studio 2010.  3) Manually set the above registry key to the correct location.  4) Pass the correct location into the "ToolPath" parameter of the task. (MSB3091)

 

I also installed the microsoft windoes SDK, but still I got the same error.

 

0 Likes
Message 12 of 12

J33C316
Advocate
Advocate

This code works unless a sheet with the same number already exist. How would you handle that short of editing the the CSV file? How would you skip and resume next? Thanks.

0 Likes