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
Solved! Go to Solution.
Solved by bejenaru.a. Go to Solution.
Maybe the scope box name is used as some kind of identifier to link it with some other object?
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
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)); }
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