Esempio n. 1
0
        private static ScheduleTable CreateScheduleTable(UiData uiData, ObjectId propertySetDefinitionId, ObjectId styleId, Transaction trans)
        {
            Database         db  = ScheduleSample.GetDatabase();
            BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

            ScheduleTable scheduleTable = new ScheduleTable();

            scheduleTable.SetToStandard(db);
            scheduleTable.SetDatabaseDefaults(db);
            scheduleTable.StyleId = styleId;
            scheduleTable.SetDefaultLayer();

            btr.AppendEntity(scheduleTable);
            trans.AddNewlyCreatedDBObject(scheduleTable, true);

            ObjectIdCollection selectionSet = new ObjectIdCollection();

            foreach (List <ObjectId> idSetByObjectType in uiData.classObjectIdsMap.Values)
            {
                foreach (ObjectId id in idSetByObjectType)
                {
                    selectionSet.Add(id);
                }
            }

            scheduleTable.SetSelectionSet(selectionSet, new ObjectIdCollection());
            scheduleTable.AutomaticUpdate = true;

            return(scheduleTable);
        }
Esempio n. 2
0
        public static IList <PolylineChildren> CreatePolylineChildren(ACADDB.ObjectIdCollection polylines)
        {
            IList <PolylineChildren> children = new List <PolylineChildren>();

            foreach (ACADDB.ObjectId polyoid in polylines)
            {
                ACADDB.ObjectIdCollection collection  = null;
                Point2dCollection         innerpoints = null;
                Point2dCollection         outerpoints = null;

                outerpoints = PlineToPoints(polyoid);
                collection  = new ACADDB.ObjectIdCollection();

                //Is Polyline within Outer Polyline
                foreach (ACADDB.ObjectId polyline in polylines)
                {
                    innerpoints = PlineToPoints(polyline);
                    if (PointUtilities.PointInPolyline(outerpoints, innerpoints))
                    {
                        collection.Add(polyline);
                    }
                }
                children.Add(new PolylineChildren(polyoid, collection));
            }


            return(children);
        }
Esempio n. 3
0
        static public ObjectIdCollection PickObjectSet(string tips)
        {
            Editor editor = GetEditor();
            PromptSelectionOptions options = new PromptSelectionOptions();

            options.MessageForAdding  = tips;
            options.MessageForRemoval = "Remove objects from selection";
            options.AllowDuplicates   = false;
            options.RejectObjectsFromNonCurrentSpace = true;
            options.RejectObjectsOnLockedLayers      = true;
            options.RejectPaperspaceViewport         = true;
            ObjectIdCollection ids = new ObjectIdCollection();

            PromptSelectionResult result = editor.GetSelection(options);

            if (result.Status == PromptStatus.OK)
            {
                SelectionSet set = result.Value;
                foreach (SelectedObject obj in set)
                {
                    ids.Add(obj.ObjectId);
                }
            }

            return(ids);
        }
        private static void SetDrawOrderInBlock(App.Document dwg, Db.ObjectId blkId)
        {
            using (Db.Transaction tran =
                       dwg.TransactionManager.StartTransaction())
            {
                Db.BlockReference bref = (Db.BlockReference)tran.GetObject(
                    blkId, Db.OpenMode.ForRead);

                Db.BlockTableRecord bdef = (Db.BlockTableRecord)tran.GetObject(
                    bref.BlockTableRecord, Db.OpenMode.ForWrite);

                Db.DrawOrderTable doTbl = (Db.DrawOrderTable)tran.GetObject(
                    bdef.DrawOrderTableId, Db.OpenMode.ForWrite);

                Db.ObjectIdCollection col = new Db.ObjectIdCollection();
                foreach (Db.ObjectId id in bdef)
                {
                    if (id.ObjectClass == Rtm.RXObject.GetClass(typeof(Db.Wipeout)))
                    {
                        col.Add(id);
                    }
                }

                if (col.Count > 0)
                {
                    doTbl.MoveToBottom(col);
                }


                tran.Commit();
            }
        }
Esempio n. 5
0
 RecordReferences(AcDb.ObjectId lookForObjId, AcDb.DBObject objToCheck, ReferenceFiler filer)
 {
     // now see if we showed up in any of the lists
     if (filer.m_hardPointerIds.Contains(lookForObjId))
     {
         m_hardPointerIds.Add(objToCheck.ObjectId);
     }
 }
