Create window element

Create window element

stav1233
Explorer Explorer
1,301 Views
4 Replies
Message 1 of 5

Create window element

stav1233
Explorer
Explorer

Hey everyone,

I am trying to create a new window instance using

doc.Create.NewFamilyInstance(XYZ, FamilySymbol, HostElement, StructuralType.NonStructural);

After I run the command the window is created but I can’t see it on the module.

I try to lock for the reason using vlookup and I suspect the reason is the new window instance

levelid Element properties is null,

host FamilyInstance properties is null,

host face FamilyInstance properties is null,

Any suggestion?

 

 

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

jeremy_tammik
Alumni
Alumni

A newly loaded family symbol needs to be activated before it can be used:

 

http://thebuildingcoder.typepad.com/blog/2014/08/activate-your-family-symbol-before-using-it.html

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

stav1233
Explorer
Explorer

I activate the family symbol but its steal not work.

any more suggestion?

0 Likes
Message 4 of 5

jeremy_tammik
Alumni
Alumni

Work through the process step by step in the end user interface. Does it work as expected there?

 

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

caroline.gitonga
Autodesk
Autodesk

Hi @stav1233

As per @jeremy_tammik response above, I have checked and solved the same issue you have using Activate Family Symbol article.
Family Symbols require to be activated for them to be loaded into the document. You should check whether the symbol is active once the transaction starts or right before the transaction commits. Once it is activated the document re/generates it and it gets loaded. If the symbol is inactive, Revit gives you this exception (attached below). See my code snippet of how you can implement the solution provide on @jeremy_tammik article.

// Find a Window type for the new windows
FilteredElementCollector winCollector = new FilteredElementCollector(document);
IList<Element> windowTypes = winCollector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsElementType().ToElements();
FamilySymbol winType = windowTypes.First() as FamilySymbol;

//Level level = myWall.Document.GetElement(myWall.LevelId) as Level;
//XYZ location = new XYZ(-22.6724094227806, 45.595454156592, 3.00196850393702);
double x =2 , y =2, z =2;
//inserts 3 windows
for(int i = 0; i < 3; i++)
{
XYZ location = new XYZ(x, y, z);

Transaction trans = new Transaction(document);
trans.Start("window instance");
//check whether the family symbol is active, if not activate and regenerate
if (!winType.IsActive)
{
winType.Activate();
document.Regenerate();
}

FamilyInstance instance = document.Create.NewFamilyInstance(location, winType, myWall, StructuralType.NonStructural);
x += 3;
y += 3;
trans.Commit();

}

 

Carol Gitonga, Developer Advocacy and Support, ADN Open