create family instance with parametric angle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'd like to embed a generic model into a window family.
An angle parameter of the window family (host) shall rotate the generic model instance.
But my problem is that the generic model instance does not rotate. ("Always vertical" is off)
It seem to be bound for translations, but not for rotations.
here is what I do:
I create with the API two reference lines and an angle parameter.
Then I add an angular dimension between the two reference lines und bind the parameter to it.
Now the reference line is parametric und rotates according to the parameter.
Then I insert the generic model instance with the reference line as host.
In addition I bind the family instance to the reference line using NewAlignment.
However, the generic model does not rotate with the reference line.
My actual code is:
ModelLine modelLineStart = CreateReferenceLine(docFamily, sketchPlane, pointProjectedStart, pointProjectedEnd);
ModelLine modelLineMid = CreateReferenceLine(docFamily, sketchPlane, pointProjectedStart, pointRotatedMid);
ModelLine modelLineParametric= CreateReference(docFamily, sketchPlane, pointProjectedStart, pointRotatedEnd);
bool bNewAlignment1 = CreateNewAlignment(docFamily, viewFloorPlan, modelLineStart.GeometryCurve.GetEndPointReference(0), insertionPlane.GetReference());
bool bNewAlignment2 = CreateNewAlignment(docFamily, viewFloorPlan, modelLineStart.GeometryCurve.GetEndPointReference(1), insertionPlane.GetReference());
bool bNewAlignment3 = CreateNewAlignment(docFamily, viewFloorPlan, modelLineParametric.GeometryCurve.GetEndPointReference(0), insertionPlane.GetReference());
bool bResultDimension = CreateAngularDimension(docFamily, viewFloorPlan, modelLineStart, modelLineMid, modelLineParametric, sParameterName);
// load generic model family to Revit family
Family familyGenericModel = LoadFamily(docFamily, sFileGenericModel);
if (familyGenericModel == null)
{
return Result.Failed;
}
// determine the family symbol - there is only one in the document
FamilySymbol familySymbol = CalcFirstFamilySymbol(docFamily, familyGenericModel);
if (familySymbol == null)
{
return Result.Failed;
}
// insert family instance
using (Transaction transaction = new Transaction(docFamily))
{
if (transaction.Start("set param") == TransactionStatus.Started)
{
// activate symbol if needed
ActivateSymbol(familySymbol);
// set angle to 0
SetParameterDouble(docFamily.FamilyManager, sParameterName, 0.0);
docFamily.Regenerate();
transaction.Commit();
}
}
FamilyInstance familyInstance = null;
using (Transaction transaction = new Transaction(docFamily))
{
if (transaction.Start("insert instance") == TransactionStatus.Started)
{
Element host = modelLineParametric;
XYZ location = modelLineParametric.GeometryCurve.GetEndPoint(0);
XYZ direction = modelLineParametric.GeometryCurve.GetEndPoint(1) - modelLineParametric.GeometryCurve.GetEndPoint(0);
Autodesk.Revit.DB.Structure.StructuralType structuralType)
familyInstance = docFamily.FamilyCreate.NewFamilyInstance(location, familySymbol, direction, host, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
transaction.Commit();
}
}
// calc reference of family instance
IList<Reference> references = familyInstance.GetReferences(FamilyInstanceReferenceType.CenterFrontBack);
Reference familyInstanceReference = references.First();
using (Transaction transaction = new Transaction(docFamily))
{
if (transaction.Start("align") == TransactionStatus.Started)
{
Dimension dimension = docFamily.FamilyCreate.NewAlignment(viewFloorPlan, familyInstanceReference, modelLineParametric.GeometryCurve.Reference);
dimension.IsLocked = true;
transaction.Commit();
}
}
I have also tried all other overloads of NewFamilyInstance.
But the generic model does not rotate.
Does anyone have any ideas please?