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();
            }
        }
Exemple #2
0
 public void SelectProcessCommand(Autodesk.AutoCAD.DatabaseServices.ObjectId id)
 {
     if (CurrentTechProcess.GetToolpathObjectIds().TryGetValue(id, out var index))
     {
         processCommandBindingSource.Position = index;
     }
 }
Exemple #3
0
        void getJointsWithSelection()
        {
            Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;
            Database           db    = Application.DocumentManager.MdiActiveDocument.Database;
            TransactionManager tm    = db.TransactionManager;
            Transaction        trans = tm.StartTransaction();

            try
            {
                PromptEntityOptions entopts = new PromptEntityOptions("Select a wall ");
                entopts.SetRejectMessage("Must select a wall, please!");
                entopts.AddAllowedClass(typeof(Wall), true);
                PromptEntityResult ent = null;
                try
                {
                    ent = ed.GetEntity(entopts);
                }
                catch
                {
                    ed.WriteMessage("You did not select a valid entity");
                    return;
                }

                if (ent.Status == PromptStatus.OK)
                {
                    ObjectId entId = ent.ObjectId;

                    Wall wall = trans.GetObject(entId, OpenMode.ForRead, false) as Wall;
                    if (wall != null)
                    {
                        Manager  mgr      = new Manager(db);
                        Graph    theGraph = mgr.FindGraph(wall);
                        Matrix3d mat      = theGraph.WcsToEcsMatrix.Inverse();
                        for (int i = 0; i < theGraph.WallJointCount; i++)
                        {
                            Joint   joint         = theGraph.GetWallJoint(i);
                            Point3d jointloc      = new Point3d(joint.Location.X, joint.Location.Y, 0);
                            Point3d jointlocTrans = jointloc.TransformBy(mat);
                            DrawBlip(jointloc.TransformBy(mat), 3, 1, false);
                            ed.WriteMessage("\n Joint at (ECS): " + joint.Location.ToString() + " (WCS): " + jointlocTrans.ToString());
                        }
                    }
                    else
                    {
                        ed.WriteMessage("\nSomething bad has happened...");
                    }
                }

                trans.Commit();
            }
            catch (System.Exception e)
            {
                trans.Abort();
                ed.WriteMessage(e.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }
Exemple #4
0
        public void CDS_CreateElevationRanges()
        {
            AcadDb.ObjectId surfaceId = promptForTinSurface();
            if (surfaceId == AcadDb.ObjectId.Null)
            {
                return;
            }

            using (AcadDb.Transaction tr = startTransaction())
            {
                TinSurface surface =
                    surfaceId.GetObject(AcadDb.OpenMode.ForWrite)
                    as TinSurface;

                // Get the existing analysis, if any.
                SurfaceAnalysisElevationData[] data =
                    surface.Analysis.GetElevationData();
                _editor.WriteMessage("\nExisting analysis length: {0}",
                                     data.Length);
                SurfaceAnalysisElevationData[] newData =
                    CreateElevationRegions(surface, 10, 100);
                surface.Analysis.SetElevationData(newData);

                tr.Commit();
            }
        }
Exemple #5
0
        //设置巷道分段温度
        public void setTemperature(int segment)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions options = new PromptEntityOptions("选择物体");
            PromptEntityResult  res     = ed.GetEntity(options);

            if (res.Status == PromptStatus.Cancel)
            {
                return;
            }

            Autodesk.AutoCAD.DatabaseServices.ObjectId id1 = res.ObjectId;
            Database db = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Utils.TransactionControl(() =>
            {
                Entity ent = (Entity)tm.GetObject(id1, OpenMode.ForWrite, false);

                if (ent is BaseTunnel)
                {
                    BaseTunnel tunnel = ent as BaseTunnel;
                }
            });
        }
        public List <AcadDB.Entity> Draw()
        {
            //return new List<AcadDB.Entity>();
            if (number_steel < 2)
            {
                return(new List <AcadDB.Entity>());
            }

            List <AcadDB.Entity> ents = new List <AcadDB.Entity>();

            AcadDB.ObjectId blk_id = AcadFuncsCSharp.BlkRefFuncs.GetBlock(BLK_NAME);
            if (AcadDB.ObjectId.Null == blk_id)
            {
                MessageBox.Show("Khong co block thep");
                throw new Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.OK, "Failed");
            }

            var steel_pos = QuerySteelPos();

            foreach (var sp in steel_pos)
            {
                ents.Add(new AcadDB.BlockReference(sp, blk_id));
            }

            return(ents);
        }
