/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="revit">
        /// The application object for the active instance of Autodesk Revit.
        /// </param>
        public DataGenerator(RevitApplication revitApp, Document doc, RevitView view)
        {
            //initialize the member variable
            if (revitApp != null)
            {
                m_RevitApp = revitApp;
                m_ActiveDocument = doc;
                m_ActiveView = view;

                m_ViewOptions = m_RevitApp.Create.NewGeometryOptions();
                m_ViewOptions.View = m_ActiveView;
            }
        }
Esempio n. 2
0
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            Element thisElement = (Element)((FScheme.Value.Container)args[0]).Item;

            instanceGeometryObjects = new List<GeometryObject>();

            var result = FSharpList<FScheme.Value>.Empty;

            Autodesk.Revit.DB.Options geoOptionsOne = new Autodesk.Revit.DB.Options();
            geoOptionsOne.ComputeReferences = true;

            GeometryObject geomObj = thisElement.get_Geometry(geoOptionsOne);
            GeometryElement geomElement = geomObj as GeometryElement;

            if ((thisElement is GenericForm) && (geomElement.Count() < 1))
            {
                GenericForm gF = (GenericForm)thisElement;
                if (!gF.Combinations.IsEmpty)
                {
                    Autodesk.Revit.DB.Options geoOptionsTwo = new Autodesk.Revit.DB.Options();
                    geoOptionsTwo.IncludeNonVisibleObjects = true;
                    geoOptionsTwo.ComputeReferences = true;
                    geomObj = thisElement.get_Geometry(geoOptionsTwo);
                    geomElement = geomObj as GeometryElement;
                }
            }

            foreach (GeometryObject geob in geomElement)
            {
                GeometryInstance ginsta = geob as GeometryInstance;
                if (ginsta != null)
                {
                    GeometryElement instanceGeom = ginsta.GetInstanceGeometry();
                    instanceGeometryObjects.Add(instanceGeom);
                    foreach (GeometryObject geobInst in instanceGeom)
                    {
                        result = FSharpList<FScheme.Value>.Cons(FScheme.Value.NewContainer(geobInst), result);
                    }
                }
                else
                {
                    result = FSharpList<FScheme.Value>.Cons(FScheme.Value.NewContainer(geob), result);
                }
            }

            return FScheme.Value.NewList(result);
        }
Esempio n. 3
0
 COVER()
 {
     mOptions = new Autodesk.Revit.DB.Options();
      mOptions.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine;
      try
      {
      ButtonIconsFolder = System.Environment.GetEnvironmentVariable("COVISEDIR");
      }
      catch
      {
      }
      if (ButtonIconsFolder == null || ButtonIconsFolder.Length == 0)
      {
      ButtonIconsFolder = "c:/src/covise";
      }
      ButtonIconsFolder += "/share/covise/icons";
      connectedImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "cover_connected_32.png"), UriKind.Absolute));
      disconnectedImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "cover_disconnected_32.png"), UriKind.Absolute));
 }
Esempio n. 4
0
        public static void BuildPreview
        (
            DB.Element element, MeshingParameters meshingParameters, DB.ViewDetailLevel DetailLevel,
            out Rhino.Display.DisplayMaterial[] materials, out Mesh[] meshes, out Curve[] wires
        )
        {
            DB.Options options = null;
            using (var geometry = element?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out options)) using (options)
                {
                    if (geometry is null)
                    {
                        materials = null;
                        meshes    = null;
                        wires     = null;
                    }
                    else
                    {
                        var categoryMaterial = element.Category?.Material.ToRhino(null);
                        var elementMaterial  = geometry.MaterialElement.ToRhino(categoryMaterial);

                        using (var ga = Convert.GraphicAttributes.Push())
                        {
                            ga.MeshingParameters = meshingParameters;

                            meshes    = geometry.GetPreviewMeshes().Where(x => x is object).ToArray();
                            wires     = geometry.GetPreviewWires().Where(x => x is object).ToArray();
                            materials = geometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object).ToArray();

                            foreach (var mesh in meshes)
                            {
                                mesh.Normals.ComputeNormals();
                            }
                        }
                    }
                }
        }
