Пример #1
0
        internal ImportInstance(string satPath, XYZ translation = null)
        {
            translation = translation ?? XYZ.Zero;

            TransactionManager.Instance.EnsureInTransaction(Document);

            var options = new SATImportOptions()
            {
                Unit = ImportUnit.Foot
            };

            var id = Document.Import(satPath, options, Document.ActiveView);
            var element = Document.GetElement(id);
            var importInstance = element as Autodesk.Revit.DB.ImportInstance;

            if (importInstance == null)
            {
                throw new Exception("Could not obtain ImportInstance from imported Element");
            }

            InternalSetImportInstance(importInstance);
            InternalUnpinAndTranslateImportInstance(translation);

            this.Path = satPath;

            TransactionManager.Instance.TransactionTaskDone();
        }
Пример #2
0
        internal ImportInstance(string satPath, XYZ translation = null)
        {
            translation = translation ?? XYZ.Zero;

            TransactionManager.Instance.EnsureInTransaction(Document);

            var options = new SATImportOptions()
            {
                Unit = ImportUnit.Foot
            };

            var id             = Document.Import(satPath, options, Document.ActiveView);
            var element        = Document.GetElement(id);
            var importInstance = element as Autodesk.Revit.DB.ImportInstance;

            if (importInstance == null)
            {
                throw new Exception("Could not obtain ImportInstance from imported Element");
            }

            InternalSetImportInstance(importInstance);
            InternalUnpinAndTranslateImportInstance(translation);

            this.Path = satPath;

            TransactionManager.Instance.TransactionTaskDone();
        }
Пример #3
0
        public void ProcessMultipleSAT()
        {
            List <ElementId> importIds = new List <ElementId>();

            // create and set new SAT options
            SATImportOptions satOptions = new SATImportOptions();

            satOptions.Placement = ImportPlacement.Origin;
            satOptions.ColorMode = ImportColorMode.BlackAndWhite;
            satOptions.Unit      = ImportUnit.Millimeter;

            using (Transaction trans = new Transaction(m_doc, "UpdateSAT"))
            {
                trans.Start();

                List <GeometryObject> geoObjList = new List <GeometryObject>();
                DirectShape           ds         = null;
                ElementId             currentId;

                try
                {
                    currentId = m_doc.Import(@"B:\Rhino\OpenNURBS\v5_example_file.sat", satOptions, m_doc.ActiveView);
                    importIds.Add(currentId);
                }
                catch (Exception)
                {
                    currentId = ElementId.InvalidElementId;
                }
                // extract geometry from import instance
                ImportInstance ii       = m_doc.GetElement(currentId) as ImportInstance;
                Options        gOptions = new Options();
                gOptions.ComputeReferences = true;
                GeometryElement geoElement = ii.get_Geometry(gOptions);

                // get solids from geometry element
                List <GeometryObject> tempGeoList = FindElementGeometry(geoElement);
                foreach (GeometryObject go in tempGeoList)
                {
                    geoObjList.Add(go);
                }


                ds = DirectShape.CreateElement(m_doc, new ElementId((int)BuiltInCategory.OST_GenericModel));
                ds.SetShape(geoObjList);

                // set the Direct Shape options
                DirectShapeOptions dsOptions = ds.GetOptions();
                dsOptions.ReferencingOption = DirectShapeReferencingOption.Referenceable;
                ds.SetOptions(dsOptions);

                trans.Commit();

                trans.Start("Delete Elements");
                // clean up imported solids
                m_doc.Delete(importIds);
                trans.Commit();
            }
        }
