Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Work Or *NOT* - Document::LoadFamilySymbol(string filename, string name, out FamilySymbol symbol)

$
0
0

Recently spotted something about the signatures of the LoadFamilySymbol Revit API from a post on web:

How to programmatically load a new symbol from an existing Family in a Revit project

“You will find that neither of the following overloaded methods will work for you:
public bool Document::LoadFamilySymbol(string filename, string name)
public bool Document::LoadFamilySymbol(string filename, string name, out FamilySymbol symbol)
You will have to use the third version of this overloaded method:”

Not sure how the guy got the above assertion, but it did not sound right at all to us. It totally contradicted to our coding experiences about the method since LoadFamilySymbol came out. To make things clear, we have done a couple of tiny experiments and verified the first signature of the LoadFamilySymbol method works just fine.

In this post, let’s take once again a few minutes to do a tiny experiment to prove he was wrong again about the second signature of the LoadFamilySymbol method.

using (Transaction tran2 = new Transaction(CachedDoc, "LoadFamilySymbolTest2"))
{
    tran2.Start();

    string libPath = CachedDoc.Application.GetLibraryPaths()["Imperial Library"];
    string rfaFullName = Path.Combine(libPath, @"Columns\Doric Column.rfa");

    FamilySymbol symbol1;
    bool success1 = CachedDoc.LoadFamilySymbol(rfaFullName, "16'  Height (10 2/3 x Dia.)", out symbol1);

    string msg1 = string.Format("Symbol #1 has {0} been loaded into the current project.\n", success1 && symbol1 != null ? "" : "NOT");

    MessageBox.Show(msg1);

    tran2.Commit();
}

Before the code is run, our test Revit model only has a couple of default architectural Rectangular Columns as shown below:
 LoadFamily2Before

After the code is run, the following message box should show up telling us everything is just fine!
 LoadFamilySuccessfully

And, we can check the model to find that the specified column symbol of the Doric Column family has been successfully loaded into the current document by the LoadFamilySymbol call and is available to use right way as shown clearly again below.
 LoadFamily2After

Again, what might be exactly going wrong then?!

By the way, he said the third signature of the LoadFamilySymbol method should work, but we can reasonably doubt how he reached that. Did he really write some real code to test it carefully himself? No review process at all either?!

We knew that signature of the method LoadFamilySymbol does work from our own coding experience. We finally got something that we do not have to bother to verify. Phew!


Viewing all articles
Browse latest Browse all 872

Trending Articles