예제 #1
0
        /// <summary>
        /// Helper method to handle all linked files
        /// </summary>
        /// <param name="files">List of linked file data</param>
        /// <param name="ctSource">CancellationToken allows the exporter to detect when the user cancelled the export</param>
        /// <param name="failed">reference parameter for the failed state</param>
        /// <returns></returns>
        private bool RunLinkedFiles(List <IFCExporterLinkedFileData> files, ref int failed)
        {
            failed = 0;
            if (null == files || files.Count <= 0)
            {
                return(true);
            }

            // the following part is needed only when we close the active document (which we are not currently doing)
            //if (files.Any(x => x.Found))
            //{
            //	// there is at least one linked file
            //	UIDoc.Document.Save();
            //}

            // loop through the list of linked files and save them (if found) or log them (if not found)
            for (int count = 0; count < files.Count; count++)
            {
                IFCExporterLinkedFileData data = files[count];
                if (!data.Found)
                {
                    Cmd.ShowResult($"Linked file '{data.Path}' could not be found and is not exported to IFC");
                    failed += 1;
                    continue;
                }

                // we have a linked file. It should not be necessary to close the current project to open a new one
                //Cmd.IfcExporterApi.CloseDocument()
                UIDocument uidoc = UIDoc.Application.OpenAndActivateDocument(data.Path);
                if (null == uidoc?.Document)
                {
                    Cmd.ShowResult($"Linked file '{data.Path}' could not be activated for export");
                    failed += 1;
                    continue;
                }

                // this saves the IFC in the same location as the main file with the name of the linked file
                // this will overwrite existing files, especially if the linked file appears more than once in the list
                // but automatically renumbering is not a solution either as that creates new files with each run of this exporter
                try
                {
                    StartTransaction($"IFC Export {count + 1}", uidoc.Document);                       // run this transaction in the new document

                    string lpath = Path.Combine(SavePath, Path.GetFileName(data.Path) ?? $"LinkedFile_{count}");
                    Cmd.IfcExporter.SaveIfcDocument(lpath, ConfigurationName, uidoc.Document);

                    CommitTransaction();
                }
                catch (Exception ex)
                {
                    failed += 1;
                    RollbackTransaction();
                    Cmd.ShowResult($"Failed to export linked file '{data.Path}' to IFC ({ex.Message})");
                }
            }

            // if the docuemnt was closed open it again
            return(false);
        }
예제 #2
0
        internal List <IFCExporterLinkedFileData> GetAllLinkedFiles()
        {
            // this assumes that GetLinkInstances returns both found and missing instances otherwise we must write a different method to find the missing ones
            List <RevitLinkInstance> instances = GetLinkInstances();

            if (null == instances || instances.Count <= 0)
            {
                return(null);
            }

            XYZ viewDirection  = UIDoc.Document.ActiveView.ViewDirection;
            XYZ rightDirection = UIDoc.Document.ActiveView.RightDirection;

            List <IFCExporterLinkedFileData> res = new List <IFCExporterLinkedFileData>();

            foreach (RevitLinkInstance inst in instances)
            {
                // dit is een extension method?
                Document doc = inst.GetLinkDocument(UIDoc.Application);
                if (null == doc)
                {
                    continue;
                }

                string path = doc.PathName;
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                IFCExporterLinkedFileData data = new IFCExporterLinkedFileData(path);

                res.Add(data);
                if (!data.Found)
                {
                    continue;
                }

                List <BasePoint> points = ElementCollectionHelper.GetAllProjectElements(doc).OfType <BasePoint>().ToList();
                if (points.Count <= 0)
                {
                    continue;
                }

                Transform toWcs = inst.GetTotalTransform();

                foreach (BasePoint point in points)
                {
                    if (point.Category.Name != "Project Base Point")
                    {
                        continue;
                    }

                    XYZ    pOrg;
                    double hoek = toWcs.BasisX.AngleOnPlaneTo(rightDirection, viewDirection);
                    if (Math.Abs(Math.Round(hoek, 2)) > 1e-6)
                    {
                        //voor hoeken gaan we de survey punten op elkaar leggen. Dat verrekenen we verder op
                        pOrg = new XYZ(0, 0, 0);
                    }
                    else
                    {
                        //FamilyParametersHandler fph = new FamilyParametersHandler(point);

                        //ParameterHandler ph = fph.Get(BuiltInParameter.BASEPOINT_EASTWEST_PARAM);
                        //double x = ph?.AsRawDouble() ?? 0.0;
                        Parameter ph = point.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM);
                        double    x  = ph?.AsDouble() ?? 0.0;

                        //ph = fph.Get(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM);
                        //double y = ph?.AsRawDouble() ?? 0.0;
                        ph = point.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM);
                        double y = ph?.AsDouble() ?? 0.0;

                        //ph = fph.Get(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                        //double z = ph?.AsRawDouble() ?? 0.0;
                        ph = point.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                        double z = ph?.AsDouble() ?? 0.0;

                        pOrg = new XYZ(x, y, z);
                    }

                    XYZ p   = toWcs.OfPoint(pOrg);
                    XYZ pos = p - 2 * pOrg;

                    data.Angle    = hoek;
                    data.Position = pos;
                    break;
                }
            }

            return(res);
        }