create family instance with parametric angle

create family instance with parametric angle

m.walterN99B3
Contributor Contributor
77 Views
2 Replies
Message 1 of 3

create family instance with parametric angle

m.walterN99B3
Contributor
Contributor

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.

 

!frage forum.png

 

 

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?

 

0 Likes
78 Views
2 Replies
Replies (2)
Message 2 of 3

Mohamed_Arshad
Advisor
Advisor

Hi @m.walterN99B3 

 

Kindly share the Family File with Generic Model attached so that will work on the issue.


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 3

m.walterN99B3
Contributor
Contributor

I attached the test.zip containing the complete code and the two needed files.

0 Likes