how to get the reference of a PlanarFace

how to get the reference of a PlanarFace

Anonymous
Not applicable
3,133 Views
2 Replies
Message 1 of 3

how to get the reference of a PlanarFace

Anonymous
Not applicable

hello,I'm a beginer of Revit API and I'm learning how to use API to make families.

 

I want to use  the method NewAlignment, which need the reference of two planes. I've got one of the reference of a ReferencePlane via the method "referencePlane.GetReference()", while I can't get the reference of a  PlanarFace via "planarFace.Reference", it seems that there is no reference of the planarFace at all.(because a System.NullReferenceException occured ).

 

here are my  codes:

 

 void addAligments(Extrusion pBox,Document doc)
    {
        View pView = findElement(typeof(View), "Front",doc) as View;
        Level upperLevel1 = findElement(typeof(Level), "Upper Ref Level",doc) as Level;
        Reference ref1 = upperLevel1.GetPlaneReference(); ;
        PlanarFace upperFace = findFace(pBox,new XYZ(0.0,0.0,1.0),null);
        Reference ref2 = upperFace.Reference;
        doc.FamilyCreate.NewAlignment(pView, ref1, ref2);

        Level lowlLevel1 = findElement(typeof(Level), "Lower Ref. Level", doc) as Level;
        Reference ref3 = lowlLevel1.GetPlaneReference();
        PlanarFace lowerFace = findFace(pBox, new XYZ(0.0, 0.0, -1.0),null);
        Reference ref4 = lowerFace.Reference;
        doc.FamilyCreate.NewAlignment(pView, ref3, ref4);
        View pViewPlan = findElement(typeof(ViewPlan), "Lower Ref. Level",doc) as View;
        ReferencePlane refRight = findElement(typeof(ReferencePlane), "Right",doc) as ReferencePlane;
        ReferencePlane refLeft = findElement(typeof(ReferencePlane), "Left",doc) as ReferencePlane;
        ReferencePlane refFront = findElement(typeof(ReferencePlane), "Front",doc) as ReferencePlane;
        ReferencePlane refBack = findElement(typeof(ReferencePlane), "Back",doc) as ReferencePlane;
        ReferencePlane refOffsetV = findElement(typeof(ReferencePlane), "OffsetV",doc) as ReferencePlane;
        ReferencePlane refOffsetH = findElement(typeof(ReferencePlane), "OffsetH",doc) as ReferencePlane;
        PlanarFace faceRight = findFace(pBox, new XYZ(1.0, 0.0, 0.0), refRight);
        PlanarFace faceLeft = findFace(pBox, new XYZ(-1.0, 0.0, 0.0),null);
        PlanarFace faceFront = findFace(pBox, new XYZ(0.0, -1.0, 0.0),null);
        PlanarFace faceBack = findFace(pBox, new XYZ(0.0, 1.0, 0.0), refBack);
        PlanarFace faceOffsetV = findFace(pBox, new XYZ(1.0, 0.0, 0.0), refOffsetV);
        PlanarFace faceOffsetH = findFace(pBox, new XYZ(0.0, 1.0, 0.0), refOffsetH);
        doc.FamilyCreate.NewAlignment(pViewPlan, refRight.GetReference(),faceRight.Reference);
        doc.FamilyCreate.NewAlignment(pViewPlan, refLeft.GetReference(),faceLeft.Reference);
        doc.FamilyCreate.NewAlignment(pViewPlan, refFront.GetReference(),faceFront.Reference);
        doc.FamilyCreate.NewAlignment(pViewPlan, refBack.GetReference(),faceBack.Reference);
        doc.FamilyCreate.NewAlignment(pViewPlan, refOffsetV.GetReference(),faceOffsetV.Reference);
        doc.FamilyCreate.NewAlignment(pViewPlan, refOffsetH.GetReference(),faceOffsetH.Reference);
    }

 

Thank you for your help.

 

 

 

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

Anonymous
Not applicable
Accepted solution

Are you setting  ComputeReferences  = true in the GeometryOptions object you are using to extract the faces?

Also, when passing face references to dimensions  and alignments you need to use the references extracted from symbol geometry not instance geometry.

Message 3 of 3

Anonymous
Not applicable
thank you, I make it.
0 Likes