Пример #4
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Document       document       = commandData.get_Application().get_ActiveUIDocument().get_Document();
            FileOpenDialog fileOpenDialog = new FileOpenDialog("SAT file (*.sat)|*.sat");

            ((FileDialog)fileOpenDialog).set_Title("Select SAT file to import");
            ((FileDialog)fileOpenDialog).Show();
            ModelPath selectedModelPath = ((FileDialog)fileOpenDialog).GetSelectedModelPath();

            ((FileDialog)fileOpenDialog).Dispose();
            string           userVisiblePath  = ModelPathUtils.ConvertModelPathToUserVisiblePath(selectedModelPath);
            SATImportOptions satImportOptions = new SATImportOptions();
            View             element          = new FilteredElementCollector(document).OfClass(typeof(View)).ToElements()[0] as View;

            try
            {
                using (Transaction transaction = new Transaction(document, "Import SAT"))
                {
                    transaction.Start();
                    ElementId elementId = document.Import(userVisiblePath, satImportOptions, element);
                    using (IEnumerator <GeometryObject> enumerator1 = document.GetElement(elementId).get_Geometry(new Options()).GetEnumerator())
                    {
                        while (((IEnumerator)enumerator1).MoveNext())
                        {
                            using (IEnumerator <GeometryObject> enumerator2 = (enumerator1.Current as GeometryInstance).get_SymbolGeometry().GetEnumerator())
                            {
                                while (((IEnumerator)enumerator2).MoveNext())
                                {
                                    Solid current = enumerator2.Current as Solid;
                                    FreeFormElement.Create(document, current);
                                }
                            }
                        }
                    }
                    document.Delete(elementId);
                    transaction.Commit();
                }
                return((Result)0);
            }
            catch
            {
                TaskDialog.Show("Error Importing", "Something went wrong");
                return((Result) - 1);
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize an ImportInstance element
        /// </summary>
        /// <param name="satPath"></param>
        /// <param name="translation"></param>
        /// <param name="view"></param>
        private void InitImportInstance(string satPath, Revit.Elements.Views.View view, XYZ translation = null)
        {
            var instance = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ImportInstance>(Document);

            if (null != instance)
            {
                DocumentManager.Instance.DeleteElement(new ElementUUID(instance.UniqueId));
            }

            translation = translation ?? XYZ.Zero;

            TransactionManager.Instance.EnsureInTransaction(Document);

            var options = new SATImportOptions()
            {
                Unit = ImportUnit.Foot
            };

            var id = null != view?Document.Import(satPath, options, view.InternalView) : Document.Import(satPath, options, Document.ActiveView);

            var element        = Document.GetElement(id);
            var importInstance = element as Autodesk.Revit.DB.ImportInstance;

            if (importInstance == null)
            {
                throw new Exception(Properties.Resources.InstanceImportFailure);
            }

            InternalSetImportInstance(importInstance);
            InternalUnpinAndTranslateImportInstance(translation);

            this.Path = satPath;

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(importInstance);
        }
Пример #6
0
        private void ConvertSAT2RFA()
        {
            // the template is included into the appbundle
            string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string fullPath     = Path.Combine(assemblyPath, RFA_TEMPLATE);

            //Get the document from the data(i.e) template file document
            Document doc = _rvtApp.NewFamilyDocument(fullPath);

            //check document is not null
            if (doc == null)
            {
                throw new InvalidOperationException("Could not create family.");
            }

            //Create the transaction as we are going to modify the document by importing the family file
            //Import SAT file into template file
            using (Transaction transaction = new Transaction(doc))
            {
                //Start the transaction
                transaction.Start("CONVERTING SAT TO RFA FILE");

                //FailureHandlingOptions will collect those warnings which occurs while importing the SAT file and deletes those warning
                //These warnings occurs because all the data from the SAT file cannot be converted to revit family file(.rfa file)
                //For simple SAT files((i.e)SAT file of a Box) these type of warnings won't occur.
                FailureHandlingOptions FH_options = transaction.GetFailureHandlingOptions();
                FH_options.SetFailuresPreprocessor(new Warning_Swallower());
                transaction.SetFailureHandlingOptions(FH_options);

                //Create SATImportOptions
                //It help you to import the .sat files
                SATImportOptions SAT_IOption = new SATImportOptions();
                SAT_IOption.VisibleLayersOnly = false;
                SAT_IOption.Placement         = ImportPlacement.Centered;
                SAT_IOption.ColorMode         = ImportColorMode.Preserved;
                SAT_IOption.Unit = ImportUnit.Default;

                //get the perfect view for the placement of imported SAT file(i.e REF.LEVEL)
                //Collect all the views and get the view named as "Ref. Level" where we are going to import the sat file
                FilteredElementCollector view_collector = new FilteredElementCollector(doc).OfClass(typeof(View)).WhereElementIsNotElementType();
                IList <ElementId>        view_ids       = view_collector.ToElementIds() as IList <ElementId>;
                View view = null;
                foreach (ElementId view_id in view_ids)
                {
                    View v = doc.GetElement(view_id) as View;
                    if (v.Name.Contains("Ref. Level") && v != null)
                    {
                        view = v;
                    }
                }

                //import the .SAT file to family template file ((i.e)Metric Generic Model.rft)
                doc.Import(SAT_INPUT, SAT_IOption, view);

                //After importing
                //to save the changes commit the transaction
                transaction.Commit();
            }

            //save the imported .SAT file as .RFA file
            //If the family file(.rfa) with same name  already exists in the rfa_path,overwrite the already existing family file with the modified family file
            ModelPath     RFAmodelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(RFA_TEMP);
            SaveAsOptions SAO          = new SaveAsOptions();

            SAO.OverwriteExistingFile = true;

            //Save the familyfile
            doc.SaveAs(RFAmodelPath, SAO);

            doc.Close();
        }
Пример #7
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            //Create folder dialog path
            FileOpenDialog file_dia = new FileOpenDialog("SAT file (*.sat)|*.sat");

            file_dia.Title = "Select SAT file to import";
            file_dia.Show();
            ModelPath path = file_dia.GetSelectedModelPath();

            file_dia.Dispose();

            //Convert file path to a string
            string path_str = ModelPathUtils.ConvertModelPathToUserVisiblePath(path);

            SATImportOptions satOpt = new SATImportOptions();

            FilteredElementCollector filEle = new FilteredElementCollector(doc);

            IList <Element> views = filEle.OfClass(typeof(View)).ToElements();

            View import_view = views[0] as View;

            try
            {
                using (Transaction trans = new Transaction(doc, "Import SAT"))
                {   // Start transaction, import SAT file and get the element
                    trans.Start();
                    ElementId importedElementId = doc.Import(path_str, satOpt, import_view);
                    Element   importedElement   = doc.GetElement(importedElementId);

                    //Extract geometry element from the imported element
                    Options         geoOptions       = new Options();
                    GeometryElement importedGeometry = importedElement.get_Geometry(geoOptions);


                    //Iterate through the geometry elements extracting the geometry as individual elements
                    foreach (GeometryObject geoObj in importedGeometry)
                    {
                        GeometryInstance instance = geoObj as GeometryInstance;
                        foreach (GeometryObject instObj in instance.SymbolGeometry)
                        {
                            Solid solid = instObj as Solid;
                            FreeFormElement.Create(doc, solid);
                        }
                    }

                    //Delete SAT file

                    doc.Delete(importedElementId);
                    trans.Commit();
                }

                return(Result.Succeeded);
            }

            catch
            {
                TaskDialog.Show("Error Importing", "Something went wrong");
                return(Result.Failed);
            }
        }