Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Nested family read bug

Anonymous

Nested family read bug

Anonymous
Not applicable

If the family A contains the same name of the sub-family A, B, C; the family D contains the same name of the sub-family D, E, F, then editing the family will be confused.

 

1) If the name of A is modified, then B will not be able to read the sub-family and save it as another The program will enter an infinite loop and cannot exit;

 

2) If you do not modify any family name, the program will directly enter an infinite loop, or even crash;

 

3) Check the same name, skip, and enter an infinite loop or even crash

 

Full of all kinds of unexplainable internal bizarre problems!!!!!!

 

NOTE: <Tom.FamilyTree.zip> don't include any my dlls, you could find them by another zip, install it, get them.

I want to upload large zip file, but network is very slow.

 

Sometime, Revit API don't give you any help, you rename family manually(maybe cannot get child families by API, if parent family and child family are same name) and restart revit.

 

In a word, nested families cannot have the same name, otherwise everything will be accompanied by uncertainty!!!

Revit Version: 2021

0 Likes
Reply
Accepted solutions (1)
358 Views
2 Replies
Replies (2)

jeremy_tammik
Autodesk
Autodesk

> If the family A contains the same name of the sub-family A, B, C; the family D contains the same name of the sub-family D, E, F, then editing the family will be confused.

 

Not only editing is confused; I am confused too.

 

> In a word, nested families cannot have the same name, otherwise everything will be accompanied by uncertainty!

 

Yes, for sure.

 

Afaik, you cannot have different families with the same name loaded into a single project. At least, I would strongly recommend to avoid trying to do that.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Anonymous
Not applicable
Accepted solution

Yes. Show the full path of family node to user, user must rename to fix the problem. 🙂

 

By the way, I closed all exception setting, stack exception don't show. 😅

 

The follow method is a solution, it could find <FamilyA/FamilyA> problem.

```

private static bool CheckFamilyName(TreeNode node)
{
var paths = node.FullPath.Split(new[] { @"\" }, RemoveEmptyEntries);

if (paths.Distinct().Count() == paths.Length)
return false;

// Find A/A; B/B to tell user and should rename manually!
node.FullPath.ShowRevitDialog();

return true;
}

 

private void ReadFamilyTree(Document parentDoc, TreeNode parentNode, bool export = false)
{
var families = parentDoc.OfClass<Family>().OfType<Family>();

foreach (var family in families)
{
if (family.FamilyCategory is null)
continue;

if (family.FamilyCategory.CategoryType == CategoryType.Annotation)
continue;

if (!family.IsEditable)
continue;

TryAction(() =>
{
var node = new TreeNode(family.Name);

// It's for 'node.FullPath'
parentNode.Nodes.Add(node);

if (CheckFamilyName(node))
return;

var fdoc = parentDoc.EditFamily(family);

if (export)
{
var familyPath = Path.Combine(_rootDirPath, node.FullPath) + Res_Type_Rfa;
var familyDirPath = Path.GetDirectoryName(familyPath);

if (!Directory.Exists(familyDirPath))
Directory.CreateDirectory(familyDirPath);

if (File.Exists(familyPath))
File.Delete(familyPath);

fdoc.SaveAs(familyPath);
}

Application.DoEvents();
_progress.UpdateProgress(++_completedNum, family.Name);

ReadFamilyTree(fdoc, node, export);
fdoc.Close(false);
}, true);
}
}

```

 

If you want to get full code, please download demo code.

 

 

0 Likes