NewAlignment to align family instance reference plane with reference line

NewAlignment to align family instance reference plane with reference line

aditazz
Contributor Contributor
2,509 Views
2 Replies
Message 1 of 3

NewAlignment to align family instance reference plane with reference line

aditazz
Contributor
Contributor

I am using Revit 2016 API to create a family with nest family instance. I want to align inserted family instance with a reference line but getting the error message below.

 

Autodesk.Revit.Exceptions.ArgumentException was unhandled by user code
HResult=-2146233088
Message=One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument.

 

Below is the code to call NewAlignment.

{
	...

	ModelCurve line3 = MakeLine(document, new XYZ(10, 10, 0), new XYZ(5, 15, 0));
	line3.ChangeToReferenceLine();

	Reference refPlaneLeft = GetFamilyInstanceLeftReferencePlane(viewPlan, familyInstance);
	if (refPlaneLeft != null)
	{
		Dimension alignToLine3 = document.FamilyCreate.NewAlignment(viewPlan, line3.GeometryCurve.Reference, refPlaneLeft);
		alignToLine3.IsLocked = true;
	}

	...
}

private Reference GetFamilyInstanceLeftReferencePlane(
    View view, 
    FamilyInstance fi)
{
    Reference referenceLeft = null;

    Options opt = new Options();
    opt.ComputeReferences = true;
    opt.IncludeNonVisibleObjects = true;
    if (view != null)
        opt.View = view;

    double minX = double.MaxValue;

    GeometryElement ge = fi.get_Geometry(_opt);
    if (ge != null)
    {
        foreach (GeometryObject go in ge)
        {
            if (go is GeometryInstance)
            {
                GeometryInstance gi = go as GeometryInstance;
                foreach (GeometryObject goSymbol in gi.GetSymbolGeometry())
                {
                    if (goSymbol is Line)
                    {
                        Line refPlane = goSymbol as Line;
                        if (refPlane.Direction.IsAlmostEqualTo(new XYZ(0, 1, 0)) || refPlane.Direction.IsAlmostEqualTo(new XYZ(0, -1, 0)))
                        {
                            if (refPlane.GetEndPoint(0).X < minX)
                            {
                                minX = refPlane.GetEndPoint(0).X;
                                referenceLeft = refPlane.Reference;
                            }
                        }
                    }
                }
            }
        }
    }

	return referenceLeft;
}

 

Does GetFamilyInstanceLeftReferencePlane() not get the correct Reference of FamilyInstance's ReferencePlane? Or, is there a better way to align FamilyInstance to a reference line?

 

Thanks

0 Likes
Accepted solutions (1)
2,510 Views
2 Replies
Replies (2)
Message 2 of 3

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Hi aditazz, the documentation says:
"These references must be already geometrically aligned (this function will not force them to become aligned)."

that means we have to move those 2 references together before calling NewAlignment,

can you check if that is the reason of the exceptions?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 3

sonicer
Collaborator
Collaborator

can you send the final code?

thx.

0 Likes