Esempio n. 5
0
        const double PRECISION = 0.00001;    //precision when judge whether two doubles are equal

        /// <summary>
        /// get all faces that compose the geometry solid of given element
        /// </summary>
        /// <param name="elem">element to be calculated</param>
        /// <returns>all faces</returns>
        public static FaceArray GetFaces(Element elem)
        {
            List <Face> faces = new List <Face>();

            Autodesk.Revit.DB.Options geoOptions =
                Command.CommandData.Application.Application.Create.NewGeometryOptions();
            geoOptions.ComputeReferences = true;

            GeoElement          geoElem  = elem.get_Geometry(geoOptions);
            GeometryObjectArray geoElems = geoElem.Objects;

            foreach (object o in geoElems)
            {
                GeoSolid geoSolid = o as GeoSolid;
                if (null == geoSolid)
                {
                    continue;
                }

                return(geoSolid.Faces);
            }

            return(null);
        }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.Element element = null;
            if (!DA.GetData(ObjectType.Name, ref element))
            {
                return;
            }

            var detailLevel = DB.ViewDetailLevel.Undefined;

            DA.GetData(1, ref detailLevel);
            if (detailLevel == DB.ViewDetailLevel.Undefined)
            {
                detailLevel = DB.ViewDetailLevel.Coarse;
            }

            DB.Options options = null;
            using (var geometry = element?.GetGeometry(detailLevel, out options)) using (options)
                {
                    var list = geometry?.ToRhino().Where(x => x is object).ToList();

                    DA.SetDataList(PropertyName, list);
                }
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (base.CastTo <Q>(ref target))
            {
                return(true);
            }

            var element = (DB.Element) this;

            if (typeof(DB.Element).IsAssignableFrom(typeof(Q)))
            {
                if (element is null)
                {
                    if (IsValid)
                    {
                        return(false);
                    }
                }
                else if (!typeof(Q).IsAssignableFrom(element.GetType()))
                {
                    return(false);
                }

                target = (Q)(object)element;
                return(true);
            }

            if (element is null)
            {
                return(false);
            }

            if (element.Category?.HasMaterialQuantities ?? false)
            {
                if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh)))
                {
                    DB.Options options = null;
                    using (var geometry = element.GetGeometry(DB.ViewDetailLevel.Fine, out options)) using (options)
                        {
                            if (geometry is object)
                            {
                                var mesh = new Rhino.Geometry.Mesh();
                                mesh.Append(geometry.GetPreviewMeshes(null).Where(x => x is object));
                                mesh.Normals.ComputeNormals();
                                if (mesh.Faces.Count > 0)
                                {
                                    target = (Q)(object)new GH_Mesh(mesh);
                                    return(true);
                                }
                            }
                        }
                }
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
            {
                var axis = Axis;
                if (axis is null)
                {
                    return(false);
                }

                target = (Q)(object)new GH_Curve(axis);
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Plane)))
            {
                try
                {
                    var plane = Plane;
                    if (!plane.IsValid || !plane.Origin.IsValid)
                    {
                        return(false);
                    }

                    target = (Q)(object)new GH_Plane(plane);
                    return(true);
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException) { return(false); }
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Point)))
            {
                var location = Location;
                if (!location.IsValid)
                {
                    return(false);
                }

                target = (Q)(object)new GH_Point(location);
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Vector)))
            {
                var normal = ZAxis;
                if (!normal.IsValid)
                {
                    return(false);
                }

                target = (Q)(object)new GH_Vector(normal);
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Transform)))
            {
                var plane = Plane;
                if (!plane.IsValid || !plane.Origin.IsValid)
                {
                    return(false);
                }

                target = (Q)(object)new GH_Transform(Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane));
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Box)))
            {
                var box = Box;
                if (!box.IsValid)
                {
                    return(false);
                }

                target = (Q)(object)new GH_Box(box);
                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Internal constructor to make a solid by extracting solids from an element.
        /// </summary>
        /// <param name="element"></param>
        internal Solid(Autodesk.Revit.DB.Element element)
        {
            // Regenerate to get the solids in the element. If the element was
            // created during this same run, document regeneration will not have
            // occured.
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            DocumentManager.Regenerate();
            TransactionManager.Instance.TransactionTaskDone();

            var instanceSolids = new Dictionary<ElementId, List<Autodesk.Revit.DB.GeometryObject>>();;
            Autodesk.Revit.DB.Solid mySolid = null;

            var thisId = ElementId.InvalidElementId;

            if (element != null)
            {
                thisId = element.Id;
                instanceSolids[thisId] = new List<Autodesk.Revit.DB.GeometryObject>();
            }

            bool bNotVisibleOption = false;
            if (element is GenericForm)
            {
                var gF = (GenericForm)element;
                if (!gF.Combinations.IsEmpty)
                    bNotVisibleOption = true;
            }

            int nTry = (bNotVisibleOption) ? 2 : 1;
            for (int iTry = 0; iTry < nTry && (mySolid == null);
                iTry++)
            {
                var geoOptions = new Autodesk.Revit.DB.Options();
                geoOptions.ComputeReferences = true;
                if (bNotVisibleOption && (iTry == 1))
                    geoOptions.IncludeNonVisibleObjects = true;

                Autodesk.Revit.DB.GeometryObject geomObj = element.get_Geometry(geoOptions);
                var geomElement = geomObj as GeometryElement;

                if (geomElement != null)
                {
                    foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
                    {
                        var ginsta = geob as GeometryInstance;
                        if (ginsta != null && thisId != ElementId.InvalidElementId)
                        {
                            GeometryElement instanceGeom = ginsta.GetInstanceGeometry();

                            instanceSolids[thisId].Add(instanceGeom);

                            foreach (Autodesk.Revit.DB.GeometryObject geobInst in instanceGeom)
                            {
                                mySolid = geobInst as Autodesk.Revit.DB.Solid;
                                if (mySolid != null)
                                {
                                    FaceArray faceArr = mySolid.Faces;
                                    var thisEnum = faceArr.GetEnumerator();
                                    bool hasFace = false;
                                    for (; thisEnum.MoveNext(); )
                                    {
                                        hasFace = true;
                                        break;
                                    }
                                    if (!hasFace)
                                        mySolid = null;
                                    else
                                        break;
                                }
                            }
                            if (mySolid != null)
                                break;
                        }
                        else
                        {
                            mySolid = geob as Autodesk.Revit.DB.Solid;
                            if (mySolid != null)
                            {
                                FaceArray faceArr = mySolid.Faces;
                                var thisEnum = faceArr.GetEnumerator();
                                bool hasFace = false;
                                for (; thisEnum.MoveNext(); )
                                {
                                    hasFace = true;
                                    break;
                                }
                                if (!hasFace)
                                    mySolid = null;
                                else
                                    break;
                            }

                        }
                    }
                }
            }

            this.InternalSolid = mySolid;
        }
Esempio n. 10
0
        AddObjectsToTree(Element elem, TreeNodeCollection curNodes)
        {
            Autodesk.Revit.DB.Options geomOp;

            TreeNode tmpNode;

            // add geometry with the View set to null.
            TreeNode rootNode1 = new TreeNode("View = null");

            curNodes.Add(rootNode1);
            foreach (ViewDetailLevel viewDetailLevel in Enum.GetValues(typeof(ViewDetailLevel)))
            {
                tmpNode = new TreeNode("Detail Level = " + viewDetailLevel.ToString());
                // IMPORTANT!!! Need to create options each time when you are
                // getting geometry. In other case, all the geometry you got at the
                // previous step will be owerriten according with the latest DetailLevel
                geomOp = m_app.Create.NewGeometryOptions();
                geomOp.ComputeReferences = true;
                geomOp.DetailLevel       = viewDetailLevel;
                tmpNode.Tag = elem.get_Geometry(geomOp);
                rootNode1.Nodes.Add(tmpNode);
            }



            // add model geometry including geometry objects not set as Visible.
            TreeNode rootNode = new TreeNode("View = null - Including geometry objects not set as Visible");

            curNodes.Add(rootNode);
            foreach (ViewDetailLevel viewDetailLevel in Enum.GetValues(typeof(ViewDetailLevel)))
            {
                tmpNode = new TreeNode("Detail Level = " + viewDetailLevel.ToString());
                // IMPORTANT!!! Need to create options each time when you are
                // getting geometry. In other case, all the geometry you got at the
                // previous step will be owerriten according with the latest DetailLevel
                geomOp = m_app.Create.NewGeometryOptions();
                geomOp.ComputeReferences        = true;
                geomOp.IncludeNonVisibleObjects = true;
                geomOp.DetailLevel = viewDetailLevel;
                tmpNode.Tag        = elem.get_Geometry(geomOp);
                rootNode.Nodes.Add(tmpNode);
            }

            // now add geometry with the View set to the current view
            if (elem.Document.ActiveView != null)
            {
                Options geomOp2 = m_app.Create.NewGeometryOptions();
                geomOp2.ComputeReferences = true;
                geomOp2.View = elem.Document.ActiveView;

                TreeNode rootNode2 = new TreeNode("View = Document.ActiveView");
                rootNode2.Tag = elem.get_Geometry(geomOp2);
                curNodes.Add(rootNode2);

                // SOFiSTiK FS
                // add model geometry including geometry objects not set as Visible.
                {
                    Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
                    opts.ComputeReferences        = true;
                    opts.IncludeNonVisibleObjects = true;
                    opts.View = elem.Document.ActiveView;

                    rootNode = new TreeNode("View = Document.ActiveView - Including geometry objects not set as Visible");
                    curNodes.Add(rootNode);

                    rootNode.Tag = elem.get_Geometry(opts);
                }
            }
        }
Esempio n. 11
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            var elements = new List <DB.Element>();

            if (!DA.GetDataList("Elements", elements) || elements.Count == 0)
            {
                return;
            }

            var exclude   = new List <DB.Element>();
            var _Exclude_ = Params.IndexOfInputParam("Exclude");

            if (_Exclude_ >= 0)
            {
                DA.GetDataList(_Exclude_, exclude);
            }

            if (!TryGetCommonDocument(elements.Concat(exclude), out var doc))
            {
                return;
            }

            var detailLevel   = DB.ViewDetailLevel.Undefined;
            var _DetailLevel_ = Params.IndexOfInputParam("Detail Level");

            if (_DetailLevel_ >= 0)
            {
                DA.GetData(_DetailLevel_, ref detailLevel);
                if (detailLevel == DB.ViewDetailLevel.Undefined)
                {
                    detailLevel = DB.ViewDetailLevel.Coarse;
                }
            }

            using (var options = new DB.Options()
            {
                DetailLevel = detailLevel
            })
            {
                Params.TrySetDataList(DA, "Elements", () => elements);

                var _Geometry_ = Params.IndexOfOutputParam("Geometry");
                SolveGeometry
                (
                    DA.ParameterTargetPath(_Geometry_),
                    doc,
                    elements,
                    exclude,
                    options,
                    out var Geometry
                );
                DA.SetDataTree(_Geometry_, Geometry);

                var _Categories_ = Params.IndexOfOutputParam("Categories");
                var Categories   = _Categories_ >= 0 ? new GH_Structure <Types.Category>() : default;

                var _Materials_ = Params.IndexOfOutputParam("Materials");
                var Materials   = _Materials_ >= 0 ? new GH_Structure <Types.Material>() : default;

                SolveAttributes(doc, Geometry, Categories, Materials);

                if (Categories is object)
                {
                    DA.SetDataTree(_Categories_, Categories);
                }

                if (Materials is object)
                {
                    DA.SetDataTree(_Materials_, Materials);
                }
            }
        }
