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: 

Clear Mark Value On All Families In Use

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Hugh_Compton
2050 Views, 4 Replies

Clear Mark Value On All Families In Use

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

 

4 REPLIES 4
Message 2 of 5
Moustafa_K
in reply to: Hugh_Compton

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();
            }

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 5
Revitalizer
in reply to: Moustafa_K

Hi,

 

it's better to use the language independent BuiltInParameter (if existing) instead of strings.

e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).Set("");

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 5
Hugh_Compton
in reply to: Hugh_Compton

 

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
Message 5 of 5
Anonymous
in reply to: Hugh_Compton

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.

Screenshot 2020-11-02 173617.png

I can not find out how to fix these errors.

I'm using Sharp Develop for Revit 2020. 

Any help would be appreciated. 

@Hugh_Compton 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report