Esempio n. 6
0
 public void AddStandardBreakline(ObjectId SurfaceId, ObjectId polyId, string name)
 {
     using (Transaction tr = CivilApplicationManager.StartTransaction())
     {
         C3DLandDb.TinSurface surface  = SurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
         ObjectIdCollection   entities = new ObjectIdCollection();
         entities.Add(polyId);
         surface.BreaklinesDefinition.AddStandardBreaklines(entities, 1.0, 1.0, 1.0, 0.0);
         tr.Commit();
     }
 }
        //[CommandMethod("PGA-ExportTo3DSMax")]
        //public static void Export3DSMax()
        //{
        //    PasteSurfaces surfaceManager = new PasteSurfaces();
        //    Database db = Application.DocumentManager.MdiActiveDocument.Database;
        //    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

        //    try
        //    {
        //        ObjectIdCollection surfaces = surfaceManager.GetAllSurfaces();

        //        foreach (ObjectId surfaceId in surfaces)
        //        {
        //            using (Transaction trans = db.TransactionManager.StartTransaction())
        //            {
        //                TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;

        //                surface.GetTriangles(true);


        //                trans.Commit();
        //            }

        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        ACADLogging.LogMyExceptions(e.Message);
        //    }

        //}
        public static Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection CloseSelectedPolylines()
        {
            Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection oids;
            oids = new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();

            SelectionSet selection;

            selection = BBC.Common.AutoCAD.SelectionManager.GetSelectionSet("");

            foreach (ObjectId obj in selection.GetObjectIds())
            {
                oids.Add(obj);
            }
            return(oids);
        }
Esempio n. 8
0
        public Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection GetAllPolyLines()
        {
            try
            {
                Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection oids =
                    new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
                SelectionSet selection = null;
                selection = SelectionManager.GetSelectionSet("Select Polylines");

                foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId oid in selection.GetObjectIds())
                {
                    oids.Add((oid));
                }
                return(oids);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                PGA.Civil.Logging.ACADLogging.LogMyExceptions(e.Message);
            }

            return(null);
        }