Esempio n. 12
0
        public IEnumerable<Autodesk.Revit.DB.GeometryObject> InternalGeometry()
        {
            var thisElement = InternalElement;

            var goptions0 = new Autodesk.Revit.DB.Options();
            goptions0.ComputeReferences = true;

            var geomElement = thisElement.get_Geometry(goptions0);

            // GenericForm is a special case
            if ((thisElement is GenericForm) && (!geomElement.Any()))
            {
                var gF = (GenericForm)thisElement;
                if (!gF.Combinations.IsEmpty)
                {
                    var goptions1 = new Autodesk.Revit.DB.Options();
                    goptions1.IncludeNonVisibleObjects = true;
                    goptions1.ComputeReferences = true;
                    geomElement = thisElement.get_Geometry(goptions1);
                }
            }

            return CollectConcreteGeometry(geomElement);
        }
Esempio n. 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))
            //{
        }
        private void ImportAutoCADFile(int id)
        {
            if (uidoc.Document != null)
            {
                preCurveElementIds.Clear();
                FilteredElementCollector preElementDocFilter = new FilteredElementCollector(doc);
                if (preElementDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preElementDocFilter.OfClass(typeof(CurveElement)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preCurveElementIds.Add(preElementsIdsIterator.Current);
                    }
                }

                preTextNotesIds.Clear();
                FilteredElementCollector preTextNoteDocFilter = new FilteredElementCollector(doc);
                if (preTextNoteDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preTextNoteDocFilter.OfClass(typeof(TextNote)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preTextNotesIds.Add(preElementsIdsIterator.Current);
                    }
                }

                preTextNoteTypesIds.Clear();
                FilteredElementCollector preTextNoteTypeDocFilter = new FilteredElementCollector(doc);
                if (preTextNoteTypeDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preTextNoteTypeDocFilter.OfClass(typeof(TextNoteType)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preTextNoteTypesIds.Add(preElementsIdsIterator.Current);

                        TextNoteType preTextNodeType = doc.GetElement(preElementsIdsIterator.Current) as TextNoteType;
                        if (preTextNodeType != null)
                        {
                            this.revitTextNoteTypesDict.Add(preTextNodeType.Name, preTextNodeType);
                        }
                    }
                }

                Category preLinesStyles = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                foreach (Category preLineCategory in preLinesStyles.SubCategories)
                {
                    preLineCategoriesIds.Add(preLineCategory.Id);
                    this.revitCategoriesDict.Add(preLineCategory.Name, preLineCategory);
                }


                preGraphycStyleIds.Clear();
                FilteredElementCollector preGraphycsStyleDocFilter = new FilteredElementCollector(doc);
                if (preGraphycsStyleDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preGraphycsStyleDocFilter.OfClass(typeof(GraphicsStyle)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        GraphicsStyle preGraphicsStyle = doc.GetElement(preElementsIdsIterator.Current) as GraphicsStyle;
                        if (preGraphicsStyle != null)
                        {
                            if (preLineCategoriesIds.Contains(preGraphicsStyle.GraphicsStyleCategory.Id))
                            {
                                preGraphycStyleIds.Add(preElementsIdsIterator.Current);

                                revitLineStylesDict.Add(preGraphicsStyle.Name, preGraphicsStyle);
                            }
                        }
                    }
                }

                #region
                deleteImportInstances();
                DWGImportOptions importOptions = new DWGImportOptions();
                importOptions.OrientToView = true;
                importOptions.Placement    = ImportPlacement.Origin;
                doc.Import(fileName, importOptions, importView, out importInstanceId);
                if (importInstanceId != null)
                {
                    explodeImportInstance();
                }
                uidoc.RefreshActiveView();


                curCurveElementIds.Clear();
                FilteredElementCollector curElementDocFilter = new FilteredElementCollector(doc);
                if (curElementDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curElementDocFilter.OfClass(typeof(CurveElement)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curCurveElementIds.Add(curElementsIdsIterator.Current);
                    }
                }

                curTextNotesIds.Clear();
                FilteredElementCollector curDocFilter = new FilteredElementCollector(doc);
                if (curDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curDocFilter.OfClass(typeof(TextNote)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curTextNotesIds.Add(curElementsIdsIterator.Current);
                    }
                }

                curTextNoteTypesIds.Clear();
                FilteredElementCollector curTextNoteTypeDocFilter = new FilteredElementCollector(doc);
                if (curTextNoteTypeDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curTextNoteTypeDocFilter.OfClass(typeof(TextNoteType)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curTextNoteTypesIds.Add(curElementsIdsIterator.Current);
                    }
                }

                Category curLinesStyles = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                foreach (Category curLineCategory in curLinesStyles.SubCategories)
                {
                    curLineCategoriesIds.Add(curLineCategory.Id);
                }


                curGraphycStyleIds.Clear();
                FilteredElementCollector curGraphycsStyleDocFilter = new FilteredElementCollector(doc);
                if (curGraphycsStyleDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curGraphycsStyleDocFilter.OfClass(typeof(GraphicsStyle)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        GraphicsStyle curGraphicsStyle = doc.GetElement(curElementsIdsIterator.Current) as GraphicsStyle;
                        if (curGraphicsStyle != null)
                        {
                            if (curLineCategoriesIds.Contains(curGraphicsStyle.GraphicsStyleCategory.Id))
                            {
                                curGraphycStyleIds.Add(curElementsIdsIterator.Current);
                            }
                        }
                    }
                }
                #endregion

                difCurveElementIds.Clear();
                difCurveElementIds.UnionWith(curCurveElementIds);
                difCurveElementIds.ExceptWith(preCurveElementIds);

                difTextNotesIds.Clear();
                difTextNotesIds.UnionWith(curTextNotesIds);
                difTextNotesIds.ExceptWith(preTextNotesIds);

                difTextNoteTypesIds.Clear();
                difTextNoteTypesIds.UnionWith(curTextNoteTypesIds);
                difTextNoteTypesIds.ExceptWith(preTextNoteTypesIds);

                difLineCategoriesIds.Clear();
                difLineCategoriesIds.UnionWith(curLineCategoriesIds);
                difLineCategoriesIds.ExceptWith(preLineCategoriesIds);

                difGraphycStyleIds.Clear();
                difGraphycStyleIds.UnionWith(curGraphycStyleIds);
                difGraphycStyleIds.ExceptWith(preGraphycStyleIds);


                foreach (Category curLineCategory in curLinesStyles.SubCategories)
                {
                    if (difLineCategoriesIds.Contains(curLineCategory.Id))
                    {
                        Color curColor = curLineCategory.LineColor;
                        Tuple <byte, byte, byte> curColorTuple = new Tuple <byte, byte, byte>(curColor.Red, curColor.Green, curColor.Blue);

                        if (autocadColorLineStylesDict.ContainsKey(curColorTuple))
                        {
                            autocadColorLineStylesDict[curColorTuple].Add(curLineCategory);
                        }
                        else
                        {
                            List <Category> norList = new List <Category>();
                            norList.Add(curLineCategory);
                            autocadColorLineStylesDict.Add(curColorTuple, norList);
                        }
                    }
                }

                #region
                Autodesk.Revit.DB.Options geoOptions = uiapp.Application.Create.NewGeometryOptions();
                geoOptions.ComputeReferences = true;
                FilteredElementCollector curElementsDocFilter = new FilteredElementCollector(doc);
                if (curElementsDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curElementsDocFilter.WhereElementIsNotElementType().GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        ElementId curElementId = curElementsIdsIterator.Current;
                        if (curElementId != null)
                        {
                            Element curElement = doc.GetElement(curElementId);
                            if (curElement != null)
                            {
                                GeometryElement curGeometryElement = curElement.get_Geometry(geoOptions);
                                if (curGeometryElement != null)
                                {
                                    foreach (GeometryObject curGeometryObject in curGeometryElement)
                                    {
                                        ElementId curGraphicsStyleId = curGeometryObject.GraphicsStyleId;
                                        if (curGraphicsStyleId != null)
                                        {
                                            GraphicsStyle curGraphicsStyle = doc.GetElement(curGraphicsStyleId) as GraphicsStyle;
                                            if (curGraphicsStyle != null)
                                            {
                                                string curGraphicsStyleName = curGraphicsStyle.Name;

                                                Category curGraphicsStyleCategory = curGraphicsStyle.GraphicsStyleCategory;
                                                if (curGraphicsStyleCategory != null)
                                                {
                                                    string curGraphicsStyleCategoryName = curGraphicsStyleCategory.Name;

                                                    if (this.curGraphicsStylesNamesCount.ContainsKey(curGraphicsStyleCategoryName))
                                                    {
                                                        this.curGraphicsStylesNamesCount[curGraphicsStyleCategoryName]++;
                                                    }
                                                    else
                                                    {
                                                        this.curGraphicsStylesNamesCount.Add(curGraphicsStyleCategoryName, 1);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion


                CadDetailConverterOutputForm outputForm = new CadDetailConverterOutputForm(this);
                outputForm.ShowDialog();

                uiapp.Idling += uiapp_Idling;
            }
        }
Esempio n. 15
0
File: COVER.cs Progetto: nixz/covise
 COVER()
 {
     mOptions = new Autodesk.Revit.DB.Options();
      mOptions.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine;
 }
Esempio n. 16
0
        /// <summary>
        /// Get all of the Geometry associated with this object
        /// </summary>
        public object[] Geometry()
        {
            Autodesk.Revit.DB.Element thisElement = InternalElement;

            var instanceGeometryObjects = new List<Autodesk.Revit.DB.GeometryObject>();

            var geoOptionsOne = new Autodesk.Revit.DB.Options();
            geoOptionsOne.ComputeReferences = true;

            var geomObj = thisElement.get_Geometry(geoOptionsOne);
            var geomElement = geomObj as GeometryElement;

            if ((thisElement is GenericForm) && (geomElement.Count() < 1))
            {
                GenericForm gF = (GenericForm)thisElement;
                if (!gF.Combinations.IsEmpty)
                {
                    Autodesk.Revit.DB.Options geoOptionsTwo = new Autodesk.Revit.DB.Options();
                    geoOptionsTwo.IncludeNonVisibleObjects = true;
                    geoOptionsTwo.ComputeReferences = true;
                    geomObj = thisElement.get_Geometry(geoOptionsTwo);
                    geomElement = geomObj as GeometryElement;
                }
            }

            foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
            {
                GeometryInstance ginsta = geob as GeometryInstance;
                if (ginsta != null)
                {
                    Autodesk.Revit.DB.GeometryElement instanceGeom = ginsta.GetInstanceGeometry();
                    instanceGeometryObjects.Add(instanceGeom);
                    foreach (Autodesk.Revit.DB.GeometryObject geobInst in instanceGeom)
                    {
                        instanceGeometryObjects.Add(geobInst);
                    }
                }
                else
                {
                    instanceGeometryObjects.Add(geob);
                }
            }

            return instanceGeometryObjects.Select(x =>
            {
                object w = x.Convert();
                if (w != null) return w;
                return x.Wrap();
            }).ToArray();
        }
Esempio n. 17
0
 public static new bool IsValidElement(DB.Element element)
 {
     using (var options = new DB.Options())
         return(!(element.get_Geometry(options) is null));
 }
Esempio n. 18
0
        internal IEnumerable<Autodesk.Revit.DB.GeometryObject> InternalGeometry()
        {
            var thisElement = InternalElement;

            var instanceGeometryObjects = new List<Autodesk.Revit.DB.GeometryObject>();

            var geoOptionsOne = new Autodesk.Revit.DB.Options();
            geoOptionsOne.ComputeReferences = true;

            var geomObj = thisElement.get_Geometry(geoOptionsOne);
            var geomElement = geomObj as GeometryElement;

            if ((thisElement is GenericForm) && (geomElement.Count() < 1))
            {
                var gF = (GenericForm)thisElement;
                if (!gF.Combinations.IsEmpty)
                {
                    var geoOptionsTwo = new Autodesk.Revit.DB.Options();
                    geoOptionsTwo.IncludeNonVisibleObjects = true;
                    geoOptionsTwo.ComputeReferences = true;
                    geomObj = thisElement.get_Geometry(geoOptionsTwo);
                    geomElement = geomObj as GeometryElement;
                }
            }

            foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
            {
                var ginsta = geob as GeometryInstance;
                if (ginsta != null)
                {
                    Autodesk.Revit.DB.GeometryElement instanceGeom = ginsta.GetInstanceGeometry();
                    instanceGeometryObjects.Add(instanceGeom);
                    foreach (Autodesk.Revit.DB.GeometryObject geobInst in instanceGeom)
                    {
                        instanceGeometryObjects.Add(geobInst);
                    }
                }
                else
                {
                    instanceGeometryObjects.Add(geob);
                }
            }

            return instanceGeometryObjects;
        }
Esempio n. 19
0
        private Autodesk.Revit.DB.GeometryElement GetGeometryElement()
        {
            var geoOptions = new Autodesk.Revit.DB.Options()
            {
                ComputeReferences = true
            };
            var geomObj = InternalForm.get_Geometry(geoOptions);

            if (geomObj == null)
            {
                throw new Exception("Could not obtain geometry from element");
            }

            return geomObj;
        }
Esempio n. 20
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            var elements = new List <DB.Element>();

            if (!DA.GetDataList("Elements", elements) || elements.Count == 0)
            {
                return;
            }

            var exclude   = new List <DB.Element>();
            var _Exclude_ = Params.IndexOfInputParam("Exclude");

            if (_Exclude_ >= 0)
            {
                DA.GetDataList(_Exclude_, exclude);
            }

            var view   = default(DB.View);
            var _View_ = Params.IndexOfInputParam("View");

            if (!DA.GetData(_View_, ref view))
            {
                return;
            }

            if (!TryGetCommonDocument(elements.Concat(exclude).Concat(Enumerable.Repeat(view, 1)), out var doc))
            {
                return;
            }

            using (var options = new DB.Options()
            {
                View = view
            })
            {
                var _Geometry_ = Params.IndexOfOutputParam("Geometry");
                SolveGeometry
                (
                    DA.ParameterTargetPath(_Geometry_),
                    doc,
                    elements,
                    exclude,
                    options,
                    out var Geometry
                );

                DA.SetDataTree(_Geometry_, Geometry);

                var _Categories_ = Params.IndexOfOutputParam("Categories");
                var Categories   = _Categories_ >= 0 ? new GH_Structure <Types.Category>() : default;

                var _Materials_ = Params.IndexOfOutputParam("Materials");
                var Materials   = _Materials_ >= 0 ? new GH_Structure <Types.Material>() : default;

                SolveAttributes(doc, Geometry, Categories, Materials);

                if (Categories is object)
                {
                    DA.SetDataTree(_Categories_, Categories);
                }

                if (Materials is object)
                {
                    DA.SetDataTree(_Materials_, Materials);
                }
            }
        }
Esempio n. 21
0
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            Element thisElement = (Element)((FScheme.Value.Container)args[0]).Item;

            ElementId thisId = ElementId.InvalidElementId;

            if (thisElement != null)
            {
                thisId = thisElement.Id;
                instanceSolids[thisId] = new List<GeometryObject>();
            }

            Solid mySolid = null;

            //because of r2013 used GenericForm  which is superclass of FreeFromElement
            if ((thisElement is GenericForm) && (FreeForm.freeFormSolids != null &&
                  FreeForm.freeFormSolids.ContainsKey(thisElement.Id)))
            {
                mySolid = FreeForm.freeFormSolids[thisElement.Id];
            }
            else
            {
                bool bNotVisibleOption = false;
                if (thisElement is GenericForm)
                {
                    GenericForm gF = (GenericForm)thisElement;
                    if (!gF.Combinations.IsEmpty)
                        bNotVisibleOption = true;
                }
                int nTry = (bNotVisibleOption) ? 2 : 1;
                for (int iTry = 0; iTry < nTry && (mySolid == null); iTry++)
                {
                    Autodesk.Revit.DB.Options geoOptions = new Autodesk.Revit.DB.Options();
                    geoOptions.ComputeReferences = true;
                    if (bNotVisibleOption && (iTry == 1))
                        geoOptions.IncludeNonVisibleObjects = true;

                    GeometryObject geomObj = thisElement.get_Geometry(geoOptions);
                    GeometryElement geomElement = geomObj as GeometryElement;

                    if (geomElement != null)
                    {
                        foreach (GeometryObject geob in geomElement)
                        {
                            GeometryInstance ginsta = geob as GeometryInstance;
                            if (ginsta != null && thisId != ElementId.InvalidElementId)
                            {
                                GeometryElement instanceGeom = ginsta.GetInstanceGeometry();

                                instanceSolids[thisId].Add(instanceGeom);

                                foreach (GeometryObject geobInst in instanceGeom)
                                {
                                    mySolid = geobInst as Solid;
                                    if (mySolid != null)
                                    {
                                        FaceArray faceArr = mySolid.Faces;
                                        var thisEnum = faceArr.GetEnumerator();
                                        bool hasFace = false;
                                        for (; thisEnum.MoveNext(); )
                                        {
                                            hasFace = true;
                                            break;
                                        }
                                        if (!hasFace)
                                            mySolid = null;
                                        else
                                            break;
                                    }
                                }
                                if (mySolid != null)
                                    break;
                            }
                            else
                            {
                                mySolid = geob as Solid;
                                if (mySolid != null)
                                {
                                    FaceArray faceArr = mySolid.Faces;
                                    var thisEnum = faceArr.GetEnumerator();
                                    bool hasFace = false;
                                    for (; thisEnum.MoveNext(); )
                                    {
                                        hasFace = true;
                                        break;
                                    }
                                    if (!hasFace)
                                        mySolid = null;
                                    else
                                        break;
                                }

                            }
                        }
                    }
                }
            }

            return FScheme.Value.NewContainer(mySolid);
        }
Esempio n. 22
0
        /// <summary>
        /// Judge whether an element has face geometry
        /// </summary>
        /// <param name="elem">the element to be checked</param>
        /// <returns>true is having face geometry, false is having no face geometry</returns>
        private bool CheckSelectedElement(RevitElement elem)
        {
            if(null == elem)
            {
                return false;
            }
            Autodesk.Revit.DB.Options opts = new Autodesk.Revit.DB.Options();
            opts.View = m_revitDoc.Document.ActiveView;
            opts.ComputeReferences = true;
            // Get geometry of the element
            GeoElement geoElement = elem.get_Geometry(opts);
            InquireGeometry(geoElement, elem);

            return true;
        }
Esempio n. 23
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            if (!Params.TryGetData(DA, "Detail Level", out DB.ViewDetailLevel? detailLevel))
            {
                return;
            }
            if (!Params.GetDataList(DA, "Elements", out IList <Types.Element> elements))
            {
                return;
            }
            if (!Params.TryGetDataList(DA, "Exclude", out IList <Types.Element> exclude))
            {
                return;
            }

            if (!detailLevel.HasValue)
            {
                detailLevel = DB.ViewDetailLevel.Coarse;
            }

            if (!TryGetCommonDocument(elements.Concat(exclude ?? Enumerable.Empty <Types.Element>()), out var doc))
            {
                return;
            }

            using (var options = new DB.Options()
            {
                DetailLevel = detailLevel.Value
            })
            {
                Params.TrySetDataList(DA, "Elements", () => elements);

                var _Geometry_ = Params.IndexOfOutputParam("Geometry");
                SolveGeometry
                (
                    DA.ParameterTargetPath(_Geometry_),
                    doc,
                    elements,
                    exclude,
                    options,
                    out var Geometry
                );
                DA.SetDataTree(_Geometry_, Geometry);

                var _Categories_ = Params.IndexOfOutputParam("Categories");
                var Categories   = _Categories_ >= 0 ? new GH_Structure <Types.Category>() : default;

                var _Materials_ = Params.IndexOfOutputParam("Materials");
                var Materials   = _Materials_ >= 0 ? new GH_Structure <Types.Material>() : default;

                SolveAttributes(doc, Geometry, Categories, Materials);

                if (Categories is object)
                {
                    DA.SetDataTree(_Categories_, Categories);
                }

                if (Materials is object)
                {
                    DA.SetDataTree(_Materials_, Materials);
                }
            }
        }
        public new bool BakeElement
        (
            IDictionary <DB.ElementId, Guid> idMap,
            bool overwrite,
            RhinoDoc doc,
            ObjectAttributes att,
            out Guid guid
        )
        {
            // 1. Check if is already cloned
            if (idMap.TryGetValue(Id, out guid))
            {
                return(true);
            }

            // 3. Update if necessary
            if (Value is DB.FamilyInstance element)
            {
                using (var options = new DB.Options()
                {
                    DetailLevel = DB.ViewDetailLevel.Fine
                })
                {
                    using (var context = GeometryDecoder.Context.Push())
                    {
                        context.Element         = element;
                        context.GraphicsStyleId = element.Category?.GetGraphicsStyle(DB.GraphicsStyleType.Projection)?.Id ?? DB.ElementId.InvalidElementId;
                        context.MaterialId      = element.Category?.Material?.Id ?? DB.ElementId.InvalidElementId;

                        using (var geometry = element.GetGeometry(options))
                        {
                            if (geometry is DB.GeometryElement geometryElement)
                            {
                                var transform      = element.GetTransform();
                                var location       = new Plane(transform.Origin.ToPoint3d(), transform.BasisX.ToVector3d(), transform.BasisY.ToVector3d());
                                var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);

                                if (BakeGeometryElement(idMap, overwrite, doc, att, worldToElement, element, geometry, out var idefIndex))
                                {
                                    att      = att.Duplicate();
                                    att.Name = element.get_Parameter(DB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
                                    att.Url  = element.get_Parameter(DB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;

                                    var category = Category;
                                    if (category is object && category.BakeElement(idMap, false, doc, att, out var layerGuid))
                                    {
                                        att.LayerIndex = doc.Layers.FindId(layerGuid).Index;
                                    }

                                    guid = doc.Objects.AddInstanceObject(idefIndex, Transform.PlaneToPlane(Plane.WorldXY, location), att);
                                }
                            }

                            if (guid != Guid.Empty)
                            {
                                idMap.Add(Id, guid);
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 25
0
        AddObjectsToTree(Element elem, TreeNodeCollection curNodes)
        {
            Autodesk.Revit.DB.Options geomOp = m_app.Create.NewGeometryOptions();
            geomOp.ComputeReferences = true;
            TreeNode tmpNode;

            // add geometry with the View set to null.
            TreeNode rootNode1 = new TreeNode("View = null");

            curNodes.Add(rootNode1);

            tmpNode            = new TreeNode("Detail Level = Undefined");
            geomOp.DetailLevel = ViewDetailLevel.Undefined;
            tmpNode.Tag        = elem.get_Geometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Coarse");
            geomOp.DetailLevel = ViewDetailLevel.Coarse;
            tmpNode.Tag        = elem.get_Geometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Medium");
            geomOp.DetailLevel = ViewDetailLevel.Medium;
            tmpNode.Tag        = elem.get_Geometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Fine");
            geomOp.DetailLevel = ViewDetailLevel.Fine;
            tmpNode.Tag        = elem.get_Geometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            // SOFiSTiK FS
            // add model geometry including geometry objects not set as Visible.
            {
                Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
                opts.ComputeReferences        = true;
                opts.IncludeNonVisibleObjects = true;

                TreeNode rootNode = new TreeNode("View = null - Including geometry objects not set as Visible");
                curNodes.Add(rootNode);

                tmpNode          = new TreeNode("Detail Level = Undefined");
                opts.DetailLevel = ViewDetailLevel.Undefined;
                tmpNode.Tag      = elem.get_Geometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Coarse");
                opts.DetailLevel = ViewDetailLevel.Coarse;
                tmpNode.Tag      = elem.get_Geometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Medium");
                opts.DetailLevel = ViewDetailLevel.Medium;
                tmpNode.Tag      = elem.get_Geometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Fine");
                opts.DetailLevel = ViewDetailLevel.Fine;
                tmpNode.Tag      = elem.get_Geometry(opts);
                rootNode.Nodes.Add(tmpNode);
            }

            // now add geometry with the View set to the current view
            if (elem.Document.ActiveView != null)
            {
                Options geomOp2 = m_app.Create.NewGeometryOptions();
                geomOp2.ComputeReferences = true;
                geomOp2.View = elem.Document.ActiveView;

                TreeNode rootNode2 = new TreeNode("View = Document.ActiveView");
                rootNode2.Tag = elem.get_Geometry(geomOp2);
                curNodes.Add(rootNode2);

                // SOFiSTiK FS
                // add model geometry including geometry objects not set as Visible.
                {
                    Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
                    opts.ComputeReferences        = true;
                    opts.IncludeNonVisibleObjects = true;
                    opts.View = elem.Document.ActiveView;

                    TreeNode rootNode = new TreeNode("View = Document.ActiveView - Including geometry objects not set as Visible");
                    curNodes.Add(rootNode);

                    rootNode.Tag = elem.get_Geometry(opts);
                }
            }
        }
        public static void BuildPreview
        (
            DB.Element element, MeshingParameters meshingParameters, DB.ViewDetailLevel DetailLevel,
            out Rhino.Display.DisplayMaterial[] materials, out Mesh[] meshes, out Curve[] wires
        )
        {
            DB.Options options = null;
            using (var geometry = element?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out options)) using (options)
                {
                    if (geometry is null)
                    {
                        materials = null;
                        meshes    = null;
                        wires     = null;
                    }
                    else
                    {
                        var categoryMaterial = element.Category?.Material.ToDisplayMaterial(null);
                        var elementMaterial  = geometry.MaterialElement.ToDisplayMaterial(categoryMaterial);

                        meshes    = geometry.GetPreviewMeshes(meshingParameters).Where(x => x is object).ToArray();
                        wires     = geometry.GetPreviewWires().Where(x => x is object).ToArray();
                        materials = geometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object).ToArray();

                        if (meshes.Length == 0 && wires.Length == 0 && element.get_BoundingBox(null) is DB.BoundingBoxXYZ)
                        {
                            var subMeshes    = new List <Mesh>();
                            var subWires     = new List <Curve>();
                            var subMaterials = new List <Rhino.Display.DisplayMaterial>();

                            foreach (var dependent in element.GetDependentElements(null).Select(x => element.Document.GetElement(x)))
                            {
                                if (dependent.get_BoundingBox(null) is null)
                                {
                                    continue;
                                }

                                DB.Options dependentOptions = null;
                                using (var dependentGeometry = dependent?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out dependentOptions)) using (dependentOptions)
                                    {
                                        if (dependentGeometry is object)
                                        {
                                            subMeshes.AddRange(dependentGeometry.GetPreviewMeshes(meshingParameters).Where(x => x is object));
                                            subWires.AddRange(dependentGeometry.GetPreviewWires().Where(x => x is object));
                                            subMaterials.AddRange(dependentGeometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object));
                                        }
                                    }
                            }

                            meshes    = subMeshes.ToArray();
                            wires     = subWires.ToArray();
                            materials = subMaterials.ToArray();
                        }

                        foreach (var mesh in meshes)
                        {
                            mesh.Normals.ComputeNormals();
                        }
                    }
                }
        }