Exemplo n.º 1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Topography);

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            IList <Element>          topoSurf  = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();

            TopographySurface topo = topoSurf[0] as TopographySurface;

            try
            {
                GeometryElement elementGeometry = topo.get_Geometry(new Options());
                TaskDialog.Show("Here", elementGeometry.LongCount().ToString());

                int count = 0;
                foreach (GeometryObject obj in elementGeometry)
                {
                    if (obj is Mesh)
                    {
                        Mesh topoMesh = obj as Mesh;
                        count += topoMesh.NumTriangles;
                    }
                    else if (obj is Solid)
                    {
                        Solid sol = obj as Solid;
                        foreach (Face face in sol.Faces)
                        {
                            Mesh meshFace = face.Triangulate(0.7);
                        }
                    }
                }

                TaskDialog.Show("There", count.ToString());

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                TaskDialog.Show("There", e.Message);
                return(Result.Cancelled);
            }
        }
Exemplo n.º 2
0
        public static Topography ToSpeckle(this TopographySurface mySurface)
        {
            var speckleTopo = new Topography();

            speckleTopo.Vertices = new List <double>();
            speckleTopo.Faces    = new List <int>();

            var geom = mySurface.get_Geometry(new Options());

            foreach (var element in geom)
            {
                if (element is Mesh)
                {
                    var mesh = ( Mesh )element;

                    foreach (var vert in mesh.Vertices)
                    {
                        speckleTopo.Vertices.AddRange(new double[] { vert.X / Scale, vert.Y / Scale, vert.Z / Scale });
                    }

                    for (int i = 0; i < mesh.NumTriangles; i++)
                    {
                        var triangle = mesh.get_Triangle(i);
                        var A        = triangle.get_Index(0);
                        var B        = triangle.get_Index(1);
                        var C        = triangle.get_Index(2);
                        speckleTopo.Faces.Add(0);
                        speckleTopo.Faces.AddRange(new int[] { ( int )A, ( int )B, ( int )C });
                    }
                }
            }

            speckleTopo.parameters     = GetElementParams(mySurface);
            speckleTopo.typeParameters = GetElementTypeParams(mySurface);
            speckleTopo.ApplicationId  = mySurface.UniqueId;
            speckleTopo.elementId      = mySurface.Id.ToString();

            speckleTopo.GenerateHash();
            return(speckleTopo);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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))
            //{
        }