[REVIT 2017 - VB] Loaded family not showing in Project Browser

[REVIT 2017 - VB] Loaded family not showing in Project Browser

Anonymous
Not applicable
966 Views
3 Replies
Message 1 of 4

[REVIT 2017 - VB] Loaded family not showing in Project Browser

Anonymous
Not applicable

Hello everyone,

I'm new to Revit programming and I'm trying to load a family symbol/type through VB macro in Revit 2017 (SharpDevelop).

Code is very simple: I load a beam family or a single symbol/type contained in the family.

 

 

Sub LoadFamilySymbol_fp()
		Dim sFName, sTName As String
		'create transaction e load the family
		Using t As New Transaction (Me.Document, "LoadFamily")
			If t.Start = TransactionStatus.Started Then
				sFName = "C:\ProgramData\Autodesk\RVT 2017\Libraries\Italy\Telaio strutturale\Acciaio\Travi HE.rfa"
				sTName = "HE180A"
				
				'Document.LoadFamilySymbol(sFName,sTName)   'load only a symbol/type contained in the family
				Document.LoadFamily(sFName)                 'load the entire family
			End If
			t.Commit
		End Using
End Sub

 

Code works fine and I get no errors, however the newly loaded family or family symbol/type do not show in Project Browser.

On the other hand, after executing the Sub above, if I try to manually load a family via the Insert > Load Family menu, I get a warning that the family already exists in the project (see attached image).

 

How this happens? Should I change my code above to tell Revit this family is actually a Structural Framing family?

 

Thanks in advance for your valuable feedback.

 

fp

 

 

0 Likes
Accepted solutions (1)
967 Views
3 Replies
Replies (3)
Message 2 of 4

matthew_taylor
Advisor
Advisor
Accepted solution

Hi fp,

You need to implement another overload of .LoadFamily:

Dim familyLoadOptions As New FamilyLoadOptions
Dim tempFamily As DB.Family = Nothing
If m_doc.LoadFamily(fileName, familyLoadOptions, tempFamily) Then
...

With *something like* this:

 

Public Class FamilyLoadOptions
    Implements db.IFamilyLoadOptions

#Region "IFamilyLoadOptions Interface methods"

    Public Function OnFamilyFound(ByVal familyInUse As Boolean, _
ByRef overwriteParameterValues As Boolean) _
As Boolean Implements db.IFamilyLoadOptions.OnFamilyFound overwriteParameterValues = True Return True End Function Public Function OnSharedFamilyFound(ByVal sharedFamily As DB.Family, _
ByVal familyInUse As Boolean, _
ByRef source As DB.FamilySource, _ ByRef overwriteParameterValues As Boolean) _
As Boolean Implements db.IFamilyLoadOptions.OnSharedFamilyFound overwriteParameterValues = True Return True End Function #End Region End Class

 

Note that one of the foibles of .LoadFamily is that it won't return the family if the family is already loaded (and is the same version).

I seem to remember that it doesn't even return true. I guess that's by design.

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 4

FAIR59
Advisor
Advisor

maybe you could try an explicit Document.Regenerate()  after your using statement.

0 Likes
Message 4 of 4

Anonymous
Not applicable

Dear Matthew, I apologize for the terrible delay: I've been off for quite a while.

Your solution works flawlessly!

Thanks for your support.

 

Thanks also to FAIR59 for the hint: Document.Regenerate() did not solve the problem though.

 

Have a nice week.

fp