Exemple #7
0
        TreeNodeSelected(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            // this call back is used for both the SymTbl and Dict tab pages,
            // but we need to know which so we can use the correct ListView
            // control.
            ListView lvCur = null;

            if (sender == m_tvSymTbls)
            {
                lvCur = m_lvSymTbl;
            }
            else if (sender == m_tvDicts)
            {
                lvCur = m_lvDict;
            }
            else
            {
                Debug.Assert(false);    // Why not?
            }
            m_curObjId = (AcDb.ObjectId)e.Node.Tag;


            AcDb.DBObject dbObj = m_trans.Transaction.GetObject(m_curObjId, OpenMode.ForRead);

            // collect all the data about the object
            m_snoopCollector.Collect(dbObj);

            // now display it
            Snoop.Utils.Display(lvCur, m_snoopCollector);
        }
Exemple #8
0
        public ObjectId GetSiteId(ObjectId surfaceId)
        {
            var site = ObjectId.Null;

            using (Transaction tr = CivilApplicationManager.StartTransaction())

            {
                Autodesk.AutoCAD.DatabaseServices.Database db = CivilApplicationManager.WorkingDatabase;
                var doc = CivilDocument.GetCivilDocument(db);
                ObjectIdCollection siteIds = doc.GetSiteIds();
                if (siteIds != null && siteIds.Count != 0)
                {
                    site = (from s in siteIds.Cast <ObjectId>()
                            select s).FirstOrDefault();
                }

                if (site == ObjectId.Null)
                {
                    site = C3DLandDb.Site.Create(doc, "Site-ALL");
                }

                tr.Commit();
            }
            return(site);
        }
        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);
        }
Exemple #10
0
        static public void GetEnt()
        {
            AcEd.Editor  ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptResult rs = ed.GetString("\nВведите метку примитива (в hex-представлении): ");

            if (rs.Status != PromptStatus.OK)
            {
                return;
            }
            System.Int64  l  = System.Int64.Parse(rs.StringResult, System.Globalization.NumberStyles.HexNumber);
            AcDb.Handle   h  = new AcDb.Handle(l);
            AcDb.Database db = AcDb.HostApplicationServices.WorkingDatabase;
            AcDb.ObjectId id = db.GetObjectId(false, h, 0);
            if (!id.IsValid)
            {
                ed.WriteMessage("\nОшибочная метка примитива {0}", h);
                return;
            }
            using (AcAp.DocumentLock doclock = ed.Document.LockDocument())
            {
                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.Entity ent = tr.GetObject(id, AcDb.OpenMode.ForRead) as AcDb.Entity;
                    if (ent != null)
                    {
                        ed.WriteMessage("\nEntity Class: {0}", AcRx.RXClass.GetClass(ent.GetType()).Name);
                        // Ну и так далее - делаешь с примитивом то, что тебе нужно...
                    }
                    else
                    {
                        ed.WriteMessage("\nЭто не примитив!");
                    }
                }
            }
        }
Exemple #11
0
        public void AddCivil2016Breakline(ObjectId SurfaceId, ObjectId polyId, ObjectId siteId, string name)
        {
            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                ObjectId featureId            = ObjectId.Null;
                C3DLandDb.FeatureLine feature = null;

                //ObjectId featureId = C3DLandDb.FeatureLine.Create(GetFeatureLineName(), polyId, GetSiteId(ObjectId.Null));
                var checkPoly = polyId.GetObject(OpenMode.ForRead, false, true) as Polyline;

                if (checkPoly != null)
                {
                    featureId = C3DLandDb.FeatureLine.Create(GetFeatureLineName(), polyId, siteId);
                }

                feature = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForRead);
                feature.AssignElevationsFromSurface(SurfaceId, true);
                var p3Dcollection = feature.GetPoints(FeatureLinePointType.AllPoints);

                //Polyline3d poly = new Polyline3d(Poly3dType.SimplePoly, p3Dcollection, true);
                //tr.AddNewlyCreatedDBObject(poly,true);

                C3DLandDb.TinSurface surface = SurfaceId.GetObject(OpenMode.ForWrite) as C3DLandDb.TinSurface;

                //ObjectIdCollection entities = new ObjectIdCollection();
                //entities.Add(poly.ObjectId);
                surface.BreaklinesDefinition.AddStandardBreaklines(p3Dcollection, 1.0, 2.0, 1.0, 0.0);
                tr.Commit();
            }
        }
