예제 #1
0
        public static List<DecalData> GetDecalsFromDocument(Document doc)
        {
            var ids = ExternalFileUtils.GetAllExternalFileReferences(doc);
            var decalIds = (from id in ids
                            let ext = ExternalFileUtils.GetExternalFileReference(doc, id)
                            where ext != null && ext.ExternalFileReferenceType == ExternalFileReferenceType.Decal
                            select id);

            var collector = new FilteredElementCollector(doc);
            var elems = collector.OfCategory(BuiltInCategory.OST_GenericModel)
                .WhereElementIsNotElementType().ToElements();
            var decals = elems.Where(e => decalIds.Contains(e.GetTypeId())).ToList();

            var result = new List<DecalData>();
            var op = new Options();
            op.DetailLevel = ViewDetailLevel.Medium;
            foreach (var decal in decals)
            {
                var points = new List<PointData>();
                var geoElement = decal.get_Geometry(op);
                foreach (GeometryObject go in geoElement)
                {
                    if (go is Line line)
                    {
                        var ptStart = line.GetEndPoint(0);
                        points.Add(new PointData(ptStart.X, ptStart.Y, ptStart.Z));
                    }
                }
                if (points.Count != 4)
                    continue;

                var ext = ExternalFileUtils.GetExternalFileReference(doc, decal.GetTypeId());
                if (ext == null)
                    continue;

                result.Add(new DecalData
                {
                    Points = points,
                    MapFileName = ModelPathUtils.ConvertModelPathToUserVisiblePath(ext.GetPath())
                });
            }

            return result;
        }
예제 #2
0
        /// <summary>
        /// Remove DWF links from model and return
        /// the total number of deleted elements.
        /// </summary>
        int RemoveDwfLinkUsingExternalFileUtils(
            Document doc)
        {
            List <ElementId> idsToDelete
                = new List <ElementId>();

            ICollection <ElementId> ids = ExternalFileUtils
                                          .GetAllExternalFileReferences(doc);

            foreach (ElementId id in ids)
            {
                Element e = doc.GetElement(id);

                Debug.Print(Util.ElementDescription(e));

                ExternalFileReference xr = ExternalFileUtils
                                           .GetExternalFileReference(doc, id);

                ExternalFileReferenceType xrType
                    = xr.ExternalFileReferenceType;

                if (xrType == ExternalFileReferenceType.DWFMarkup)
                {
                    ModelPath xrPath = xr.GetPath();

                    string path = ModelPathUtils
                                  .ConvertModelPathToUserVisiblePath(xrPath);

                    if (path.EndsWith(".dwf") ||
                        path.EndsWith(".dwfx"))
                    {
                        idsToDelete.Add(id);
                    }
                }
            }

            int n = idsToDelete.Count;

            ICollection <ElementId> idsDeleted = null;

            if (0 < n)
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Delete DWFx Links");

                    idsDeleted = doc.Delete(idsToDelete);

                    t.Commit();
                }
            }

            int m = (null == idsDeleted)
        ? 0
        : idsDeleted.Count;

            Debug.Print(string.Format(
                            "Selected {0} DWF external file reference{1}, "
                            + "{2} element{3} successfully deleted.",
                            n, Util.PluralSuffix(n), m, Util.PluralSuffix(m)));

            return(m);
        }