Hello
Newbie question, how can I clear the Mark parameter value on all family instances in use?
Here is my attempt:
Public Function Execute( ByVal commandData As ExternalCommandData, ByRef message As String, ByVal elements As ElementSet) _ As Result Implements IExternalCommand.Execute Dim uiapp As UIApplication = commandData.Application Dim uidoc As UIDocument = uiapp.ActiveUIDocument Dim app As Application = uiapp.Application Dim doc As Document = uidoc.Document Dim sel As Selection = uidoc.Selection 'TODO: Add your code here Dim FamilyInstanceFilter As New ElementClassFilter(GetType(FamilyInstance)) Dim FamilyInstanceCollector As New FilteredElementCollector(doc) Dim AllFamilyInstances As ICollection(Of Element) = FamilyInstanceCollector.WherePasses(FamilyInstanceFilter).ToElements() Dim ParamLst As New List(Of String)() Dim FmlySmbl As FamilySymbol Dim Fmly As Family Dim res As New List(Of String) For Each FmlyInst As FamilyInstance In AllFamilyInstances FmlySmbl = FmlyInst.Symbol Fmly = FmlySmbl.Family Dim pbin As BuiltInParameter For Each pbin In [Enum].GetValues(GetType(BuiltInParameter)) If (Not FmlyInst.Parameter(pbin) Is Nothing) Then If pbin.ToString = "Mark" Then FmlyInst.Parameter(pbin).SetValueString("") ' res.Add(pbin.ToString & vbTab & FmlyInst.Parameter(pbin).AsValueString() & vbCrLf) End If Next Next TaskDialog.Show("I am the title", "All Family Instances Have Had Mark Numbers Reset") '"All Family Instances Have Had Mark Numbers Reset" Using tx As New Transaction(doc) tx.Start("RevitAddin1") tx.Commit() End Using 'Must return some code Return Result.Succeeded End Function
Solved! Go to Solution.
Solved by Hugh_Compton. Go to Solution.
Hi
I know how to Do it in C# but I trust you can translate it to VB -- assuming you are working on REvit 2015+
UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document m_doc = uidoc.Document; FilteredElementCollector filcol = new FilteredElementCollector(m_doc).OfClass(typeof(FamilyInstance)); using (Transaction t = new Transaction(m_doc, "ClearMark")) { t.Start(); foreach (Element e in filcol) { e.LookupParameter("Mark").Set(""); } t.Commit(); }
Hi,
it's better to use the language independent BuiltInParameter (if existing) instead of strings.
e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).Set("");
Revitalizer
Thank you both! I had to add a Try Catch since Revit threw a "Object reference not set to an instance of an object." error on some element that I couldn't see (I assume). Here's the final version:
Public Function Execute(ByVal commandData As ExternalCommandData, ByRef message As String, ByVal elements As ElementSet) As Result Implements IExternalCommand.Execute Dim uiapp As UIApplication = commandData.Application Dim uidoc As UIDocument = uiapp.ActiveUIDocument Dim app As Application = uiapp.Application Dim doc As Document = uidoc.Document Dim sel As Selection = uidoc.Selection 'TODO: Add your code here Dim filcol As FilteredElementCollector = New FilteredElementCollector(doc).OfClass(GetType(FamilyInstance)) Using t As New Transaction(doc, "RevitAddin1") t.Start() For Each e As Element In filcol Try 'e.LookupParameter("Mark").[Set]("") ' Works, using Built In parameter instead e.Parameter(BuiltInParameter.ALL_MODEL_MARK).[Set]("") Catch ex As Exception ' This is to stop errors "Object reference not set to an instance of an object." End Try Next t.Commit() End Using TaskDialog.Show("I am the title", "All Family Instances Have Had Mark Numbers Reset") '"All Family Instances Have Had Mark Numbers Reset" 'Must return some code Return Result.Succeeded End Function
Full disclosure, I'm not that good at VB.NET yet, please forgive me if this is an easy to fix issue.
I tried the Clear Mark Value On All Families In Use Macro and after Building Solution it comes up with 3 errors.
I can not find out how to fix these errors.
I'm using Sharp Develop for Revit 2020.
Any help would be appreciated.
Can't find what you're looking for? Ask the community or share your knowledge.