Exemple #12
0
        ProcessObject(AcDb.Transaction trHelp, AcDb.ObjectId lookForObjId, AcDb.ObjectId curObjId)
        {
            AcDb.DBObject tmpObj = trHelp.GetObject(curObjId, AcDb.OpenMode.ForRead);
            if (tmpObj != null)
            {
                m_count++;
                ReferenceFiler filer = new ReferenceFiler();
                tmpObj.DwgOut(filer);                          // find out who this object owns

                RecordReferences(lookForObjId, tmpObj, filer); // record references for this object

                // now recursively visit all the objects this one owns
                for (int i = 0; i < filer.m_hardOwnershipIds.Count; i++)
                {
                    ProcessObject(trHelp, lookForObjId, filer.m_hardOwnershipIds[i]);
                }

                for (int i = 0; i < filer.m_softOwnershipIds.Count; i++)
                {
                    ProcessObject(trHelp, lookForObjId, filer.m_softOwnershipIds[i]);
                }
            }
            else
            {
                m_skipped++;
            }
        }
Exemple #13
0
        } //WriteResourceToFile

        internal static Db.ObjectId GetIDbyName <T>(Db.Database db, string strName)
        {
            Db.ObjectId RecId = Db.ObjectId.Null;
            using (Db.Transaction tr1 = db.TransactionManager.StartTransaction())
            {
                if (typeof(T) == typeof(Db.MLeaderStyle))
                {
                    Db.DBDictionary mlstyles = (Db.DBDictionary)tr1.GetObject(
                        db.MLeaderStyleDictionaryId,
                        Db.OpenMode.ForRead);

                    RecId = (mlstyles.Contains(strName)) ? mlstyles.GetAt(strName) : Db.ObjectId.Null;
                }
                else if (typeof(T) == typeof(Db.LayerTableRecord))
                {
                    Db.LayerTable layerTable;
                    layerTable = (Db.LayerTable)tr1.GetObject(db.LayerTableId,
                                                              Db.OpenMode.ForRead);

                    RecId = (layerTable.Has(strName)) ? layerTable[strName] : Db.ObjectId.Null;
                }
                tr1.Commit();
            }
            // Все еще можно получить Db.ObjectId.Null для передачи.
            return(RecId);
        }
Exemple #14
0
        public CivilTinSurface CreateSelectedSurface(Autodesk.AutoCAD.DatabaseServices.ObjectId oid)
        {
            try
            {
                ACADLogging.LogMyExceptions("Start CreateSelectedSurface Method");
                string surfaceName      = GetPolyLayerFromOid((oid));
                string surfaceStyleName = GetPolyLayerFromOid((oid)); //layer and style name are the same name.
                // m_polylinesurfaces = new Dictionary<ObjectId, string>();

                int i = 0;
                //string tempSurface = "s-" + surfaceName.ToLower();
                string tempSurface = surfaceName.ToUpper();
                while (CivilTinSurface.FindCivilTinSurfaceByName(tempSurface, ""))
                {
                    tempSurface = string.Format("{0}-{1}", surfaceName, i++);
                }
                surfaceName = tempSurface;
                if (!SurfaceStyleManager.Exists(surfaceStyleName))
                {
                    string msg = String.Format("\nSurface Style '{0}' doesn't exist. Creating it with default values.",
                                               surfaceStyleName);
                    //EditorUtils.Write(msg);
                    SurfaceStyleManager.CreateDefault(surfaceStyleName);
                }
                CivilTinSurface surface = new CivilTinSurface(surfaceName, surfaceStyleName);
                m_polylinesurfaces.Add(CivilTinSurface.FindCivilTinSurfaceByName(surface.Name), surfaceName);
                m_polylinesonly.Add(oid, surfaceName);
                return(surface);
            }
            catch (System.Exception ex)
            {
                ACADLogging.LogMyExceptions("CreateSelectedSurface" + ex.Message);
            }
            return(null);
        }
