Loading families with nested elements

Loading families with nested elements

Anonymous
Not applicable
1,368 Views
4 Replies
Message 1 of 5

Loading families with nested elements

Anonymous
Not applicable

I am trying to load families into a document with a macro. It appears that if I attempt to load a family with a nested family inside it, and that nested family is already loaded into the project, it will fail. Has anyone else noticed this? Is there a way around it? Thanks.

0 Likes
1,369 Views
4 Replies
Replies (4)
Message 2 of 5

MarryTookMyCoffe
Collaborator
Collaborator

did you try to load it manually with the UI?
I load lots of families and I never had problem with it. Almost all my families are nested, some even with 12 layers. If families are already loaded it should  make actualisation.
What kid error appear?

 

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 3 of 5

matthew_taylor
Advisor
Advisor

Hi @Anonymous,

If the family in document is shared, and the nested family is not (or vice-versa), then the load will fail (as it would if you did it manually).

That's probably where @MarryTookMyCoffe is coming from.

Otherwise, show us code. Are you implementing IFamilyLoadOptions?

 

 


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?
0 Likes
Message 4 of 5

Anonymous
Not applicable

The family (in this example) is a table with a support. The supports are nested in the family. There are several different families to load which are variations of this table (round, handicap accessible, etc.). The table support nested in the family is shared, but the table family itself is not.

 

I've found by attempting to load manually that if the dialog box "Shared Family Already Exists" pops up when loading, that also seems to be the place where the script fails. Conversely, if I load tables manually and that dialog does not pop up, then the script works as well. The minute I have a family where that dialog would occur, the script fails, which leads me to believe that it is the source of the problem.

 

If I manually unload the support family in the script before attempting to load the tables, it also works. I would rather not hard code in families to remove for obvious reasons. If there is a way to check what families exist in a family and then unload them, that would be preferred, but I can't figure out how to do that.

 

The code is below. It is checking a specific parameter 'portfolio' in the types to see if it contains a specified value:

 

public void LoadFamilies(string dirpath)
{
Document doc = this.Document;

// this is the portfolio name
String portfolio_name = @"Origin Classic-Core";
// we want anything that is for all templates too
String all_templates = "<All Templates>";

string[] files = Directory.GetFiles(dirpath, "*.rfa");

// step through the list and load the families one by one
foreach (string familyfile in files) {
Family fam = null;

Transaction trans = new Transaction(doc, "Checking Family for Types");
trans.Start();
doc.LoadFamily(familyfile, out fam); // load the family and its types

// use ids to get all the types for the family
ISet<ElementId> symbolIds = fam.GetFamilySymbolIds();

// family types to load
List<String> typesToLoad = new List<String>();

// iterate through the types and check for Portfolio parameter.
foreach (ElementId id in symbolIds) {
bool hasPortfolio = false;
// retrieve the type symbol
Element symbol = doc.GetElement(id);
// check for 'Portfolio' value
foreach (Parameter para in symbol.Parameters) {
switch (para.Definition.Name) {
case "Portfolio":
string defValue = GetParameterInformation(para, doc);
if ( (defValue.Equals(portfolio_name)) || (defValue.Equals(all_templates)) ) {
typesToLoad.Add(symbol.Name);
} //if
hasPortfolio = true;
break;
default:
break;
}
} //foreach
if (hasPortfolio == false) {
typesToLoad.Add(symbol.Name);
}
} //foreach
trans.RollBack(); // don't load the entire family!

// Now load only family types we want for this portfolio
// if there is a 'Portfolio' parameter and some items match our criteria, i.e. the list has elements in it
using (Transaction transNew = new Transaction(doc)) {
transNew.Start("Load Types");
if ( (typesToLoad != null) && (typesToLoad.Any()) ) {
foreach (String symbol in typesToLoad) {
doc.LoadFamilySymbol(familyfile, symbol);
} //foreach
} //if
transNew.Commit();
}
} //iterate through list of families in directory
} //LoadFamilies

0 Likes
Message 5 of 5

matthew_taylor
Advisor
Advisor

Hi @Anonymous,

You are best to either have one copy of each family, and have them shared if necessary.

If you have a shared and a non-shared family legacy issue, then I suggest renaming one of them (in a standard way), so that the loading clash doesn't happen.

There's no easier workaround (that I can think of).

You can check if a loaded family is shared by checking the value of the Family_Shared builtinparameter.

 


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?
0 Likes