Code from this morning’s class at #RTCEUR

Not at #RTCEUR?

Did something else with your morning?

Came to the class and would like the source code?

public void CountElements()
{
    try
    {
        Document doc = this.ActiveUIDocument.Document;
        ICollection<Element> walls = new FilteredElementCollector(doc)
            .OfCategory(BuiltInCategory.OST_Walls).WhereElementIsCurveDriven().ToList();
        // TaskDialog.Show("Count", "# of Walls " + walls.Count);
        
        string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        
        // these two lines do the same thing
        string otherway = desktop + @"\" + @"RTC_EUR_2015-2015-10-28\RTC EUR 2015\You can be a Revit Programmer\output.";
		string pathToFile = Path.Combine(desktop, @"RTC_EUR_2015-2015-10-28\RTC EUR 2015\You can be a Revit Programmer\output.");
		
		//using (StreamWriter writer = new StreamWriter(@"C:\Users\harry_000\Desktop\RTC_EUR_2015-2015-10-28\RTC EUR 2015\You can be a Revit Programmer\output.", true))
		using (StreamWriter writer = new StreamWriter(pathToFile, true))
		{
			// Write doesn't add a new line at the end, WriteLine does
			// or Environment.NewLine to insert a line break
		    writer.WriteLine(walls.Count);
		    
		    foreach (Element element in walls) {
		    	
		    	writer.Write(element.Name + " " + element.Id.IntegerValue);
		    	// need to cast from Element to Wall
		    	
		    	Wall wall = element as Wall;
		    	
		    	
		    	Parameter paramVolume = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED);
		    	StorageType storageVolume = paramVolume.StorageType;
		    	
		    	// match the method (AsDouble, AsInteger) with how the value is stored
		    	double volume = paramVolume.AsDouble();
		    	volume = UnitUtils.ConvertFromInternalUnits(volume, DisplayUnitType.DUT_CUBIC_METERS);
		    	writer.WriteLine(" " + wall.Width + " " + volume);
		    	
		    	writer.WriteLine();
		    	
		    }
		    
		}
	}
	catch (Exception ex)
	{
		TaskDialog.Show("",ex.Message);
	}
		
}
Advertisements

4 thoughts on “Code from this morning’s class at #RTCEUR

  1. […] public void CountElements() { try { Document doc = this.ActiveUIDocument.Document; ICollection<Element> walls = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Walls).WhereElementIsCurveDriven().ToList(); // TaskDialog.Show("Count", "# of Walls " + walls.Count); string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // these two lines do the same thing string otherway = desktop + @"" + @"RTC_EUR_2015-2015-10-28RTC EUR 2015You can be a Revit Programmeroutput."; string pathToFile = Path.Combine(desktop, @"RTC_EUR_2015-2015-10-28RTC EUR 2015You can be a Revit Programmeroutput."); //using (StreamWriter writer = new StreamWriter(@"C:Usersharry_000DesktopRTC_EUR_2015-2015-10-28RTC EUR 2015You can be a Revit Programmeroutput.", true)) using (StreamWriter writer = new StreamWriter(pathToFile, true)) { // Write doesn't add a new line at the end, WriteLine does // or Environment.NewLine to insert a line break writer.WriteLine(walls.Count); Read more […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s