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

Create Revit Sheets from Excel

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
miketurpin
4851 Views, 11 Replies

Create Revit Sheets from Excel

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

11 REPLIES 11
Message 2 of 12
tlogan_lmn
in reply to: miketurpin

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
miketurpin
in reply to: miketurpin

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

 

Message 4 of 12
Partha.Sarkar
in reply to: miketurpin

Hi miketurpin,

 

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

 

Thanks,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 5 of 12
miketurpin
in reply to: Partha.Sarkar

Partha,
All resolved thanks.
Have accepted as solution.
Message 6 of 12
karthik_dkk
in reply to: miketurpin

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..

Message 7 of 12
tlogan_lmn
in reply to: karthik_dkk

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

 

 

Message 8 of 12
KellyR1641
in reply to: tlogan_lmn

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

Message 9 of 12
farshid90
in reply to: tlogan_lmn

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

Message 10 of 12
KellyR1641
in reply to: farshid90

I have not done anything in Revit API for quite some time, sorry.
Message 11 of 12
farshid90
in reply to: tlogan_lmn

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.

 

Message 12 of 12
J33C316
in reply to: tlogan_lmn

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.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community