
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Solved! Go to Solution.