Sometimes its not your code (try a different Revit version)

An API developer asked why this code didn’t work to place a face-based family instance on a face in an RVT Link.

public void PlaceFaceBasedFamilyinLink()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    
    ReferenceIntersector ri = new ReferenceIntersector((View3D)doc.ActiveView);
    ri.FindReferencesInRevitLinks = true;
    Reference r = ri.FindNearest(XYZ.Zero,XYZ.BasisZ.Negate()).GetReference();

    Family fam = new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>().FirstOrDefault(q => q.Name == "Family2");
    
    using (Transaction t = new Transaction(doc,"place instance"))
    {
        t.Start();
        doc.Create.NewFamilyInstance(r, r.GlobalPoint, XYZ.BasisY, fam.Symbols.Cast<FamilySymbol>().First());
        t.Commit();
    }        
}

After investigating for a while in 2014 and wondering why this error occurred:

Capture

I decided to try the same code in 2015 where I found it to work just fine. This doesn’t help me get it working if I need a Revit 2014 solution, but at least it lets me stop spending time looking for a problem in my code that doesn’t exist.

Advertisements

6 thoughts on “Sometimes its not your code (try a different Revit version)

  1. Hi,
    Is it possible and I haven’t had any success trying so far, to find a room using ray projection from a wall/ curtain wall that is a bounding wall on the room’s perimeter?
    Here is the code that I have attempted to use.
    ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Rooms);
    ReferenceIntersector refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.Element, view3d);
    ReferenceWithContext referenceWithContext = refIntersector.FindNearest(CurtainWallcurveCenter, wallorientation);

    • Hi Nik,

      The documentation for ReferenceIntersector says: An instance of this class can be constructed to return any 3D geometric element that intersects the ray created by the origin and direction

      I don’t think rooms are considered a “3D geometric element” so will not be found. But there may be other ways to accomplish your goal. What are you trying to do?

      Harry

      • Hi Harry,
        I thought so, It would have been the easy method however.
        So what I am trying to get the room as an element on the inside of a curtainWall wall that is on the rooms perimeter. My next attempt will be to use the wall orientation property and do a transform/ translation of the CW’s bounding box into the room on the interior side of the CW. unless you know an easier method?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s