示例#1
0
        public PlanarFace GetFace(Element element)
        {
            Options opt = new Options();
            // Get geometry element of the selected element
            GeometryElement geoElement = element.get_Geometry(opt);

            PlanarFace pf = null;

            // Get geometry object
            foreach (GeometryObject geoObject in geoElement)
            {
                // Get the geometry instance which contains the geometry information
                Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;
                if (null != instance)
                {
                    GeometryElement instanceGeometryElement = instance.GetInstanceGeometry();
                    foreach (GeometryObject instObj in instanceGeometryElement)
                    {
                        Solid solid = instObj as Solid;
                        if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }
                        // Get the faces and edges from solid, and transform the formed points
                        foreach (Face face in solid.Faces)
                        {
                            //face.ComputeNormal(new UV(0.5, 0.5));
                            pf = face as PlanarFace;
                        }
                    }
                }
            }

            return(pf);
        }
示例#2
0
        /// <summary>
        /// Scan GeometryElement to collect triangles.
        /// </summary>
        /// <param name="geometry">The geometry element.</param>
        /// <param name="trf">The transformation.</param>
        private void ScanGeomElement(Document document, GeometryElement geometry, Transform transform)
        {
            //get all geometric primitives contained in the GeometryElement
            foreach (GeometryObject gObject in geometry)
            {
                // if the type of the geometric primitive is Solid
                Solid solid = gObject as Solid;
                if (null != solid)
                {
                    ScanSolid(document, solid, transform);
                    continue;
                }

                // if the type of the geometric primitive is instance
                GeometryInstance instance = gObject as GeometryInstance;
                if (null != instance)
                {
                    ScanGeometryInstance(document, instance, transform);
                    continue;
                }

                GeometryElement geomElement = gObject as GeometryElement;
                if (null != geomElement)
                {
                    ScanGeomElement(document, geomElement, transform);
                }
            }
        }
示例#3
0
        /// <summary>
        /// generate data of a Geometry Instance.
        /// </summary>
        /// <param name="obj">a geometry object of element.</param>
        private void AddInstance(GeometryObject obj)
        {
            Autodesk.Revit.DB.GeometryInstance instance   = obj as Autodesk.Revit.DB.GeometryInstance;
            Autodesk.Revit.DB.GeometryElement  geoElement = instance.SymbolGeometry;

            AddGeometryElement(geoElement);
        }
示例#4
0
        /// <summary>
        /// Scan GeometryInstance to collect triangles.
        /// </summary>
        /// <param name="instance">The geometry instance.</param>
        /// <param name="trf">The transformation.</param>
        private void ScanGeometryInstance(Document document, GeometryInstance instance, Transform transform)
        {
            GeometryElement instanceGeometry = instance.SymbolGeometry;

            if (null == instanceGeometry)
            {
                return;
            }
            Transform newTransform;

            if (null == transform)
            {
                newTransform = instance.Transform;
            }
            else
            {
                newTransform = transform.Multiply(instance.Transform);  // get a transformation of the affine 3-space
            }

            // get all geometric primitives contained in the GeometryElement
            ScanGeomElement(document, instanceGeometry, newTransform);
        }
示例#5
0
 Stream(Autodesk.Revit.DB.GeometryInstance inst)
 {
     PushXform(inst.Transform);
     Stream(inst.SymbolGeometry);
     PopXform();
 }
示例#6
0
文件: Form.cs 项目: algobasket/Dynamo
 private static IEnumerable <Autodesk.Revit.DB.Face> GetFaces(Autodesk.Revit.DB.GeometryInstance geomInst)
 {
     return(geomInst.GetInstanceGeometry()
            .OfType <Autodesk.Revit.DB.Solid>()
            .SelectMany(x => x.Faces.Cast <Autodesk.Revit.DB.Face>()));
 }