Exemple #15
0
        References(string label, AcDb.ObjectId val)
            :   base(label)
        {
            m_val = val;

            if (m_val.IsNull == false)
            {
                using (TransactionHelper trHlp = new TransactionHelper(m_val.Database)) {
                    trHlp.Start();

                    AcDb.DBObject dbObj = trHlp.Transaction.GetObject(m_val, AcDb.OpenMode.ForRead);

                    MgdDbg.Utils.ReferenceFiler filer = new MgdDbg.Utils.ReferenceFiler();
                    dbObj.DwgOut(filer);

                    trHlp.Commit();

                    m_hardPointerIds   = filer.m_hardPointerIds;
                    m_softPointerIds   = filer.m_softPointerIds;
                    m_hardOwnershipIds = filer.m_hardOwnershipIds;
                    m_softOwnershipIds = filer.m_softOwnershipIds;
                }

                if ((m_hardPointerIds.Count == 0) && (m_softPointerIds.Count == 0) && (m_hardOwnershipIds.Count == 0) && (m_softOwnershipIds.Count == 0))
                {
                    m_hasRefs = false;
                }
                else
                {
                    m_hasRefs = true;
                }
            }
        }
Exemple #16
0
        public int processObjectId(DB.Transaction tr, DB.ObjectId objId, FindReplacer findReplacer)
        {
            int replaced = 0;
            var ent      = tr.GetObject(objId, DB.OpenMode.ForWrite, false);

            if (ent is DB.Table)
            {
                var tbl = ent as DB.Table;
                if (tbl.NumRows > 0 && tbl.NumColumns > 0)
                {
                    for (var r = 0; r < tbl.NumRows; r++)
                    {
                        for (var c = 0; c < tbl.NumColumns; c++)
                        {
                            var text = tbl.GetTextString(r, c, 0, DB.FormatOption.FormatOptionNone);
                            var textWithoutFormat = tbl.GetTextString(r, c, 0, DB.FormatOption.IgnoreMtextFormat);
                            if (findReplacer.ContainsIn(text, textWithoutFormat))
                            {
                                tbl.SetTextString(r, c, text.Replace(findReplacer.Find, findReplacer.Replace));
                                replaced++;
                            }
                        }
                    }
                }
            }
            else if (ent is DB.MText)
            {
                var mtext             = ent as DB.MText;
                var text              = mtext.Contents;
                var textWithoutFormat = mtext.Text;
                if (findReplacer.ContainsIn(text, textWithoutFormat))
                {
                    mtext.Contents = text.Replace(findReplacer.Find, findReplacer.Replace);
                    replaced++;
                }
            }
            else if (ent is DB.DBText)
            {
                var dbtext = ent as DB.DBText;
                var text   = dbtext.TextString;
                if (findReplacer.ContainsIn(text, text))
                {
                    dbtext.TextString = text.Replace(findReplacer.Find, findReplacer.Replace);
                    replaced++;
                }
            }
            else if (ent is DB.BlockReference)
            {
                var br   = ent as DB.BlockReference;
                var brId = br.IsDynamicBlock ? br.DynamicBlockTableRecord : br.BlockTableRecord;
                var btr  = (DB.BlockTableRecord)tr.GetObject(brId, DB.OpenMode.ForRead, false);
                foreach (DB.ObjectId objId2 in btr)
                {
                    processObjectId(tr, objId2, findReplacer);
                }
            }

            return(replaced);
        }
Exemple #17
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);
     }
 }
