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: 

Rename a scope box via api

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
david_rock
3773 Views, 5 Replies

Rename a scope box via api

Hello,

 

Is it possible to rename a scope box via the api?

 

I can get the name of a scope box with element.name it does not seem to be parameter diven.

 

However if I try to set the name of the element I get. This element does not support assignment of a user-specified name.

 

Any ideas? 

 

Kind Regards

David

 

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: david_rock

Maybe the scope box name is used as some kind of identifier to link it with some other object?



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

Message 3 of 6
david_rock
in reply to: jeremytammik

Anouther issue I'm having is I can't seem to collect the scope boxes from a linked model. The following works if the objDocument is the active document but not if the document is linked.

 

Public Shared Function GetAllScopeBoxs(ByVal objDocument As Autodesk.Revit.DB.Document) As List(Of Element)
Try
Dim ListOfElement As New List(Of Element)
Dim ElementIter As IEnumerator
Dim objCollector As New FilteredElementCollector(objDocument)
Dim eleactiveDBdoc As FilteredElementCollector = objCollector.WhereElementIsNotElementType()
ElementIter = eleactiveDBdoc.GetEnumerator
Do While ElementIter.MoveNext
Dim objElement As Element = ElementIter.Current
Dim objCategory As Category = objElement.Category
If objCategory IsNot Nothing Then
If objCategory.Name.Contains("Scope Boxes") Then
ListOfElement.Add(objElement)
End If
End If
Loop
Return ListOfElement
Catch ex As Exception
msgbox(ex.message)
Return Nothing
End Try
End Function

 

Kind Regards

David

 

Message 4 of 6
Anonymous
in reply to: david_rock

Try using a category filter on your FilteredElementCollector instead of checking to see if the category name contains "Scope Boxes". If your linked Revit models are in another language, your check for the name of the category would fail.  

.OfCategory(BuiltInCategory.OST_VolumeOfInterest)

It's not immediately obvious, but OST_VolumeOfInterest is the category that scope boxes belong to.

 

This should also increase the performance of your code by a fair bit, since you are now only retrieving scope boxes instead of checking every instance element in the project.

 

I wrote a quick test macro and was able to retrieve the scope boxes from a linked model (Revit 2015).

 

public void ScopeBoxTest()
		{
			Document doc = this.ActiveUIDocument.Document;
			
			//Helper function
			var loadedLinkDocs = doc.GetLoadedLinkedDocuments();
			
			var firstDoc = loadedLinkDocs.First();
			
			var linkedScopeBoxes = new FilteredElementCollector(firstDoc).OfCategory(BuiltInCategory.OST_VolumeOfInterest).ToList();
			
			TaskDialog.Show("Result", string.Format("{0} scope boxes found in linked model", linkedScopeBoxes.Count));
		}

 

Message 5 of 6
bejenaru.a
in reply to: Anonymous

Here's how I managed to batch change the scope boxes names

 

		public void ChangeNameScopeBox()
		{
			
			UIDocument uidoc = this.ActiveUIDocument;
			Document doc = uidoc.Document;
			
			string checkstring="";
			string originalName="";
			string newName="";
			
			View3D view = doc.ActiveView as View3D;
			
			 if( null == view )
			  {
			 	TaskDialog.Show("error", "Please run this command in a 3D view.");
			    return;
			  }
			 
			 
			
			// get all elements in the model
			ICollection<Element> scopeBoxes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest).ToElements();

			
			// create and start a new transaction
			using(Transaction t = new Transaction(doc, "Change scopebox name"))
			{
				t.Start();
				
				foreach (Element e in scopeBoxes) {
					
					if (e.Name.Contains("De coupage")) {
						
						originalName = e.Name;
						newName = originalName.Replace("De coupage","Decoupage");
						
						Parameter par = e.get_Parameter(BuiltInParameter.VOLUME_OF_INTEREST_NAME);
						par.Set(newName);
						
					    checkstring=checkstring + Environment.NewLine + e.Name;
					}
				}
				
				
				// finalize transaction				
				t.Commit();

				// show dialog of how many views were created
				TaskDialog.Show("Cahnged scopeboxes", "scopeboxes: " +checkstring);	
			}
				
		}

You can acces the bulit parameter wich stores the Name 

Parameter par = e.get_Parameter(BuiltInParameter.VOLUME_OF_INTEREST_NAME);

I've got the "inspiration from Jeremy's bolg: http://thebuildingcoder.typepad.com/blog/2012/08/set-view-section-box-to-match-scope-box.html

 

Hope this helps,

Best

Andrei Bejenaru
Message 6 of 6
david_rock
in reply to: bejenaru.a

BuiltInParameter.VOLUME_OF_INTEREST_NAME

Ahh so easy, thank you so much 🙂

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