Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create a family (it's "Face-based"), but I get the following error
Failed to create family instance on face.
в ?A0xf5bdfe27.FamilyInstance_create(ADocument* pADoc, ElementId symbolId, Pick* pPick, XYZ* refPoint, XYZ* refDir, ElementId levelId, Boolean doRegenerate)
в ?A0xf5bdfe27.newFamilyInstance(Document doc, Reference reference, XYZ location, XYZ direction, FamilySymbol symbol)
The code is shown below.
TS - is a wrapper over a Transaction,
doc.DrawLine() - extension-method for drawing model lines
var doc = commandData.GetDoc();
TS.Create(doc);
TS.Start();
XYZ point1 = new XYZ(3,3,3); // Первая точка (центр грани)
XYZ point2 = point1 + XYZ.BasisX.Normalize(); // Вторая точка (смещение по X)
XYZ point3 = point1 + XYZ.BasisY.Normalize(); // Третья точка (смещение по Y)
// Проверяем неколлинеарность
XYZ vec1 = point2 - point1;
XYZ vec2 = point3 - point1;
XYZ normal = vec1.CrossProduct(vec2).Normalize();
if (normal.IsZeroLength())
{
throw new InvalidOperationException("Точки лежат на одной прямой, невозможно создать плоскость.");
}
// 2. Создаём геометрическую плоскость
Plane plane = Plane.CreateByThreePoints(point1, point2, point3);
// 3. Создаём SketchPlane
SketchPlane sketchPlane = SketchPlane.Create(doc, plane);
// 4. Рисуем линии для отладки
doc.DrawLine(point1, point2);
doc.DrawLine(point1, point3);
doc.DrawLine(point1, point1 + normal * 5.0);
// 7. Размещаем семейство
FamilyInstance instance = doc.Create.NewFamilyInstance(
sketchPlane.GetPlaneReference(), // Ссылка на плоскость
point1, // Точка размещения
normal, // Ось ориентации
doc.GetFamilySymbol("Placer_OST_MechanicalEquipment", "Placer_OST_MechanicalEquipment") // Символ семейства
);
TS.Commit();
Can anyone tell me how to do this correctly? I need to create a family on an axial plane created by three points:
1. Origin
2. Forward,
3. Right or Up
Thank you!
Solved! Go to Solution.