renaming views when creating levels

renaming views when creating levels

will.wydock
Advocate Advocate
783 Views
3 Replies
Message 1 of 4

renaming views when creating levels

will.wydock
Advocate
Advocate

I am working on a routine for Revit 2015 for creating levels and the corresponding views with a form. I have everything working correctly with regards to this creating levels and views however, I am stuck on naming the views based on a value from the dialog box and either a value from if/then statements or a parameter embedded within the view templates. Any help would be greatly appreciated.

 

using (Transaction tx = new Transaction(doc)
{ tx.Start("Create New Level"); try { double elevfoot=FrmLvl.ElevFeet; double elevinch=FrmLvl.ElevInch; double elevation = elevinch/12+elevfoot; string lvlname=FrmLvl.Level_Name; string lvlabb=FrmLvl.Level_Abbr; string prefix="PN"; Level level = doc.Create.NewLevel(elevation); level.Name=lvlname; foreach (ViewFamilyType vfp in new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast<ViewFamilyType>() .Where(q => q.ViewFamily == ViewFamily.FloorPlan)) { ViewPlan newview = ViewPlan.Create(doc, vfp.Id, level.Id); string VIEWNAME = string.Concat(prefix,lvlabb); newview.Name=VIEWNAME; }}

Thanks

 

0 Likes
784 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Renaming a view is no problem.

 

What is a significant problem is trying to do everything at once.

 

Please separate your code into three clear steps:

 

  • Filtered element collector to retrieve the view.
  • Logic to determine the new name.
  • The actual setting of the name.

 

The last step obviously needs to be encapsulated in a transaction.

 

The others do not.

 

KISS!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

will.wydock
Advocate
Advocate

I tried what you suggested but I am not sure I filtered correctly for the views and levels.

 

                tx.Start("Create New Level");
		                try
		
		                {
		                	double elevfoot=FrmLvl.ElevFeet;
							double elevinch=FrmLvl.ElevInch;
		            		double elevation = elevinch/12+elevfoot;
							string lvlname=FrmLvl.Level_Name;
							string lvlabb=FrmLvl.Level_Abbr;
							string prefix="PN";
							
							Level level = doc.Create.NewLevel(elevation);
	                
							level.Name=lvlname;
		                   foreach (ViewFamilyType vfp in new FilteredElementCollector(doc)
		                        .OfClass(typeof(ViewFamilyType))
		                        .Cast<ViewFamilyType>()
		                		.Where(q => q.ViewFamily == ViewFamily.FloorPlan))
		                  		 {
		                       		ViewPlan newview = ViewPlan.Create(doc, vfp.Id, level.Id);
		                       		ElementLevelFilter collevel = new ElementLevelFilter(level.Id);
		                       		foreach(Autodesk.Revit.DB.View Fp in new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.View)).WherePasses(collevel).Cast<Autodesk.Revit.DB.View>().Where(q => q.ViewType == ViewType.FloorPlan))
			                       		using (Transaction t = new Transaction(doc))
							            {
		                       			t.Start("View Rename");
				                       	Fp.Name+=string.Concat(prefix,lvlabb);
				                       	t.Commit();
		                       			}
		                    	 }
		                   foreach (ViewFamilyType vcp in new FilteredElementCollector(doc)
		                        .OfClass(typeof(ViewFamilyType))
		                        .Cast<ViewFamilyType>()
		                		.Where(q => q.ViewFamily == ViewFamily.CeilingPlan))
		                  		 {
		                       		 ViewPlan newview = ViewPlan.Create(doc, vcp.Id, level.Id);
		                    	 }
		                    tx.Commit();
0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

No, that is not what I meant at all.

 

Split your code clearly.

 

 

For instance, collect the element ids that you wish to work with first, and then terminate that operation.

 

Do not perform any modifications at all inside the iteration of a filtered element collector.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes