NewFamilyInstance Exception - Failed to create family instance on face

NewFamilyInstance Exception - Failed to create family instance on face

Sam_sippeQYA97
Explorer Explorer
1,078 Views
6 Replies
Message 1 of 7

NewFamilyInstance Exception - Failed to create family instance on face

Sam_sippeQYA97
Explorer
Explorer

Hi,

 

I'm getting a

 

Autodesk.Revit.Exceptions.InvalidOperationException: 'Failed to create family instance on face.'

 

...exception on this line...

 

var instance = doc.Create.NewFamilyInstance(face, insertLine, symbol);

 

The NewFamilyInstance call works successfully for one project but not the other. Any ideas what could be going wrong?

0 Likes
Accepted solutions (1)
1,079 Views
6 Replies
Replies (6)
Message 2 of 7

Moustafa_K
Collaborator
Collaborator

hard to tell with the given information, things to cross check

  1. the family you are using is WorkPlaneBased or CurveBased.
  2. the face is valid
  3. the line is correctly placed on face area.
  4. the symbol is active symbol

list can go longer.... try the above and if failed, send a sample of your code, may be we can be able to help

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 7

Sam_sippeQYA97
Explorer
Explorer

Hi Moustafa, 

 

Thanks for your help! Answers below.

 

1. CurveBased

 

2. Face is {Autodesk.Revit.DB.PlanarFace} with FaceNormal = {(0.000000000, -1.000000000, 0.000000000)}.  Is that valid?

 

3. insertLine.Direction = {(1.000000000, 0.000000000, 0.000000000)}, insertLine.Origin = {(-7.256397638, -2.739501312, 8.738845144)}, insertLine.Length = 4.1781496062992129. Is that correctly placed?

 

4. Symbol.IsActive==true

 

I'll get a code example together if you think that would help.

0 Likes
Message 4 of 7

Moustafa_K
Collaborator
Collaborator

not clear enough, if the  face location and line are aligned. have you tried the sample over here with your variables?, if it didn't work then probably there is something wrong with your inputs, and if it did work, then something in your code that needs to be reviewed thoroughly . 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 5 of 7

scgq425
Advocate
Advocate

Hi @Sam_sippeQYA97 :

May Be The IntersectLine is offset of the face , u can change the code , and used `PickObject` to select face and point to create u target instance , and then debug u code .

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 6 of 7

Sam_sippeQYA97
Explorer
Explorer
Accepted solution

Firstly, thanks for the help. I really appreciate it. I've spent a bunch of time on this, going down multiple rabbit holes and all your suggestions were very valuable.

 

I managed to find a workaround the problem which involved updating the family I was using as a source of the face parameter of the NewFamilyInstance call. The famly is concrete core represented by an extruded shape of roughly 10m x 10m. I noticed that the core family origin point was > 100m from the shape. If I moved the shape closer to the origin and ran the code again, it would run fine. This workaround worked on a serval different concrete core families without any changes to the code. If I had to guess, there's some kind of rounding issue that causes an issue when the face is a long way from the family origin. This was interesting but not something I could use in my code.

 

The fix I eventually landed on works like this:

* create a new temporary BuiltInCategory.OST_Walls wall that runs along the path of the line

* doc.Regenerate()  

* get the PlanarFaces from the wall

* choose the planarFace where planarFace.FaceNormal that matches the normal we need for the line

doc.Create.NewFamilyInstance(face, insertLine, symbol)

* delete the wall

It seems solid in my testing so far. 

 

In hindsight, it seems a pretty obvious solution. I'm a bit annoyed for not trying it earlier. If anyone is interested I can provide more details.

 

Cheers!

 

 

 

 

0 Likes
Message 7 of 7

Dean.kichenbrand
Contributor
Contributor

Good Day,

 

I'm having difficulty creating a line based family instance on the geometry of a curtain panel, On a wall it works perfectly. 

I have tried using geometry from symbol and instance with no luck. If posable could you anyone please provide code that is able to draw a line based family on the front face of the curtain wall using the face edge for the line.

 

Thank You.

 

 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection selection = uidoc.Selection;
var app = commandData.Application;

using (Transaction tx = new Transaction(doc, "Place Family"))
{
tx.Start();

// Get face and ensure it has references
Reference faceRef = selection.PickObject(ObjectType.Face, "Select a face");

// Get edge
Reference edgeRef = selection.PickObject(ObjectType.Edge, "Select an edge");
Element edgeElem = doc.GetElement(edgeRef);
Edge edge = edgeElem.GetGeometryObjectFromReference(edgeRef) as Edge;
Line line = edge.AsCurve() as Line;

var symbol = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_StructuralStiffener)
.WhereElementIsElementType()
.First() as FamilySymbol;

doc.Create.NewFamilyInstance(faceRef, line, symbol);

tx.Commit();
}

return Result.Succeeded;
}

0 Likes