Exemple #18
0
        void getSectionsWithSelection()
        {
            Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;
            Database           db    = Application.DocumentManager.MdiActiveDocument.Database;
            TransactionManager tm    = db.TransactionManager;
            Transaction        trans = tm.StartTransaction();

            try
            {
                PromptEntityOptions entopts = new PromptEntityOptions("Select a wall ");
                entopts.SetRejectMessage("Must select a wall, please!");
                entopts.AddAllowedClass(typeof(Wall), true);
                PromptEntityResult ent = null;
                try
                {
                    ent = ed.GetEntity(entopts);
                }
                catch
                {
                    ed.WriteMessage("You did not select a valid entity");
                    return;
                }

                if (ent.Status == PromptStatus.OK)
                {
                    ObjectId entId = ent.ObjectId;

                    Wall     wall     = trans.GetObject(entId, OpenMode.ForRead, false) as Wall;
                    Manager  mgr      = new Manager(db);
                    Graph    theGraph = mgr.FindGraph(wall);
                    Matrix3d mat      = theGraph.WcsToEcsMatrix.Inverse();
                    for (int i = 0; i < theGraph.WallJointCount; i++)
                    {
                        Joint joint = theGraph.GetWallJoint(i);
                        ConnectionCollection connections = joint.Connections;
                        foreach (Connection connection in connections)
                        {
                            Section section = connection.Section;
                            int     count   = section.ComponentSetCount;
                            ed.WriteMessage("\n  Section in wall system for wall id: " + section.WallId + "\n    component set count = " + count);
                            ed.DrawVector(new Point3d(section.StartPoint.X, section.StartPoint.Y, 0).TransformBy(mat),
                                          new Point3d(section.EndPoint.X, section.EndPoint.Y, 0).TransformBy(mat), 4, true);
                        }
                    }
                }

                trans.Commit();
            }
            catch (System.Exception e)
            {
                trans.Abort();
                ed.WriteMessage(e.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }
        private void Check(string path)
        {
            ProjectFile file = proj.GetFile(path);

            if (file.DwgExists)
            {
                // Gets the database for the specified dwg file
                string dwgName = file.DrawingFullPath;

                Database dwgDb = GetDbForFile(dwgName);

                if (dwgDb != null)
                {
                    ObjectId    symTbId = dwgDb.BlockTableId;
                    Transaction trans   = dwgDb.TransactionManager.StartTransaction();

                    try
                    {
                        BlockTable       bt   = trans.GetObject(symTbId, OpenMode.ForRead, false) as BlockTable;
                        StringCollection refs = new StringCollection();

                        foreach (ObjectId recId in bt)
                        {
                            BlockTableRecord btr = trans.GetObject(recId, OpenMode.ForRead) as BlockTableRecord;

                            if (btr.IsFromExternalReference)
                            {
                                refs.Add(btr.Name);
                            }
                        }

                        // output referenced files
                        if (refs.Count == 0)
                        {
                            Print("<" + file.FileName + "> references no other dwg files.");
                        }
                        else
                        {
                            Print("<" + file.FileName + @"> references the following dwg files:");
                            int i = 0;
                            foreach (string refName in refs)
                            {
                                Print(++i + ". " + refName);
                            }
                        }
                    }
                    catch
                    {
                        trans.Abort();
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                }
            }
        }
Exemple #20
0
        void RecursiveReferencesToOfSeletedObject()
        {
            //
            // Transaction processing
            //
            Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;
            Database           db    = Application.DocumentManager.MdiActiveDocument.Database;
            TransactionManager tm    = db.TransactionManager;
            Transaction        trans = tm.StartTransaction();

            try
            {
                PromptEntityOptions entopts = new PromptEntityOptions("Select an Aec Entity ");
                entopts.SetRejectMessage("Must select an Aec Entity, please!");
                entopts.AddAllowedClass(typeof(Autodesk.Aec.DatabaseServices.Entity), false);
                PromptEntityResult ent = null;
                try
                {
                    ent = ed.GetEntity(entopts);
                }
                catch
                {
                    ed.WriteMessage("You did not select a valid entity");
                    return;
                }

                if (ent.Status == PromptStatus.OK)
                {
                    ObjectId entId = ent.ObjectId;

                    Autodesk.Aec.DatabaseServices.Entity aecent = tm.GetObject(entId, OpenMode.ForRead, false) as Autodesk.Aec.DatabaseServices.Entity;

                    DBObjectRelationshipManager    mgr    = new DBObjectRelationshipManager();
                    DBObjectRelationshipCollection refsTo = mgr.GetReferencesToThisObjectRecursive(aecent, 0, false);

                    ed.WriteMessage("\n\n");
                    foreach (DBObjectRelationship relTo in refsTo)
                    {
                        ed.WriteMessage("Ent ID = " + entId.ToString() + "  " + entId.ObjectClass.Name.ToString() + " is referenced recursively by: " + relTo.Id.ToString() + "("
                                        + relTo.Id.ObjectClass.Name + ")" + ", whose relationship type is "
                                        + relTo.RelationshipType.ToString() + "\n");
                    }
                }

                trans.Commit();
            }
            catch (System.Exception e)
            {
                trans.Abort();
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }
 private void _verifyObjectTypeIs(Type requestedType)
 {
     acaddb.ObjectIdCollection node =
         m_TestDocument.NodeProvider.GetNode(m_RequestedType);
     acaddb.ObjectId id     = node[0];
     c3ddb.Entity    entity = id.GetObject(acaddb.OpenMode.ForRead)
                              as c3ddb.Entity;
     Assert.AreEqual(requestedType, entity.GetType(),
                     "Incorrect node returned.");
 }
        void StreamCollectClipBodiesSample()
        {
            Database db     = GetDatabase();
            Editor   editor = GetEditor();

            editor.WriteMessage("* StreamCollectClipBodies *\n");
            editor.WriteMessage("StreamCollectClipBodies clips all geometry pushed in against the supplied body.\n");
            editor.WriteMessage("Pick some objects in the current drawing and then pick an mass element to define the clipping boundary. The collected graphics will be highlighted in the current view.\n");

            ObjectIdCollection ids = PickObjectSet("Please pick the objects to be clipped");

            if (ids.Count == 0)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            ObjectId massElemId = PickObject(typeof(MassElement), true, "Please pick a mass element to define the clipping boundary");

            if (massElemId.IsNull)
            {
                editor.WriteMessage("A mass element is needed to define the clipping boundary.\n");
                return;
            }

            StreamCollectClipBodies stream = new StreamCollectClipBodies(db);
            // You may tell the stream to retain bodies instead of turning bodies into shells.
            // stream.SetRetainBodies(true);
            // But now we use the default setting, which uses shell as output.
            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                MassElement     masselem = trans.GetObject(massElemId, OpenMode.ForRead) as MassElement;
                AecModeler.Body body     = masselem.Body.Transform(masselem.Ecs);
                stream.SetBodyClipVolume(body);

                stream.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);

                foreach (ObjectId id in ids)
                {
                    Entity entity = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    stream.Stream(entity);
                }

                stream.PopDisplayParameters();
                trans.Commit();
            }

            GraphicsStorage[] gsCollection = stream.GetCollectedGraphics();
            foreach (GraphicsStorage gs in gsCollection)
            {
                HighlightGraphics(gs);
            }
        }
        public static void attachpropertysetstoobjects()
        {
            DocumentCollection docCol   = Application.DocumentManager;
            Database           localDb  = docCol.MdiActiveDocument.Database;
            Editor             ed       = docCol.MdiActiveDocument.Editor;
            Document           doc      = docCol.MdiActiveDocument;
            CivilDocument      civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            //Reference ODTables
            Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
            DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(localDb);

            using (Transaction tx = localDb.TransactionManager.StartTransaction())
            {
                //Change here to add other types of objects
                HashSet <Entity> ents = new HashSet <Entity>();
                ents.UnionWith(localDb.HashSetOfType <Line>(tx));
                ents.UnionWith(localDb.HashSetOfType <Spline>(tx));
                ents.UnionWith(localDb.HashSetOfType <DBPoint>(tx));
                ents.UnionWith(localDb.HashSetOfType <Polyline>(tx));
                ents.UnionWith(localDb.HashSetOfType <Polyline3d>(tx));
                ents.UnionWith(localDb.HashSetOfType <BlockReference>(tx));
                //ents = ents.Where(x => x.Layer == "0-FJV_fremtid").ToHashSet();

                foreach (Entity ent in ents)
                {
                    using (Records records =
                               tables.GetObjectRecords(0, ent.Id, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false))
                    {
                        int recordsCount = records.Count;
                        for (int i = 0; i < recordsCount; i++)
                        {
                            Record record      = records[i];
                            int    recordCount = record.Count;
                            string tableName   = record.TableName;

                            //Attach correct property set to entity
                            Oid dictId = dictPropSetDef.GetAt(tableName);
                            if (dictId == Oid.Null)
                            {
                                ed.WriteMessage($"\nODTable {tableName} does not have corresponding propertyset!" +
                                                $"Create propertysets first.");
                                tx.Abort();
                                return;
                            }
                            //Add property set to the object
                            ent.CheckOrOpenForWrite();
                            PropertyDataServices.AddPropertySet(ent, dictId);
                        }
                    }
                }
                tx.Commit();
                prdDbg("Finished!");
            }
        }
Exemple #24
0
        public ObjectId FindCivilTinSurface(string surfaceName)
        {
            ObjectId requested = findSurface(surfaceName);

            if (requested == ObjectId.Null)
            {
                return(ObjectId.Null);
            }

            return(requested);
        }
Exemple #25
0
        public bool removeImgDefByName()
        {
            DocumentLock doclock = null;

            try
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                doclock = doc.LockDocument();

                Database db = HostApplicationServices.WorkingDatabase;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                using (Transaction t = tm.StartTransaction())
                {
                    try
                    {
                        // open the dictionary
                        Autodesk.AutoCAD.DatabaseServices.ObjectId imgDictID = RasterImageDef.GetImageDictionary(db);
                        DBDictionary imgDict;
                        if (imgDictID.OldId == 0)
                        {
                            imgDictID = RasterImageDef.CreateImageDictionary(db);
                        }

                        imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForWrite);

                        if (imgDict.Contains(ImgName))
                        {
                            ObjectId       rasterDefID = imgDict.GetAt(ImgName);
                            RasterImageDef rasterDef   = (RasterImageDef)t.GetObject(rasterDefID, OpenMode.ForWrite);

                            rasterDef.Erase();


                            imgDict.Remove(ImgName);
                        }
                        imgDict.Close();
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception eex)
                    { }
                    catch (System.Exception ex) { }
                    t.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception eex)
            { return(false); }
            catch (System.Exception ex) { return(false); }
            finally
            {
                doclock.Dispose();
            }

            return(true);
        }
Exemple #26
0
        EntityDiff(AcDb.ObjectId objId1, AcDb.ObjectId objId2, TransactionHelper tr)
        {
            // Required for Windows Form Designer support
            InitializeComponent();

            Object obj1 = tr.Transaction.GetObject(objId1, OpenMode.ForRead);
            Object obj2 = tr.Transaction.GetObject(objId2, OpenMode.ForRead);

            m_compareObjs = new ObjectCompare(obj1, obj2);
            Initialise();
        }
Exemple #27
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();
     }
 }