Esempio n. 9
0
        internal static bool CloneFromRepository <T>(Db.Database db,
                                                     string strName,
                                                     string RepositorySourcePath)
        {
            bool returnValue = false;

            using (Db.Database dbSource = new Db.Database(false, true))
            {
                try
                {
                    dbSource.ReadDwgFile(RepositorySourcePath,
                                         System.IO.FileShare.Read,
                                         true,
                                         null);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    App.Application.DocumentManager.MdiActiveDocument.Editor.
                    WriteMessage("\nError reading file repository: " +
                                 ex.Message);
                    return(returnValue);
                }

                Db.ObjectIdCollection sourceIds = new Db.ObjectIdCollection();

                using (Db.Transaction tr1 = dbSource.TransactionManager.
                                            StartTransaction())
                {
                    Db.ObjectId destDbMsId = Db.ObjectId.Null;
                    if (typeof(T) == typeof(Db.MLeaderStyle))
                    {
                        destDbMsId = db.MLeaderStyleDictionaryId;
                    }
                    else if (typeof(T) == typeof(Db.LayerTableRecord))
                    {
                        destDbMsId = db.LayerTableId;
                    }

                    Db.ObjectId destId = GetIDbyName <T>(dbSource, strName);

                    if (destId != Db.ObjectId.Null && destDbMsId != Db.ObjectId.Null)
                    {
                        sourceIds.Add(destId);
                        if (sourceIds.Count > 0)
                        {
                            Db.IdMapping mapping = new Db.IdMapping();
                            try
                            {
                                //Клонируем с заменой
                                dbSource.WblockCloneObjects(sourceIds,
                                                            destDbMsId,
                                                            mapping,
                                                            Db.DuplicateRecordCloning.Replace,
                                                            false);

                                returnValue = true;
                            }
                            catch (Rtm.Exception ex)
                            {
                                App.Application.DocumentManager.MdiActiveDocument.Editor.
                                WriteMessage(@"\nError during clone from the repository: "
                                             + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        App.Application.DocumentManager.MdiActiveDocument.Editor.
                        WriteMessage("\nError during clone from repository. " +
                                     "At the repository there is no Object with the specified name!");
                    }

                    tr1.Commit();
                }
            }

            return(returnValue);
        } //CloneFromRepository
Esempio n. 10
0
        private static void CreateTinForDistinctSurfaces(IList <Point3dCollection> p3D,
                                                         ACADDB.ObjectIdCollection collection)
        {
            if (p3D.Count != collection.Count)
            {
                return;
            }
            PolylineChildren children;

            try
            {
                foreach (ACADDB.ObjectId polys in collection)
                {
                    children = new PolylineChildren();

                    foreach (PolylineChildren item in m_PolylineChildren)
                    {
                        if (item.Oid.Equals(polys))
                        {
                            for (int i = 0; i < item.Children.Count; i++)
                            {
                                if (item.Children[i].Equals(polys))
                                {
                                    item.Children.RemoveAt(i);
                                }
                                else if (PGA.AcadUtilities.AcadUtilities.CompareAreasFromPolylines(polys,
                                                                                                   item.Children[i]))
                                {
                                    item.Children.RemoveAt(i);
                                }
                            }

                            children = item;
                            break;
                        }
                    }
                    var layer = PGA.SimplifyPolylines.Commands.GetPolylineName(polys);
                    var index = collection.IndexOf(polys);
                    CreateAllSurface.CreateTINSurface pTinSurface;
                    C3D.PasteSurfaces surfaces = new C3D.PasteSurfaces();

                    TinSurface theSurface;
                    if (index < p3D.Count)
                    {
                        pTinSurface = new CreateAllSurface.CreateTINSurface();
                        theSurface  = pTinSurface.CreateTINSurfaceByPointCollection(p3D[index], layer);
                        surfaces.AddBoundariesForSurfaces(PlineToPoints(children.Oid), theSurface.ObjectId);
                        // ACADDB.ObjectId materId = ACADDB.Material.FromAcadObject(theSurface.AcadObject);

                        //adds outer
                        //Adds hide polylines
                        for (int i = 0; i < children.Children.Count; i++)
                        {
                            var polyboundary = new  ACADDB.ObjectIdCollection();
                            polyboundary.Add(children.Oid);
                            SurfaceMaskCreationData mask = new SurfaceMaskCreationData
                                                               (String.Format("Hide-{0}", i), "Hide", theSurface.ObjectId, polyboundary, 3, theSurface.MaterialId, SurfaceMaskType.InSide, false);
                            if (!PGA.AcadUtilities.AcadUtilities.CompareAreasFromPolylines(polys, children.Children[i]))
                            {
                                surfaces.AddStandardBoundary(children.Children[i], theSurface.Name, theSurface);
                                //theSurface.Masks.Add(mask);
                            }
                        }
                    }
                }
            }
            catch (Exception ex1)
            {
                DatabaseLogs.FormatLogs(ex1.Message);
            }
        }
        public void exportshapefiles()
        {
            DocumentCollection docCol   = Application.DocumentManager;
            Database           localDb  = docCol.MdiActiveDocument.Database;
            Editor             editor   = docCol.MdiActiveDocument.Editor;
            Document           doc      = docCol.MdiActiveDocument;
            CivilDocument      civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
            MapApplication     mapApp   = HostMapApplicationServices.Application;

            Autodesk.Gis.Map.ImportExport.Exporter exporter = mapApp.Exporter;

            using (Transaction tx = localDb.TransactionManager.StartTransaction())
            {
                string logFileName = @"C:\1\DRI\0371-1158 - Gentofte Fase 4 - Dokumenter\02 Ekstern\" +
                                     @"01 Gældende tegninger\01 GIS input\02 Trace shape\export.log";

                try
                {
                    string fileName    = localDb.OriginalFileName;
                    string phaseNumber = "";

                    Regex regex = new Regex(@"(?<number>\d.\d)(?<extension>\.[^.]*$)");

                    if (regex.IsMatch(fileName))
                    {
                        Match match = regex.Match(fileName);
                        phaseNumber = match.Groups["number"].Value;
                        phaseNumber = phaseNumber.Replace(".", "");
                        File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Phase number detected: <{phaseNumber}>." });
                    }
                    else
                    {
                        File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: " +
                                                                        $"Detection of phase from filename failed! Aborting export for current file." });
                        tx.Abort();
                        return;
                    }

                    string finalExportFileNameBase = @"C:\1\DRI\0371-1158 - Gentofte Fase 4 - Dokumenter\02 Ekstern\" +
                                                     @"01 Gældende tegninger\01 GIS input\02 Trace shape";
                    string finalExportFileNamePipes  = finalExportFileNameBase + "\\" + phaseNumber + ".shp";
                    string finalExportFileNameBlocks = finalExportFileNameBase + "\\" + phaseNumber + "-komponenter.shp";

                    #region Create GIS Data
                    GisData.creategisdata();
                    #endregion

                    #region Export af rør
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Exporting pipes to {finalExportFileNamePipes}." });

                    HashSet <Polyline> pls  = localDb.HashSetOfType <Polyline>(tx, true);
                    HashSet <Line>     ls   = localDb.HashSetOfType <Line>(tx, true);
                    HashSet <Arc>      arcs = localDb.HashSetOfType <Arc>(tx, true);
                    HashSet <Entity>   ents = new HashSet <Entity>();
                    ents.UnionWith(pls);
                    ents.UnionWith(ls);
                    ents.UnionWith(arcs);
                    //Filter ents for forbidden values
                    ents = ents.Where(x => !DataQa.Gis.ContainsForbiddenValues(x.Layer)).ToHashSet();

                    ObjectIdCollection ids         = new ObjectIdCollection();
                    ObjectIdCollection rejectedIds = new ObjectIdCollection();
                    foreach (Entity ent in ents)
                    {
                        if (ent.Layer.Contains("FJV-TWIN") ||
                            ent.Layer.Contains("FJV-FREM") ||
                            ent.Layer.Contains("FJV-RETUR"))
                        {
                            ids.Add(ent.Id);
                        }
                        else
                        {
                            rejectedIds.Add(ent.Id);
                        }
                    }

                    foreach (ObjectId id in rejectedIds)
                    {
                        File.AppendAllLines(logFileName, new string[]
                                            { $"{DateTime.Now}: PIPEERROR!!! Pipe {id.Handle} has wrong layer: {id.Layer()}" });
                    }

                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: {ids.Count} pipe(s) found for export." });

                    exporter.Init("SHP", finalExportFileNamePipes);
                    exporter.SetStorageOptions(
                        Autodesk.Gis.Map.ImportExport.StorageType.FileOneEntityType,
                        Autodesk.Gis.Map.ImportExport.GeometryType.Line, null);
                    exporter.SetSelectionSet(ids);
                    Autodesk.Gis.Map.ImportExport.ExpressionTargetCollection mappings =
                        exporter.GetExportDataMappings();
                    mappings.Add(":Serie@Pipes", "Serie");
                    mappings.Add(":System@Pipes", "System");
                    mappings.Add(":DN@Pipes", "DN");
                    exporter.SetExportDataMappings(mappings);

                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Starting pipes export." });
                    exporter.Export(true);
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Exporting of pipes completed!" });
                    #endregion

                    #region Export af komponenter
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Exporting components to {finalExportFileNameBlocks}." });
                    System.Data.DataTable fjvKomponenter = CsvReader.ReadCsvToDataTable(
                        @"C:\1\DRI\AutoCAD DRI - 01 Civil 3D\FJV Komponenter.csv", "FjvKomponenter");
                    System.Data.DataTable fjvKompDyn = CsvReader.ReadCsvToDataTable(
                        @"C:\1\DRI\AutoCAD DRI - 01 Civil 3D\FJV Dynamiske Komponenter.csv", "FjvKomponenter");
                    ObjectIdCollection allBlockIds = new ObjectIdCollection();

                    #region Gather ordinary blocks
                    BlockTable bt = tx.GetObject(localDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                    foreach (ObjectId oid in bt)
                    {
                        BlockTableRecord btr = tx.GetObject(oid, OpenMode.ForRead) as BlockTableRecord;
                        if (btr.GetBlockReferenceIds(true, true).Count == 0)
                        {
                            continue;
                        }

                        if (ReadStringParameterFromDataTable(btr.Name, fjvKomponenter, "Navn", 0) != null)
                        {
                            ObjectIdCollection blkIds = btr.GetBlockReferenceIds(true, true);
                            foreach (ObjectId blkId in blkIds)
                            {
                                allBlockIds.Add(blkId);
                            }
                        }
                    }
                    #endregion

                    #region Gather dynamic blocks
                    HashSet <BlockReference> brSet = localDb.HashSetOfType <BlockReference>(tx);
                    foreach (BlockReference br in brSet)
                    {
                        if (br.IsDynamicBlock)
                        {
                            string realName = ((BlockTableRecord)tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name;
                            if (ReadStringParameterFromDataTable(realName, fjvKompDyn, "Navn", 0) != null)
                            {
                                allBlockIds.Add(br.ObjectId);
                            }
                        }
                    }
                    #endregion
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: {allBlockIds.Count} block(s) found for export." });

                    #region QA block export
                    HashSet <string> blockNamesInModel = new HashSet <string>();
                    foreach (BlockReference br in brSet)
                    {
                        if (br.IsDynamicBlock)
                        {
                            blockNamesInModel.Add(((BlockTableRecord)tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name);
                        }
                        else
                        {
                            blockNamesInModel.Add(br.Name);
                        }
                    }

                    HashSet <string> blockNamesGathered = new HashSet <string>();
                    foreach (ObjectId oid in allBlockIds)
                    {
                        BlockReference br = oid.Go <BlockReference>(tx);
                        if (br.IsDynamicBlock)
                        {
                            blockNamesGathered.Add(((BlockTableRecord)tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name);
                        }
                        else
                        {
                            blockNamesGathered.Add(br.Name);
                        }
                    }

                    var query = blockNamesInModel.Where(x => !blockNamesGathered.Contains(x));
                    foreach (string name in query)
                    {
                        File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: BLOCKERROR!!!: Block named {name} not included in export!" });
                    }
                    #endregion

                    #region Export components
                    int i = 1;
                    exporter.Init("SHP", finalExportFileNameBlocks);
                    exporter.SetStorageOptions(
                        Autodesk.Gis.Map.ImportExport.StorageType.FileOneEntityType,
                        Autodesk.Gis.Map.ImportExport.GeometryType.Point, null);
                    exporter.SetSelectionSet(allBlockIds);
                    Autodesk.Gis.Map.ImportExport.ExpressionTargetCollection mappingsForBlocks =
                        exporter.GetExportDataMappings();
                    mappings.Add(":BlockName@Components", "BlockName");
                    mappings.Add(":Type@Components", "Type");
                    mappings.Add(":Rotation@Components", "Rotation");
                    // mappings.Add(":System@Components", "System");
                    mappings.Add(":DN1@Components", "DN1");
                    mappings.Add(":DN2@Components", "DN2");
                    //mappings.Add(":Serie@Components", "Serie");
                    exporter.SetExportDataMappings(mappings);


                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Starting blocks export." });
                    exporter.Export(true);
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: Exporting of blocks complete." });
                    #endregion

                    #endregion
                }
                catch (MapImportExportException mex)
                {
                    tx.Abort();
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: EXCEPTION!!! Message: {mex.Message}. Aborting export of current file!" });
                    editor.WriteMessage("\n" + mex.Message);
                    return;
                }
                catch (System.Exception ex)
                {
                    tx.Abort();
                    File.AppendAllLines(logFileName, new string[] { $"{DateTime.Now}: EXCEPTION!!! Message: {ex.Message}. Aborting export of current file!" });
                    editor.WriteMessage("\n" + ex.Message);
                    return;
                }
                tx.Abort();
            }
        }
Esempio n. 12
0
        public void CreateLerData()
        {
            #region Catch no pipelines
            switch (this.type)
            {
            case GraveforespoergselssvartypeType.ingenledningerigraveområde:
                throw new System.Exception("INGEN ledninger i graveområde!");

            case GraveforespoergselssvartypeType.ledningsoplysningerudleveresikke:
                throw new System.Exception("Leningsoplysninger udleveres ikke!");

            case GraveforespoergselssvartypeType.ledningsoplysningerudleveret:
                break;

            case GraveforespoergselssvartypeType.udtagettilmanuelbehandling:
                break;

            case GraveforespoergselssvartypeType.udtagettilpåvisningledningsoplysningerudleveresikke:
                break;

            case GraveforespoergselssvartypeType.udtagettilpåvisningledningsoplysningerudleveret:
                break;

            default:
                break;
            }
            #endregion

            if (this.ledningMember == null)
            {
                this.ledningMember =
                    new GraveforespoergselssvarTypeLedningMember[0];
            }
            if (this.ledningstraceMember == null)
            {
                this.ledningstraceMember =
                    new GraveforespoergselssvarTypeLedningstraceMember[0];
            }
            if (this.ledningskomponentMember == null)
            {
                this.ledningskomponentMember =
                    new GraveforespoergselssvarTypeLedningskomponentMember[0];
            }

            Log.log($"Number of ledningMember -> {this.ledningMember?.Length.ToString()}");
            Log.log($"Number of ledningstraceMember -> {this.ledningstraceMember?.Length.ToString()}");
            Log.log($"Number of ledningskomponentMember -> {this.ledningskomponentMember?.Length.ToString()}");

            #region Create property sets
            //Dictionary to translate between type name and psName
            Dictionary <string, string> psDict = new Dictionary <string, string>();

            //Create property sets
            HashSet <Type> allUniqueTypes = ledningMember.Select(x => x.Item.GetType()).Distinct().ToHashSet();
            allUniqueTypes.UnionWith(ledningstraceMember.Select(x => x.Ledningstrace.GetType()).Distinct().ToHashSet());
            allUniqueTypes.UnionWith(ledningskomponentMember.Select(x => x.Item.GetType()).Distinct().ToHashSet());
            foreach (Type type in allUniqueTypes)
            {
                string psName = type.Name.Replace("Type", "");
                //Store the ps name in dictionary referenced by the type name
                //PS name is not goood! It becomes Elledning which is not unique
                //But it is unique!!
                //Data with different files will still follow the class definition in code
                //Which assures that all pssets are the same
                psDict.Add(type.Name, psName);

                PropertySetDefinition propSetDef = new PropertySetDefinition();
                propSetDef.SetToStandard(WorkingDatabase);
                propSetDef.SubSetDatabaseDefaults(WorkingDatabase);

                propSetDef.Description = type.FullName;
                bool isStyle   = false;
                var  appliedTo = new StringCollection()
                {
                    RXClass.GetClass(typeof(Polyline)).Name,
                    RXClass.GetClass(typeof(Polyline3d)).Name,
                    RXClass.GetClass(typeof(DBPoint)).Name,
                    RXClass.GetClass(typeof(Hatch)).Name,
                };
                propSetDef.SetAppliesToFilter(appliedTo, isStyle);

                var properties = type.GetProperties();

                foreach (PropertyInfo prop in properties)
                {
                    bool include = prop.CustomAttributes.Any(x => x.AttributeType == typeof(Schema.PsInclude));
                    if (include)
                    {
                        var propDefManual = new PropertyDefinition();
                        propDefManual.SetToStandard(WorkingDatabase);
                        propDefManual.SubSetDatabaseDefaults(WorkingDatabase);
                        propDefManual.Name        = prop.Name;
                        propDefManual.Description = prop.Name;
                        switch (prop.PropertyType.Name)
                        {
                        case nameof(String):
                            propDefManual.DataType    = Autodesk.Aec.PropertyData.DataType.Text;
                            propDefManual.DefaultData = "";
                            break;

                        case nameof(Boolean):
                            propDefManual.DataType    = Autodesk.Aec.PropertyData.DataType.TrueFalse;
                            propDefManual.DefaultData = false;
                            break;

                        case nameof(Double):
                            propDefManual.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                            propDefManual.DefaultData = 0.0;
                            break;

                        case nameof(Int32):
                            propDefManual.DataType    = Autodesk.Aec.PropertyData.DataType.Integer;
                            propDefManual.DefaultData = 0;
                            break;

                        default:
                            propDefManual.DataType    = Autodesk.Aec.PropertyData.DataType.Text;
                            propDefManual.DefaultData = "";
                            break;
                        }
                        propSetDef.Definitions.Add(propDefManual);
                    }
                }

                using (Transaction tx = WorkingDatabase.TransactionManager.StartTransaction())
                {
                    //check if prop set already exists
                    DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(WorkingDatabase);
                    if (dictPropSetDef.Has(psName, tx))
                    {
                        tx.Abort();
                        continue;
                    }
                    dictPropSetDef.AddNewRecord(psName, propSetDef);
                    tx.AddNewlyCreatedDBObject(propSetDef, true);
                    tx.Commit();
                }
            }
            #endregion

            //Debug list of all types in collections
            HashSet <string> names = new HashSet <string>();

            //List of all (new) layers of new entities
            HashSet <string> layerNames = new HashSet <string>();

            foreach (GraveforespoergselssvarTypeLedningMember member in ledningMember)
            {
                if (member.Item == null)
                {
                    Log.log($"ledningMember is null! Some enity has not been deserialized correct!");
                    continue;
                }

                string      psName   = psDict[member.Item.GetType().Name];
                ILerLedning ledning  = member.Item as ILerLedning;
                Oid         entityId = ledning.DrawEntity2D(WorkingDatabase);
                Entity      ent      = entityId.Go <Entity>(WorkingDatabase.TransactionManager.TopTransaction, OpenMode.ForWrite);
                layerNames.Add(ent.Layer);

                //Attach the property set
                PropertySetManager.AttachNonDefinedPropertySet(WorkingDatabase, ent, psName);

                //Populate the property set
                var psData = GmlToPropertySet.TranslateGmlToPs(member.Item);
                PropertySetManager.PopulateNonDefinedPropertySet(WorkingDatabase, ent, psName, psData);

                //names.Add(member.Item.ToString());
            }

            foreach (GraveforespoergselssvarTypeLedningstraceMember member in ledningstraceMember)
            {
                if (member.Ledningstrace == null)
                {
                    Log.log($"ledningstraceMember is null! Some enity has not been deserialized correct!");
                    continue;
                }

                string      psName   = psDict[member.Ledningstrace.GetType().Name];
                ILerLedning ledning  = member.Ledningstrace as ILerLedning;
                Oid         entityId = ledning.DrawEntity2D(WorkingDatabase);
                Entity      ent      = entityId.Go <Entity>(WorkingDatabase.TransactionManager.TopTransaction, OpenMode.ForWrite);
                layerNames.Add(ent.Layer);

                //Attach the property set
                PropertySetManager.AttachNonDefinedPropertySet(WorkingDatabase, ent, psName);

                //Populate the property set
                var psData = GmlToPropertySet.TranslateGmlToPs(member.Ledningstrace);
                PropertySetManager.PopulateNonDefinedPropertySet(WorkingDatabase, ent, psName, psData);

                //names.Add(item.Ledningstrace.ToString());
                //prdDbg(ObjectDumper.Dump(item.Ledningstrace));
            }

            foreach (GraveforespoergselssvarTypeLedningskomponentMember member in ledningskomponentMember)
            {
                if (member.Item == null)
                {
                    Log.log($"ledningskomponentMember is null! Some enity has not been deserialized correct!");
                    continue;
                }

                string        psName   = psDict[member.Item.GetType().Name];
                ILerKomponent creator  = member.Item as ILerKomponent;
                Oid           entityId = creator.DrawComponent(WorkingDatabase);
                Entity        ent      = entityId.Go <Entity>(WorkingDatabase.TransactionManager.TopTransaction, OpenMode.ForWrite);
                //Layer names are not analyzed for components currently
                //layerNames.Add(ent.Layer);

                //Attach the property set
                PropertySetManager.AttachNonDefinedPropertySet(WorkingDatabase, ent, psName);

                //Populate the property set
                var psData = GmlToPropertySet.TranslateGmlToPs(member.Item);
                PropertySetManager.PopulateNonDefinedPropertySet(WorkingDatabase, ent, psName, psData);

                //names.Add(member.Item.ToString());
            }

            foreach (string name in names)
            {
                prdDbg(name);
            }

            #region Read and assign layer's color
            //Regex to parse the color information
            Regex colorRegex = new Regex(@"^(?<R>\d+)\*(?<G>\d+)\*(?<B>\d+)");

            //Cache layer table
            LayerTable lt = WorkingDatabase.LayerTableId.Go <LayerTable>(WorkingDatabase.TransactionManager.TopTransaction);

            //Set up all LER layers
            foreach (string layerName in layerNames)
            {
                string colorString = ReadStringParameterFromDataTable(layerName, DtKrydsninger, "Farve", 0);

                Color color;
                if (colorString.IsNoE())
                {
                    Log.log($"Ledning with layer name {layerName} could not get a color!");
                    color = Color.FromColorIndex(ColorMethod.ByAci, 0);
                }
                else if (colorRegex.IsMatch(colorString))
                {
                    Match match = colorRegex.Match(colorString);
                    byte  R     = Convert.ToByte(int.Parse(match.Groups["R"].Value));
                    byte  G     = Convert.ToByte(int.Parse(match.Groups["G"].Value));
                    byte  B     = Convert.ToByte(int.Parse(match.Groups["B"].Value));
                    //prdDbg($"Set layer {name} to color: R: {R.ToString()}, G: {G.ToString()}, B: {B.ToString()}");
                    color = Color.FromRgb(R, G, B);
                }
                else
                {
                    Log.log($"Ledning layer name {layerName} could not parse colorString {colorString}!");
                    color = Color.FromColorIndex(ColorMethod.ByAci, 0);
                }

                LayerTableRecord ltr = lt[layerName]
                                       .Go <LayerTableRecord>(WorkingDatabase.TransactionManager.TopTransaction, OpenMode.ForWrite);

                ltr.Color = color;
            }
            #endregion

            #region Read and assign layer's linetype
            LinetypeTable ltt = (LinetypeTable)WorkingDatabase.TransactionManager.TopTransaction
                                .GetObject(WorkingDatabase.LinetypeTableId, OpenMode.ForWrite);

            //Check if all line types are present
            HashSet <string> missingLineTypes = new HashSet <string>();
            foreach (string layerName in layerNames)
            {
                string lineTypeName = ReadStringParameterFromDataTable(layerName, DtKrydsninger, "LineType", 0);
                if (lineTypeName.IsNoE())
                {
                    continue;
                }
                else if (!ltt.Has(lineTypeName))
                {
                    missingLineTypes.Add(lineTypeName);
                }
            }

            if (missingLineTypes.Count > 0)
            {
                Database ltDb = new Database(false, true);
                ltDb.ReadDwgFile("X:\\AutoCAD DRI - 01 Civil 3D\\Projection_styles.dwg",
                                 FileOpenMode.OpenForReadAndAllShare, false, null);
                Transaction ltTx = ltDb.TransactionManager.StartTransaction();

                Oid destDbMsId = SymbolUtilityServices.GetBlockModelSpaceId(WorkingDatabase);

                LinetypeTable sourceLtt = (LinetypeTable)ltDb.TransactionManager.TopTransaction
                                          .GetObject(ltDb.LinetypeTableId, OpenMode.ForRead);
                ObjectIdCollection idsToClone = new ObjectIdCollection();

                foreach (string missingName in missingLineTypes)
                {
                    idsToClone.Add(sourceLtt[missingName]);
                }

                IdMapping mapping = new IdMapping();
                ltDb.WblockCloneObjects(idsToClone, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
                ltTx.Commit();
                ltTx.Dispose();
                ltDb.Dispose();
            }

            Oid lineTypeId;
            foreach (string layerName in layerNames)
            {
                string lineTypeName = ReadStringParameterFromDataTable(layerName, DtKrydsninger, "LineType", 0);
                if (lineTypeName.IsNoE())
                {
                    Log.log($"WARNING! Layer name {layerName} does not have a line type specified!.");
                    //If linetype string is NoE -> CONTINUOUS linetype must be used
                    lineTypeId = ltt["Continuous"];
                }
                else
                {
                    //the presence of the linetype is assured in previous foreach.
                    lineTypeId = ltt[lineTypeName];
                }
                LayerTableRecord ltr = lt[layerName]
                                       .Go <LayerTableRecord>(WorkingDatabase.TransactionManager.TopTransaction, OpenMode.ForWrite);
                ltr.LinetypeObjectId = lineTypeId;
            }
            #endregion
        }