family instance on reference plane with API

family instance on reference plane with API

mononull
Contributor Contributor
7,111 Views
25 Replies
Message 1 of 26

family instance on reference plane with API

mononull
Contributor
Contributor

Trying to place a family instance of electrical fixture onto a reference plane with Revit 2013 API.  I get the following ArgumentsInconsistentException "Reference direction is parallel to face normal at insertion point.", "Parameter name: multiple".  

using (Transaction trans = new Transaction(Doc, "TEST"))
{
    trans.Start();
XYZ bubbleEnd = new XYZ(5, 0, 0); XYZ freeEnd = new XYZ(-5, 0, 0);
XYZ cutVec = new XYZ(0, 0, 1);

ReferencePlane plane1 = Doc.Create.NewReferencePlane(bubbleEnd, freeEnd,
cutVec, Doc.activeView) //floor plan, top-down view

XYZ refDir = new XYZ(0, 0, -1);
FamilySymbol fs = new FilteredElementCollector(Doc)..yada..get duplex receptacle familysymbol

FamilyInstance fi = Doc.Create.NewFamilyInstance(plane1.Reference, XYZ.Zero, refDir, fs);

trans.Commit(); }

 

The reference plane drawn is a vertical reference plane stretching length-wise along the world x-axis and height-wise along the world z-axis.  If I were to add a receptacle using the revit interface it would connect on the -y face of the reference plane...the underside of the plane if looking down on the floor plan.  I've tried every possible reference direction for the newfamilyinstance in the code.  I tried refDir as positive and negative for each X, Y, and Z axis...and not one reference direction worked.  I also made an exact replica command as Jeremy's post here... http://thebuildingcoder.typepad.com/blog/2012/02/hosting-a-light-fitting-on-a-reference-plane.html and nothing worked here either.  Always the same above-mentioned exception.  

 

Any help is appreciated.

0 Likes
7,112 Views
25 Replies
Replies (25)
Message 21 of 26

BardiaJahan
Advocate
Advocate

@Anonymous

Try projecting the location point on the face and use the projected point for placing the fixture.

0 Likes
Message 22 of 26

tf
Contributor
Contributor

@FAIR59

 

Thanks for your reply.  We tried this and we get the same results.  One one side of the interior wall it is correct on the other it is flipped.  If we flip the wall it reverses the problem.  See image.  The Red device is correct.  The Blue is flipped.  We think the prior code you provide is close but we are having a hard time finding a test to select the correct solid face.  Basically we need a Normal to test against but haven't found a good way of calculating this.  We are trying the vector from the center of the wall to the center of the face which gives the general direction but not exact enough for the test.

 

Capture.JPG

0 Likes
Message 23 of 26

tf
Contributor
Contributor

@FAIR59

Testing the solid faces is working for us.  We calculate the normal of the solid.  Then Created a point (PT) by Adding the normal to the solid Face center and used Space.IsPointInSpace(PT) as the test.

Hope this will work in all instances.

Thanks for all your help.

 

0 Likes
Message 24 of 26

tf
Contributor
Contributor

@FAIR59

 

The code you provided below is working well for us.  

 

Options opt = new Options();

opt.ComputeReferences =true;

opt.DetailLevel = ViewDetailLevel.Coarse;

GeometryElement geoElem = element.get_Geometry(opt);

foreach (Autodesk.Revit.DB.GeometryObject geomObj in geoElem)

 

 

Do you know if this can be used to retrieve faces from a linked file.  I don't see where it takes the document into account.  

Thank you!

0 Likes
Message 25 of 26

FAIR59
Advisor
Advisor

@tf

 

You can use your code on an element in a linked file, the problem will be to get the Element.

Any spatial result will be in the coordinate system of the linked file.

 

work-flow:

 

  • find Linked Instance
  • get Linked Document
  • find a cq all Wall(s) in the Linked Document
  • find spatial information
  • transform coordinates to Document coordinate system , via LinkedInstance. GetTotalTransform()

Hope this helps

 

Message 26 of 26

tf
Contributor
Contributor

Thanks for the reply.  Revit it designed for linked documents but makes it very difficult to traverse.

 

0 Likes