Exemple #28
0
        public Oid CreateEntity(Database database)
        {
            var exterior = this.exterior;
            var ringType = exterior.Item;

            switch (ringType)
            {
            case LinearRingType lrt:
                DirectPositionListType dplt;
                if ((dplt = lrt.Items[0] as DirectPositionListType) != null)
                {
                    var points = dplt.GetPoints();

                    Point2dCollection points2d = new Point2dCollection();
                    DoubleCollection  dc       = new DoubleCollection();
                    //-1 beacuse the last point is a repetition of first
                    for (int i = 0; i < points.Length; i++)
                    {
                        points2d.Add(points[i].To2D());
                        dc.Add(0.0);
                    }

                    //Polyline pline = new Polyline(points.Length);
                    ////-1 beacuse the last point is a repetition of first
                    //for (int i = 0; i < points.Length - 1; i++)
                    //    pline.AddVertexAt(pline.NumberOfVertices, points[i].To2D(), 0, 0, 0);
                    //pline.Closed = true;
                    //Oid plineId = pline.AddEntityToDbModelSpace(database);

                    Hatch hatch = new Hatch();
                    hatch.Normal       = new Vector3d(0.0, 0.0, 1.0);
                    hatch.Elevation    = 0.0;
                    hatch.PatternScale = 1.0;
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    Oid hatchId = hatch.AddEntityToDbModelSpace(database);

                    hatch.AppendLoop(HatchLoopTypes.Default, points2d, dc);
                    hatch.EvaluateHatch(true);

                    return(hatchId);
                }
                else
                {
                    throw new System.Exception(
                              $"Unexpected type in PolygonType.exterior.Item.Items[0]: {lrt.Items[0].GetType().Name}");
                }

            case RingType rt:
                throw new System.NotImplementedException();

            default:
                throw new System.Exception($"Unexpected type in PolygonType.exterior.Item: {ringType.GetType().Name}");
            }
        }
