Interior elevation rename

will.wydock
Advocate
Advocate

Interior elevation rename

will.wydock
Advocate
Advocate

I am working on a routine to rename my interior elevations that is based on room information. Right now it is supposed to update all elevations but it does not appear to do anything. I eventually would like to make this routine only update selected elevation(s). 

 

		public void renameelevation()
		{
			Document doc = this.Document;
			string newvname="";
	
			using(Transaction tr = new Transaction(doc, "Rename Elevations"))
			{
				
				FilteredElementCollector collector= new FilteredElementCollector( doc ).OfClass( typeof(ViewSection ) );			  
				
				tr.Start();
				{
				foreach(Element E in collector )
				{
					try
					{ 
						ViewSection current= E as ViewSection;
						{
						int value=0;
						value++;
						// Construct a point at the midpoint of the 
						// front bottom edge of the elev view cropbox
						
						double xmax = current.CropBox.Max.X;
						double xmin = current.CropBox.Min.X;
						double zmax = current.CropBox.Max.Z;
						
						XYZ pt = new XYZ(
						xmax - 0.5 * ( xmax - xmin ),
						1.0,
						zmax);
						
						
						// Get pt's translation to 
						// project coordinate system
						
						pt = current.CropBox.Transform.OfPoint( pt );
						
						Autodesk.Revit.DB.Architecture.Room rm
						= doc.GetRoomAtPoint( pt );
							if (null != rm)
							{
							string x = value.ToString();
							string combinedName= "EI-"+rm.Number+x;
							
							current.Name = combinedName;
							
							newvname += combinedName + "\n";
							}
						}
					}
					catch(Exception)
					{
					}
				}
				}
				tr.Commit();
			}
			
		}

Thanks

0 Likes
Reply
1,169 Views
5 Replies
Replies (5)

FAIR59
Advisor
Advisor

Maybe you have to use another overload to find the room : GetRoomAtPoint( pt ,phase) .

The version you are using tries to find a room in the final phase of the project, see http://www.revitapidocs.com/2015/656d34c2-1e53-7278-ab83-fefaff7f40a4.htm

0 Likes

RPTHOMAS108
Mentor
Mentor

Is the point definitely in the room? i.e. is bottom of cropbox no more than 1’ (offset you have) below room and elevation line intersecting room? Generally, I plot these points with model lines to check they are appearing in the expected location.

 

In the final version you have to also be careful of naming views with names that already exist since that will cause an exception. Routine may attempt to rename two elevations in the same room with the same name. Need to first count how many are in each room and suffix with that number. Should also allow for fact that section may have been moved elsewhere with same name.

0 Likes

will.wydock
Advocate
Advocate

FAIR59 wrote:

Maybe you have to use another overload to find the room : GetRoomAtPoint( pt ,phase) .

The version you are using tries to find a room in the final phase of the project, see http://www.revitapidocs.com/2015/656d34c2-1e53-7278-ab83-fefaff7f40a4.htm


 



Although it was not the problem,I should have realized that phasing was going to be a factor in this. Is there a way to extract phase from the elevations? The only thing i was seeing was Phase Created and demolished ID's which was turning up as null in Revit Lookup. I know that i can lookup Phase for the view as a parameter, but how can that be converted to a phase?

0 Likes

will.wydock
Advocate
Advocate

@RPTHOMAS108 wrote:

Is the point definitely in the room? i.e. is bottom of cropbox no more than 1’ (offset you have) below room and elevation line intersecting room? Generally, I plot these points with model lines to check they are appearing in the expected location.

 

In the final version you have to also be careful of naming views with names that already exist since that will cause an exception. Routine may attempt to rename two elevations in the same room with the same name. Need to first count how many are in each room and suffix with that number. Should also allow for fact that section may have been moved elsewhere with same name.


 

The point is definitely in the room. The problem I was having does have to do with duplicate naming. That was why I appended the count to the view name. It didn't quite perform how i thought it would, it was appending the totals for the routiine and not incrementing the view names. Can you point me in the direction of incrementing redundant naming?

 

Thanks

0 Likes

FAIR59
Advisor
Advisor

A phase is an Element , the  storage type of the BuiltInParameter VIEW_PHASE of the view is ElementId

Phase viewphase = doc.GetElement(phaseParameter.AsElementId()) as Phase;

 

regarding duplicate viewnames:

I would collect all the viewnames in the project, and check the new name against them, changing the new name if necessary.

 

			List<string> viewnames = new FilteredElementCollector(doc)
				.OfClass(typeof(View))
				.Cast<View>()
				.Select(v => v.Name)
				.ToList();
			int x =0;
			string newvname = "EI-"+rm.Number+x.ToString();
			while (viewnames.Contains(newvname))
			{
				x++;
				newvname = "EI-"+rm.Number+x.ToString();
			}
			viewnames.Add(newvname);
0 Likes