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
Solved! Go to Solution.
Solved by tlogan_lmn. Go to 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(); }
Thanks for the reply I will try looking at that SDK sample and using a CSV file.
Hi miketurpin,
Could you confirm if this is resolved ? Or do you need any further help ?
Thanks,
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..
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.
Could you please explain the process ( step by step ) just general, in visual studio and not in macro?
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.
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.