0

I'm trying to insert a face-hosted family that contains a void extrusion inside a generic specialty equipment family. The scenario is the following:

  • In the "parent" family there is a rectangular extrusion placed with Z = 100 mm and height = 40mm; the extrusion is created programmatically

  • I've a .rfa with a simple void cylinder. This rfa is a Generic model family and I've set "Cut with voids" to true

  • I want to insert an instance of this void family inside the parent family in order to pierce the extrusion.

The code I'm using is the following:

        Options opt = _commandData.Application.Application.Create.NewGeo​metryOptions();
        opt.ComputeReferences = true;
        var geo = shelf.get_Geometry(opt);//shelf is the extrusion
//location = 0,-800,100
//width = 1000
//depth = 800
//height = 140
//all measures are mm
        PlanarFace pf = null;
        foreach (GeometryObject obj in geo)
        {
            Solid solid = obj as Solid;

            if (null != solid)
            {
                foreach (Face face in solid.Faces)
                {
                    pf = face as PlanarFace;
                    if (null != pf)
                    {
                        XYZ normal = pf.Normal.Normalize();
                        if (0.0 < normal.Z && normal.X < 1 && normal.Y < 1)
                        {
                            break;
                        }
                    }
                }
            }
        }
        if (pf != null)
        {
            var location = new XYZ(50D.ToRevitMeasure(), -100D.ToRevitMeasure(), 140D.ToRevitMeasure());
            var referenceDirection = XYZ.BasisX;
            FamilySymbol symbol = null;
            RevitBaseUtilities.DoSomethingInsideTransaction(() => familyDocument.LoadFamilySymbol(holeFileName, Path.GetFileNameWithoutExtension(holeFileName),
                                                                                                  new FamilyLoadingDontOverwriteOption(), out symbol), familyDocument);


            FamilyInstance inst;
            RevitBaseUtilities.DoSomethingInsideTransaction(() => inst = familyDocument.FamilyCreate.NewFamilyInstance(pf, location, referenceDirection , symbol), familyDocument);

            familyDocument.SaveAs(resultFileName);
            familyDocument.Close(false);

The problem is that the cylinder is always placed in Z=0. I can send the hole family and the result project if necessary.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69

1 Answers1

0

If i'm understand what you're doing correctly, you may want to use the GlobalPoint property inherited from Reference/Element instead of the PlanarFace.Normal item. Or at least include it in your implementation so you're also grabbing the XYZ of the items you're referencing.

prestonsmith
  • 758
  • 1
  • 9
  • 29
  • I'm using the normal only to know if the actual face is the right face where I need to put my hosted family. The right face is the top face of an extrusion so it have the normal as (0,0,1) or (0,0,-1). Where should I use GlobalPoint? – Tobia Zambon Jul 18 '14 at 06:46
  • hmm, and is the foreach implementation you're using now, returning the correct face, just out of curiosity? The Global Point should be used wherever you're trying to get a location back from an element - in short, if you want to click somewhere on the object and have it land in that spot - use a Reference to grab the SelectionPoint, and then you can use the GlobalPoint property to get the exact XYZ of that point. – prestonsmith Jul 18 '14 at 10:38
  • Yes it is giving the right face I suppose..The nested family is face-hosted so the globalPoint is not useful here – Tobia Zambon Jul 28 '14 at 07:19