示例#1
0
 /// <summary>
 /// Initialize RealDWG Environent for testing purpose.
 /// If the test code is executed in AutoCAD application, we don't need to initialize the customized ApplicationService,
 /// Otherwise, we create one.
 /// </summary>
 public static void InitializeRealDwgTestEnvironent()
 {
     if (Process.GetCurrentProcess().ProcessName != "acad")
     {
         Runtime.Initialize();
         _sDatabase = DatabaseUtilities.CreateDwg();
     }
 }
示例#2
0
        /// <summary>
        /// Determine if the unit of a DWG file is metric
        /// </summary>
        /// <param name="filePath">Full name of the DWG file to load.</param>
        public static bool IsMetricDwg(string filePath)
        {
            Database database = DatabaseUtilities.LoadDwg(filePath, readOnly: true, loadXrefs: false);
            UnitType unitType = DbUnitUtils.GetUnitType(database);

            DatabaseUtilities.CloseDwg(database);

            return(unitType == UnitType.Metric);
        }
示例#3
0
        /// <summary>
        /// Get Layer names from DWG
        /// </summary>
        /// <param name="filePath">Full name of the DWG file to load.</param>
        public static IEnumerable <string> GetDwgLayers(string filePath)
        {
            var database = DatabaseUtilities.LoadDwg(filePath, readOnly: true, loadXrefs: true);

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                // Start by populating the list of names/IDs of Layer
                var layerTable = (LayerTable)transaction.GetObject(database.LayerTableId, OpenMode.ForRead);
                foreach (var entId in layerTable)
                {
                    var dbObject         = transaction.GetObject(entId, OpenMode.ForRead);
                    var layerTableRecord = dbObject as LayerTableRecord;
                    if (layerTableRecord != null && layerTableRecord.IsErased == false)
                    {
                        yield return(layerTableRecord.Name);
                    }
                }
                transaction.Commit();
            }

            DatabaseUtilities.CloseDwg(database);
        }