Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to place a face base family at column?

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
659 Views, 5 Replies

How to place a face base family at column?

place a face base family at  wall  or  beam  is OK, but at column is wrong.

 

My location xyz is right,  but...333.jpg

 

 

 

 

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

        private static void CreateInstancesOnHostFamilyFaces(FamilySymbol familySymbol, FamilyInstance hostInstance)
        {
            var faces = GetSolids(hostInstance)
                .SelectMany(x => x.Faces.OfType<PlanarFace>());

            var doc = familySymbol.Document;

            using (var transaction = new Transaction(doc, "create families"))
            {
                transaction.Start();

                if (!familySymbol.IsActive)
                    familySymbol.Activate();

                foreach (var planarFace in faces)
                {
                    var faceBox = planarFace.GetBoundingBox();

                    var center = planarFace.Evaluate(0.5 * (faceBox.Max + faceBox.Min));

                    doc.Create.NewFamilyInstance(planarFace, center, XYZ.Zero, familySymbol);
                }

                transaction.Commit();
            }
        }

        private static IEnumerable<Solid> GetSolids(Element element)
        {
            var geometry = element
              .get_Geometry(new Options { ComputeReferences = true });

            if (geometry == null)
                return Enumerable.Empty<Solid>();

            return GetSolids(geometry)
                .Where(x => x.Volume > 0);
        }

        private static IEnumerable<Solid> GetSolids(IEnumerable<GeometryObject> geometryElement)
        {
            foreach (var geometry in geometryElement)
            {
                var solid = geometry as Solid;
                if (solid != null)
                    yield return solid;

                var instance = geometry as GeometryInstance;
                if (instance != null)
                    foreach (var instanceSolid in GetSolids(instance.GetInstanceGeometry()))
                        yield return instanceSolid;

                var element = geometry as GeometryElement;
                if (element != null)
                    foreach (var elementSolid in GetSolids(element))
                        yield return elementSolid;
            }
        }




        public Autodesk.Revit.UI.Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet eleSet)
        {
            Selection selection = cmdData.Application.ActiveUIDocument.Selection;
            m_doc = cmdData.Application.ActiveUIDocument.Document;
         
 
            FamilyInstance ins= null;
            try
            {
                Reference selected = selection.PickObject(ObjectType.Element, "select:");
               
                Element elemPick = m_doc.GetElement(selected.ElementId);
                ins = elemPick as FamilyInstance;
               
            }
            catch (System.Exception)
            {
                return Result.Succeeded;
            }

            FamilySymbol type = null;
             FilteredElementCollector elemCollector = new FilteredElementCollector(doc);
            elemCollector.OfClass(typeof(FamilySymbol));
            foreach (Element ent in elemCollector)
            {
                FamilySymbol obj = ent as FamilySymbol;
                if (obj.Family.Name.CompareTo("famName") == 0)
                {
                    type = obj;
                    break;
                }
            }


          CreateInstancesOnHostFamilyFaces(type, ins);

          return Result.Succeeded;
      }
Message 3 of 6
Anonymous
in reply to: Anonymous

I want to place a family at  the center of column's  face.

 

Kindly help me.

 

Thanks Advance,

Message 4 of 6
PavelAnd
in reply to: Anonymous

Hi @Anonymous . You need to use NewFamilyInstance method with reference direction. You can find the example here.

Best regards, Pavel Plotitsyn.

Message 5 of 6
Anonymous
in reply to: PavelAnd

thank u,  but that sample can not help me.

 

My code    at  beam   and  wall   is  OK!  So, location XYZ  is right.

But  ONLY  at column is  wrong.

 

I think   column is special.

Message 6 of 6
Organon
in reply to: Anonymous

@Anonymous ,

 

Hi,

 

Were you able to find a solution to the problem?

 

Regards,


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report