Exemple #29
0
        public ObjectId AddCivil2016BreaklineByTrans(ObjectId SurfaceId, ObjectId polyId, ObjectId siteId, string name)
        {
            ObjectId featureId = ObjectId.Null;

            C3DLandDb.FeatureLine feature = null;
            Polyline3d            poly    = null;
            var layername = "";

            Debug.WriteLine("Starting AddCivil2016BreaklineByTrans");

            try
            {
                using (Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (Transaction tr = CivilApplicationManager.StartTransaction())
                    {
                        var checkPoly = polyId.GetObject
                                            (OpenMode.ForRead, false, true) as Polyline;

                        if (checkPoly != null)
                        {
                            featureId = C3DLandDb.FeatureLine.Create
                                            (GetFeatureLineName(), polyId, siteId);

                            layername = checkPoly.Layer;
                            var color = checkPoly.Color;

                            feature = featureId.GetObject(OpenMode.ForWrite) as C3DLandDb.FeatureLine;

                            feature.Layer = layername;
                            feature.Color = color;
                        }
                        else
                        {
                            tr.Abort();
                            Debug.WriteLine("Aborted AddCivil2016BreaklineByTrans " +
                                            layername + " Count: " + checkPoly.NumberOfVertices);
                        }

                        tr.Commit();

                        Debug.WriteLine("Ending AddCivil2016BreaklineByTrans" +
                                        layername + " Count: " + checkPoly.NumberOfVertices);

                        return(featureId);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 private static void AddPropertySetToObjects(UiData uiData, ObjectId propertySetDefinitionId, Transaction trans)
 {
     foreach (List <ObjectId> ids in uiData.classObjectIdsMap.Values)
     {
         foreach (ObjectId id in ids)
         {
             Autodesk.AutoCAD.DatabaseServices.DBObject obj = trans.GetObject(id, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.DBObject;
             PropertyDataServices.RemovePropertySet(obj, propertySetDefinitionId);
             PropertyDataServices.AddPropertySet(obj, propertySetDefinitionId);
         }
     }
 }
 private void SetAttributes(Dictionary<String, String> attrs, ObjectId objId)
 {
     WriteLock = true;
     if (attrs.ContainsKey("modelid"))
     {
         this.BaseModelId = Utils.ModelIdManager.Parse(attrs["modelid"]);
         if (ApplicationBaseModels.ContainsKey(this.BaseModelId))
         {
             ApplicationBaseModels[this.BaseModelId] = this;
         }
         else
         {
             ApplicationBaseModels.Add(this.BaseModelId, this);
         }
     }
     this.BaseObjectId = objId;
     this._SetAttributes(attrs);
     WriteLock = false;
 }
 public void ResetAttributes(Dictionary<String, String> _attrs, ObjectId objId)
 {
     attrs.Clear();
     if (_attrs.ContainsKey("modelid"))
     {
         this.BaseModelId = Utils.ModelIdManager.Parse(_attrs["modelid"]);
         if (ApplicationBaseModels.ContainsKey(this.BaseModelId))
         {
             ApplicationBaseModels[this.BaseModelId] = this;
         }
         else
         {
             ApplicationBaseModels.Add(this.BaseModelId, this);
         }
     }
     this.BaseObjectId = objId;
     foreach(var item in _attrs)
     {
         attrs.Add(item.Key, item.Value);
     }
 }