示例#7
0
        /// <summary>
        /// Get edges of element's profile
        /// </summary>
        /// <param name="elem">selected element</param>
        /// <returns>all the faces in the selected Element</returns>
        public override List <List <Edge> > GetFaces(Autodesk.Revit.DB.Element elem)
        {
            List <List <Edge> > faceEdges = new List <List <Edge> >();
            Options             options   = m_appCreator.NewGeometryOptions();

            options.DetailLevel = ViewDetailLevel.Medium;
            //make sure references to geometric objects are computed.
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options);
            //GeometryObjectArray gObjects = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //get all the edges in the Geometry object
            //foreach (GeometryObject geo in gObjects)
            while (Objects.MoveNext())
            {
                GeometryObject geo = Objects.Current;

                //if beam doesn't contain opening on it, then we can get edges from instance
                //and the points we get should be transformed by instance.Tranceform
                if (geo is Autodesk.Revit.DB.GeometryInstance)
                {
                    Autodesk.Revit.DB.GeometryInstance instance = geo as Autodesk.Revit.DB.GeometryInstance;
                    m_beamTransform = instance.Transform;
                    Autodesk.Revit.DB.GeometryElement elemGeo = instance.SymbolGeometry;
                    //GeometryObjectArray objectsGeo = elemGeo.Objects;
                    IEnumerator <GeometryObject> Objects1 = elemGeo.GetEnumerator();
                    //foreach (GeometryObject objGeo in objectsGeo)
                    while (Objects1.MoveNext())
                    {
                        GeometryObject objGeo = Objects1.Current;

                        Solid solid = objGeo as Solid;
                        if (null != solid)
                        {
                            FaceArray faces = solid.Faces;
                            foreach (Face face in faces)
                            {
                                EdgeArrayArray edgeArrarr = face.EdgeLoops;
                                foreach (EdgeArray edgeArr in edgeArrarr)
                                {
                                    List <Edge> edgesList = new List <Edge>();
                                    foreach (Edge edge in edgeArr)
                                    {
                                        edgesList.Add(edge);
                                    }
                                    faceEdges.Add(edgesList);
                                }
                            }
                        }
                    }
                }
                //if beam contains opening on it, then we can get edges from solid
                //and the points we get do not need transform anymore
                else if (geo is Autodesk.Revit.DB.Solid)
                {
                    m_haveOpening = true;
                    Solid     solid = geo as Solid;
                    FaceArray faces = solid.Faces;
                    foreach (Face face in faces)
                    {
                        EdgeArrayArray edgeArrarr = face.EdgeLoops;
                        foreach (EdgeArray edgeArr in edgeArrarr)
                        {
                            List <Edge> edgesList = new List <Edge>();
                            foreach (Edge edge in edgeArr)
                            {
                                edgesList.Add(edge);
                            }
                            faceEdges.Add(edgesList);
                        }
                    }
                }
            }
            return(faceEdges);
        }
        private Face FindFaceByReference(Element element, Reference reference, Transform transform)
        {
            Face faceFound = null;

            try
            {
                if (reference.LinkedElementId != ElementId.InvalidElementId)
                {
                    XYZ globalPoint    = reference.GlobalPoint;
                    UV  uvPoint        = reference.UVPoint;
                    XYZ intersectPoint = transform.Inverse.OfPoint(globalPoint);
                    //element in linked doc
                    Options opt = new Options();
                    opt.ComputeReferences = true;

                    GeometryElement geomElement = element.get_Geometry(opt);
                    foreach (GeometryObject geoObject in geomElement)
                    {
                        // Get the geometry instance which contains the geometry information
                        Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;
                        if (null != instance)
                        {
                            foreach (GeometryObject instObj in instance.SymbolGeometry)
                            {
                                Solid solid = instObj as Solid;
                                if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size)
                                {
                                    continue;
                                }
                                foreach (Face face in solid.Faces)
                                {
                                    IntersectionResult result = face.Project(intersectPoint);
                                    if (null != result)
                                    {
                                        if (result.XYZPoint.DistanceTo(intersectPoint) == 0)
                                        {
                                            return(faceFound);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    /*
                     * Reference linkReference = reference.CreateReferenceInLink();
                     * GeometryObject geomObj = element.GetGeometryObjectFromReference(linkReference);
                     * if (null != geomObj)
                     * {
                     *  faceFound = geomObj as Face;
                     * }
                     */
                }
                else
                {
                    //element in host doc
                    GeometryObject geomObj = element.GetGeometryObjectFromReference(reference);
                    if (null != geomObj)
                    {
                        faceFound = geomObj as Face;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(faceFound);
        }
示例#9
0
        private String GetRooms()
        {
            String tString = "";

            spaces = new FilteredElementCollector(doc)
                     .OfClass(typeof(SpatialElement)).WhereElementIsNotElementType()
                     .Where(X => X.Category.Name == "Spaces" || X.Category.Name == "Rooms").ToList <Element>();

            int interfaceCounter      = 1;
            int virtualElementCounter = 1;

            foreach (Element e in spaces)
            {
                //string URI = Parameters.GenerateURIifNotExist(doc, e).Replace(Namespace, "inst:");
                string URI = Util.CreateURI(e, Namespace).Replace(Namespace, "inst:");
                ElementDict.Add(e.Id, URI);
                //URItranslater.Add(URI,"inst:")

                if (e.Category.Name == "Spaces")
                {
                    Space space = e as Space;

                    String properties     = GetProperties(space);
                    String typeProperties = GetTypeProperties(space);

                    tString +=
                        NL + NL + $"{URI}" +
                        NLT + "a bot:Space ";

                    tString += ";" +
                               NLT + $"props:revitId \"{space.Id}\" ;" +
                               NLT + $"props:ifcGuid \"{space.GetGUID()}\" ;" +
                               NLT + $"props:uuid \"{space.GetUUID()}\" ;" +
                               NLT + $"props:number \"{space.Number}\"^^xsd:string " +
                               properties + typeProperties + ";";


                    tString += NLT + $"bot:hasSimple3DModel \"\"\"{Util.GetFacesAndEdges(space, true)}\"\"\" ." + NL;

                    IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
                    if (null != segments)  //the room may not be bound
                    {
                        foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
                            {
                                Element boundingEl = doc.GetElement(boundarySegment.ElementId);
                                if (boundingEl == null)
                                {
                                    Console.Out.WriteLine("Found null buildingEl: " + boundarySegment.ToString());
                                    continue;
                                }

                                //-2000066
                                //String eln = boundingEl.Name;
                                if (boundingEl.Category.Name == "<Room Separation>") // == BuiltInCategory.OST_RoomSeparationLines
                                {
                                    String virtualElement = "inst:VirtualElement_" + virtualElementCounter;
                                    if (virtualelements.ContainsKey(boundingEl.Id))
                                    {
                                        virtualElement = virtualelements[boundingEl.Id];
                                    }
                                    else
                                    {
                                        tString +=
                                            NL + "inst:VirtualElement_" + virtualElementCounter +
                                            NLT + "a bot:VirtualElement ." + NL;

                                        virtualelements.Add(boundingEl.Id, "inst:VirtualElement_" + virtualElementCounter);
                                    }

                                    tString +=
                                        NL + "inst:Interface_" + interfaceCounter +
                                        NLT + "a bot:Interface ;" +
                                        NLT + "bot:interfaceOf " + URI + ", " + virtualElement + " ;" +
                                        NLT + "fog:asSfa_v2-wkt \"LINESTRING ("
                                        + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL;

                                    interfaceCounter++;
                                    virtualElementCounter++;
                                }
                                else
                                {
                                    string boundingElURI = Util.CreateURI(boundingEl, Namespace).Replace(Namespace, "inst:");

                                    tString +=
                                        NL + "inst:Interface_" + interfaceCounter +
                                        NLT + "a bot:Interface ;" +
                                        NLT + "bot:interfaceOf " + URI + ", " + boundingElURI + " ;" +
                                        NLT + "fog:asSfa_v2-wkt \"LINESTRING ("
                                        + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL;

                                    interfaceCounter++;
                                }
                            }
                        }
                    }
                }

                if (e.Category.Name == "Rooms")
                {
                    Room room = e as Room;

                    String properties     = GetProperties(room);
                    String typeProperties = GetTypeProperties(room);

                    tString +=
                        NL + NL + $"{URI}" +
                        NLT + "a bot:Space ";

                    tString += ";" +
                               NLT + $"props:revitId \"{room.Id}\" ;" +
                               NLT + $"props:ifcGuid \"{room.GetGUID()}\" ;" +
                               NLT + $"props:uuid \"{room.GetUUID()}\" ;" +
                               NLT + $"props:number \"{room.Number}\"^^xsd:string " +
                               properties + typeProperties + ";";

                    tString += NLT + $"bot:hasSimple3DModel \"\"\"{Util.GetFacesAndEdges(room,true)}\"\"\" ." + NL;

                    IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
                    if (null != segments)  //the room may not be bound
                    {
                        foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
                            {
                                Element boundingEl = doc.GetElement(boundarySegment.ElementId);
                                if (boundingEl == null)
                                {
                                    continue;
                                }

                                //String eln = boundingEl.Name;
                                if (boundingEl.Category.Name == "Walls" && boundingEl.Category.Id == new ElementId(BuiltInCategory.OST_Walls) && !(boundingEl is FamilyInstance))
                                {
                                    Wall x = (Wall)boundingEl;
                                    IList <ElementId> inserts = x.FindInserts(true, false, false, false);
                                    foreach (ElementId id in inserts)
                                    {
                                        Element eli = doc.GetElement(id);
                                        if (eli.Category.Name == "Doors")
                                        {
                                            FamilyInstance  d  = (FamilyInstance)eli;
                                            GeometryElement ge = d.get_Geometry(new Options());

                                            // Get geometry object
                                            foreach (GeometryObject geoObject in ge)
                                            {
                                                // Get the geometry instance which contains the geometry information
                                                Autodesk.Revit.DB.GeometryInstance instance =
                                                    geoObject as Autodesk.Revit.DB.GeometryInstance;
                                                if (null != instance)
                                                {
                                                    GeometryElement instanceGeometryElement = instance.GetInstanceGeometry();
                                                    foreach (GeometryObject o in instanceGeometryElement)
                                                    {
                                                        // Try to find curves
                                                        Curve curve = o as Curve;
                                                        if (curve != null)
                                                        {
                                                            string eliURI = Util.CreateURI(eli, Namespace).Replace(Namespace, "inst:");

                                                            // The curve is already transformed into the project coordinate system
                                                            tString +=
                                                                NL + "inst:Interface_" + interfaceCounter +
                                                                NLT + "a bot:Interface ;" +
                                                                NLT + "bot:interfaceOf " + URI + ", " + eliURI + " ;" +
                                                                NLT + "fog:asSfa_v2-wkt \"LINESTRING ("
                                                                + (curve.GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                                                + (curve.GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", "
                                                                + (curve.GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                                                + (curve.GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL;

                                                            interfaceCounter++;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                else if (boundingEl.Category.Name == "<Room Separation>") // == BuiltInCategory.OST_RoomSeparationLines
                                {
                                    String virtualElement = "inst:VirtualElement_" + virtualElementCounter;
                                    if (virtualelements.ContainsKey(boundingEl.Id))
                                    {
                                        virtualElement = virtualelements[boundingEl.Id];
                                    }
                                    else
                                    {
                                        tString +=
                                            NL + "inst:VirtualElement_" + virtualElementCounter +
                                            NLT + "props:revitId " + boundingEl.Id + " ;" +
                                            NLT + "a bot:VirtualElement ." + NL;

                                        virtualelements.Add(boundingEl.Id, "inst:VirtualElement_" + virtualElementCounter);
                                    }

                                    tString +=
                                        NL + "inst:Interface_" + interfaceCounter +
                                        NLT + "a bot:Interface ;" +
                                        NLT + "bot:interfaceOf " + URI + ", " + virtualElement + " ;" +
                                        NLT + "fog:asSfa_v2-wkt \"LINESTRING ("
                                        + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL;

                                    interfaceCounter++;
                                    virtualElementCounter++;
                                }

                                else
                                {
                                    string boundingElURI = Util.CreateURI(boundingEl, Namespace).Replace(Namespace, "inst:");

                                    tString +=
                                        NL + "inst:Interface_" + interfaceCounter +
                                        NLT + "a bot:Interface ;" +
                                        NLT + "bot:interfaceOf " + URI + ", " + boundingElURI + " ;" +
                                        NLT + "fog:asSfa_v2-wkt \"LINESTRING ("
                                        + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " "
                                        + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL;

                                    interfaceCounter++;
                                }
                            }
                        }
                    }
                }
            }

            return(tString);
        }
示例#10
0
        public void execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                //Retrieves the current active project.
                Autodesk.Revit.UI.UIApplication app = commandData.Application;
                UIDocument doc = app.ActiveUIDocument;

                string ExecutingAssemblyPath = Assembly.GetExecutingAssembly().Location;
                string DllAssemblyPath       = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExeWriter)).CodeBase);
                //revitApp = app
                Autodesk.Revit.DB.View view = commandData.View;
                String ApplicationName      = doc.Document.Title;
                String WievName             = view.Document.Title;
                //Initialize RenderAppearancesForm
                //RenderAppearancesFrom.Asssets = app.Application.get_Assets(Autodesk.Revit.Utility.AssetType.Appearance);

                // Generate a object for Revit materials management.
                //MaterialsMgr materialsManager = new MaterialsMgr(doc, app);

                // Feed a MaterialsMgr to a dialog.
                FilteredElementCollector collector   = new FilteredElementCollector(doc.Document);
                ICollection <Element>    AllElements = collector.WhereElementIsNotElementType().ToElements();

                ArrayList objs = new ArrayList();
                Autodesk.Revit.DB.GeometryElement GeomElem;
                //Autodesk.Revit.DB.Options Opts= new Options();
                Autodesk.Revit.DB.Options geomOp = app.Application.Create.NewGeometryOptions();
                writeData.Init(ref message);
                Autodesk.Revit.DB.GeometryInstance instance = null;
                foreach (Element element in AllElements)
                {
                    Autodesk.Revit.DB.Phase phaseCreated = element.PhaseCreated;
                    if (null != phaseCreated)
                    {
                        //Get Geometry element
                        GeomElem = element.get_Geometry(geomOp);
                        if (null == GeomElem)
                        {
                            TopographySurface TyPo = element as TopographySurface;
                            if (null == TyPo)
                            {
                                HostObject HostOb = element as HostObject;
                                if (null == HostOb)
                                {
                                }
                                else
                                {
                                    GeomElem = HostOb.get_Geometry(geomOp);
                                }
                            }
                            else
                            {
                                GeomElem = TyPo.get_Geometry(geomOp);
                            }
                        }
                        //Geometry must be
                        if (null != GeomElem)
                        {
                            //GeomElem = element.get_Geometry(Opts);
                            foreach (GeometryObject geomObj in GeomElem.Objects)
                            {
                                uint  uCurves   = 0;
                                Solid geomSolid = geomObj as Solid;
                                Curve geomCurve = geomObj as Curve;
                                Mesh  geomMesh  = geomObj as Mesh;
                                Edge  geomEdge  = geomObj as Edge;
                                instance = geomObj as Autodesk.Revit.DB.GeometryInstance;

                                if (null != instance)
                                {
                                    foreach (GeometryObject InstanObj in instance.SymbolGeometry.Objects)
                                    {
                                        geomSolid = InstanObj as Solid;
                                        geomMesh  = InstanObj as Mesh;
                                        geomEdge  = InstanObj as Edge;
                                        geomCurve = InstanObj as Curve;
                                        if (geomCurve != null)
                                        {
                                            // transfrom the curve to make it in the instance's coordinate space
                                            geomCurve = geomCurve.get_Transformed(instance.Transform);
                                        }
                                        if (geomSolid != null)
                                        {
                                            // transfrom the curve to make it in the instance's coordinate space
                                            DataProcess(geomSolid, instance);
                                        }
                                    }
                                }
                                if (null != geomCurve)
                                {
                                    uCurves++;
                                }
                                if (null != geomSolid)
                                {
                                    DataProcess(geomSolid, instance);
                                }
                            }

                            SendData(element, instance);
                            objs.Add(element);
                            d_VerticesList.Clear();
                            d_NormalsList.Clear();
                            d_TextureCoordsList.Clear();
                            d_FeatureMaterialList.Clear();
                            u_IndicesList.Clear();
                            u_FeaturesIndList.Clear();
                        }
                    }
                }

                System.Diagnostics.Trace.WriteLine(AllElements.Count.ToString());
                CF_WriterForm form = new CF_WriterForm(objs);
                //form.ShowDialog();
                //using (MaterialsForm dlg = new MaterialsForm(materialsManager,commandData))
                //{
                form.ExportFileName = ApplicationName;
                if (form.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
                {
                    ExportFileName = form.ExportFileName;
                    EndProsess(ref message);
                    // Revit need to do nothing.
                    //return Autodesk.Revit.UI.Result.Cancelled;
                }
                else
                {
                    // Done some action, ask revit to execute it.
                    //return Autodesk.Revit.UI.Result.Succeeded;
                }
                //}
            }
            catch (Exception e)
            {
                // Exception rised, report it by revit error reporting mechanism.
                message = e.ToString();
                File.AppendAllText(@"C:\CadFaster\Revit\CF_WriterDLLs_log.txt", message);
                //return Autodesk.Revit.UI.Result.Failed;
            }
        }
示例#11
0
        /// <summary>
        /// Inquire an geometry element to get all face instances
        /// </summary>
        /// <param name="geoElement">the geometry element</param>
        /// <param name="elem">the element, it provides the prefix of face name</param>
        /// <returns></returns>
        private bool InquireGeometry(GeoElement geoElement, RevitElement elem)
        {
            if (null == geoElement || null == elem)
            {
                return(false);
            }

            //GeometryObjectArray geoArray = null;
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

            //if (null != geoElement && null != geoElement.Objects)
            if (null != geoElement && Objects.MoveNext())
            {
                //geoArray = geoElement.Objects;
            }
            else
            {
                return(false);
            }

            Objects.Reset();
            //foreach (GeometryObject obj in geoArray)
            while (Objects.MoveNext())
            {
                GeometryObject obj = Objects.Current;

                if (obj is GeoInstance)
                {
                    GeoInstance instance = (GeoInstance)obj;
                    InquireGeometry(instance.SymbolGeometry, elem);
                }
                else if (!(obj is Solid))
                {
                    // is not Solid instance
                    continue;
                }

                // continue when obj is Solid instance
                Solid solid = obj as Solid;
                if (null == solid)
                {
                    continue;
                }
                FaceArray faces = solid.Faces;
                if (faces.IsEmpty)
                {
                    continue;
                }

                // get the face name list
                String category = String.Empty;
                if (null != elem.Category && null != elem.Name)
                {
                    category = elem.Category.Name;
                }

                int ii = 0;
                foreach (Face tempFace in faces)
                {
                    if (tempFace is PlanarFace)
                    {
                        m_faceNameList.Add(
                            String.Format("{0} : {1} ({2})", category, elem.Name, ii));
                        m_faceList.Add(tempFace);
                        ii++;
                    }
                }
            }
            return(true);
        }
        /// <summary>
        /// Scan GeometryInstance to collect triangles.
        /// </summary>
        /// <param name="instance">The geometry instance.</param>
        /// <param name="trf">The transformation.</param>
        private void ScanGeometryInstance(Document document, GeometryInstance instance, Transform transform)
        {
            GeometryElement instanceGeometry = instance.SymbolGeometry;
            if (null == instanceGeometry)
            {
                return;
            }
            Transform newTransform;
            if (null == transform)
            {
                newTransform = instance.Transform;
            }
            else
            {
                newTransform = transform.Multiply(instance.Transform);	// get a transformation of the affine 3-space
            }

            // get all geometric primitives contained in the GeometryElement
            ScanGeomElement(document,instanceGeometry, newTransform);
        }
示例#13
0
        private void MakeConvertToHSF(UIApplication app, UIDocument doc)
        {
            FilteredElementCollector collector   = new FilteredElementCollector(doc.Document);
            ICollection <Element>    AllElements = collector.WhereElementIsNotElementType().ToElements();
            //fr_status.StartProgressBar(AllElements.Count);
            ArrayList objs = new ArrayList();

            Autodesk.Revit.DB.GeometryElement GeomElem = null;
            Autodesk.Revit.DB.GeometryElement CatElem  = null;
            //Autodesk.Revit.DB.Options Opts= new Options();
            Autodesk.Revit.DB.Options geomOp = app.Application.Create.NewGeometryOptions();
            writeData.Init(ExportFileName);

            Autodesk.Revit.DB.GeometryInstance instance = null;
            Material materialElement = null;

            fr_Progress.StartProgressBar(AllElements.Count);
            int iElementCount = 0;

            foreach (Element element in AllElements)
            {
                fr_Progress.AddValueProgressBar(iElementCount++);
                instance = null;

                //fr_status.UpDateProgressBar(iCurrentElementCount++);
                Autodesk.Revit.DB.Phase phaseCreated = element.PhaseCreated;
                if (null != phaseCreated)
                {
                    if (element is TopographySurface)
                    {
                        //materialElement = element.Category.Material;
                        foreach (Parameter par in element.Parameters)
                        {
                            if ("Material" == par.Definition.Name)
                            {
                                ElementId Id = par.AsElementId();
                                if (-1 != Id.IntegerValue)
                                {
                                    Element eleMat = doc.Document.get_Element(Id);
                                    materialElement = eleMat as Material;
                                }
                                else
                                {
                                    materialElement = element.Category.Material;
                                }
                                //materialElement = materials.get_Item(Id);
                            }
                        }
                    }
                    GeomElem = element.get_Geometry(geomOp);
                    if (null == GeomElem)
                    {
                        TopographySurface TyPo = element as TopographySurface;
                        if (null == TyPo)
                        {
                            HostObject HostOb = element as HostObject;
                            if (null == HostOb)
                            {
                            }//if (null == HostOb)
                            else
                            {
                                GeomElem = HostOb.get_Geometry(geomOp);
                            }
                        }//if (null == TyPo)
                        else
                        {
                            GeomElem = TyPo.get_Geometry(geomOp);
                        }
                    }//if (null == GeomElem)
                    if (null != GeomElem)
                    {
                        HandleGeometryElement(GeomElem, ref instance, doc, materialElement);
                    }//if (null != GeomElem)

                    if (null != GeomElem || null != CatElem)
                    {
                        SendData(element, instance);
                        //objs.Add(element);
                        Lid_Vertices.Clear();
                        Lid_Normals.Clear();
                        Lid_TextureCoords.Clear();
                        Lid_FeatureMaterial.Clear();
                        Liu_Indices.Clear();
                        Liu_FeatureIndex.Clear();
                    } //if (null != GeomElem)
                }     //if (null != phaseCreated)
            }         // foreach (Element element in AllElements)

            //System.Diagnostics.Trace.WriteLine(AllElements.Count.ToString());
            //CF_WriterForm form = new CF_WriterForm(objs);
            //form.ShowDialog();
            //using (MaterialsForm dlg = new MaterialsForm(materialsManager,commandData))
            //{
        }