Change Titleblock family with other

Change Titleblock family with other

stefano.cartaKGT96
Advocate Advocate
759 Views
5 Replies
Message 1 of 6

Change Titleblock family with other

stefano.cartaKGT96
Advocate
Advocate

HI..

 

I am tryng to change the Titleblock on a sheet with another family loaded in the model.

Dim titleblock As FamilyInstance = New FilteredElementCollector(doc).OfClass(GetType(FamilyInstance)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast(Of FamilyInstance)().First(Function(q) q.OwnerViewId = vs.Id)

                    Dim fInstance As FamilyInstance = TryCast(titleblock, FamilyInstance)
                    Dim FType As FamilySymbol = titleblock.Symbol
                    Dim Fam As Family = FType.Family
                    Dim NomeCart As String = Fam.Name

 

I can find the instance of the titleblock and channge the type,  but I don't know how change with another family. 

Where i can find a sample?

Stefano

0 Likes
Accepted solutions (1)
760 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor

All FamilySymbols from all Families loaded are in the project so you don't need to deal with families.

 

Filter for FamilySymbols similar to how you have filtered for FamilyInstances.

 

If symbol is not there then it needs to be loaded from family. Should check FamilySymbol.IsActive before using a FamilySymbol (if not active call FamilySymbol.Activate).

 

Private Function TObj164(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result

        Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
        If UIDoc Is Nothing Then Return Result.Cancelled Else
        Dim IntDoc As Document = UIDoc.Document

        Dim R As FamilyInstance = Nothing
        Try
            R = TryCast(IntDoc.GetElement(UIDoc.Selection.PickObject(Selection.ObjectType.Element)), FamilyInstance)
        Catch ex As Exception
            Return Result.Cancelled
        End Try
        If R Is Nothing Then Return Result.Cancelled Else
        If R.Category Is Nothing Then Return Result.Cancelled Else
        If R.Category.Id.IntegerValue <> CInt(BuiltInCategory.OST_TitleBlocks) Then Return Result.Cancelled Else

        Dim FEC As New FilteredElementCollector(IntDoc)
        Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_TitleBlocks)
        Dim TargetName As String = "A1 metric"
        Dim FS As FamilySymbol = FEC.WherePasses(ECF).WhereElementIsElementType _
                                                        .ToElements.Cast(Of FamilySymbol) _
                                                        .FirstOrDefault(Function(x) x.Name = TargetName)

If FS Is Nothing Then Return Result.Cancelled Else

        Using tx As New Transaction(IntDoc, "Change title block")
            If tx.Start = TransactionStatus.Started Then
                If FS.IsActive = False Then
                    FS.Activate()
                End If

                R.ChangeTypeId(FS.Id)

                tx.Commit()
            End If

        End Using

        Return Result.Succeeded

    End Function

 

 

 

 

0 Likes
Message 3 of 6

stefano.cartaKGT96
Advocate
Advocate

HI..

Thanks for your replay...I try your code but I am confused,

in my model I have 2 Families for Titleblock, one is named "HVS_EXT_Cartouche" and the other "HVS_EXT_Cartouche+rev", this last in inserted in the other sheets

I have to check if on the current sheet there is the first and then change it with the second.

The type in the family is the some for first and second: "A0+1F".

in the the targetname I have to put "A0+1F" but the filter find the first family.

what's wrong?

 Dim titleblock As FamilyInstance = New FilteredElementCollector(doc).OfClass(GetType(FamilyInstance)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast(Of FamilyInstance)().First(Function(q) q.OwnerViewId = vs.Id)

                    Dim fInstance As FamilyInstance = TryCast(titleblock, FamilyInstance)
                    Dim FType As FamilySymbol = titleblock.Symbol
                    Dim Fam As Family = FType.Family
                    Dim NomeCart As String = Fam.Name




                    Dim FEC As New FilteredElementCollector(doc)
                    Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_TitleBlocks)
                    Dim TargetName As String = "A0+1F" '"HVS_EXT_Cartouche+rev"
                    Dim FS As FamilySymbol = FEC.WherePasses(ECF).WhereElementIsElementType _
                                                            .ToElements.Cast(Of FamilySymbol) _
                                                            .FirstOrDefault(Function(x) x.Name = TargetName)

                    If FS Is Nothing Then Return Result.Cancelled Else



                    If FS.IsActive = False Then
                                FS.Activate()
                            End If

                    titleblock.ChangeTypeId(FS.Id)

 

0 Likes
Message 4 of 6

stefano.cartaKGT96
Advocate
Advocate

HI..

Thanks for your replay...I try your code but I am confused,

in my model I have 2 Families for Titleblock, one is named "HVS_EXT_Cartouche" and the other "HVS_EXT_Cartouche+rev", this last in inserted in the other sheets

I have to check if on the current sheet there is the first and then change it with the second.

The type in the family is the some for first and second: "A0+1F".

in the the targetname I have to put "A0+1F" but the filter find the first family.

what's wrong?

 

 Dim titleblock As FamilyInstance = New FilteredElementCollector(doc).OfClass(GetType(FamilyInstance)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast(Of FamilyInstance)().First(Function(q) q.OwnerViewId = vs.Id)

                    Dim fInstance As FamilyInstance = TryCast(titleblock, FamilyInstance)
                    Dim FType As FamilySymbol = titleblock.Symbol
                    Dim Fam As Family = FType.Family
                    Dim NomeCart As String = Fam.Name




                    Dim FEC As New FilteredElementCollector(doc)
                    Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_TitleBlocks)
                    Dim TargetName As String = "A0+1F" '"HVS_EXT_Cartouche+rev"
                    Dim FS As FamilySymbol = FEC.WherePasses(ECF).WhereElementIsElementType _
                                                            .ToElements.Cast(Of FamilySymbol) _
                                                            .FirstOrDefault(Function(x) x.Name = TargetName)

                    If FS Is Nothing Then Return Result.Cancelled Else



                    If FS.IsActive = False Then
                                FS.Activate()
                            End If

                    titleblock.ChangeTypeId(FS.Id)

 

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

You can distinguish between the two using FamilySymbol.Family.Name.

 

Alternatively after initially filtering for the Family you can then use FamilySymbolFilter to filter for the FamilySymbols within that family. Either way they are all in the project one way or the other so it is more about distinguishing between them.

0 Likes
Message 6 of 6

stefano.cartaKGT96
Advocate
Advocate

thanks!!!

0 Likes