Пример #1
0
        /// <summary>
        /// Öffnen einer Dwg ohne Editor
        /// </summary>
        //[_AcTrx.CommandMethod("Plan2TestSideDb")]
        static public void Plan2TestSideDb()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor   ed  = doc.Editor;
            // Ask the user to select a file
            _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: ");
            if (res.Status == _AcEd.PromptStatus.OK)
            {
                // Create a database and try to load the file
                _AcDb.Database db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, "");
                    }
                    catch (System.Exception)
                    {
                        ed.WriteMessage("\nUnable to read drawing file.");
                        return;
                    }

                    _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        // Open the blocktable, get the modelspace
                        _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);

                        // Iterate through it, dumping objects
                        foreach (_AcDb.ObjectId objId in btr)
                        {
                            _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead);

                            // Let's get rid of the standard namespace
                            const string prefix     = "Autodesk.AutoCAD.DatabaseServices.";
                            string       typeString = ent.GetType().ToString();
                            if (typeString.Contains(prefix))
                            {
                                typeString = typeString.Substring(prefix.Length);
                            }
                            ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " +
                                            ent.Layer + " with colour " + ent.Color.ToString());
                        }
                    }
                }
            }
        }
Пример #2
0
        public static void Plan2LayerAufteil()
        {
            var acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)_AcAp.Application.AcadApplication;

            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _Db = doc.Database;
            _AcEd.Editor ed = doc.Editor;
            try
            {
                _Tr = _Db.TransactionManager.StartTransaction();
                using (_Tr)
                {
                    // Open the blocktable, get the modelspace
                    _AcDb.BlockTable bt = (_AcDb.BlockTable)_Tr.GetObject(_Db.BlockTableId, _AcDb.OpenMode.ForRead);

                    foreach (var btrOid in bt)
                    {
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)_Tr.GetObject(btrOid, _AcDb.OpenMode.ForRead);
                        log.InfoFormat("Blocktable: {0}", btr.Name);
                        foreach (_AcDb.ObjectId objId in btr)
                        {
                            _AcDb.Entity ent = (_AcDb.Entity)_Tr.GetObject(objId, _AcDb.OpenMode.ForRead);
                            if (ent.GetType() == typeof(_AcDb.AttributeDefinition) ||
                                ent.GetType() == typeof(_AcDb.DBText) ||
                                ent.GetType() == typeof(_AcDb.MText) ||
                                ent.GetType() == typeof(_AcDb.Leader) ||
                                Regex.IsMatch(ent.GetType().Name, "Dimension", RegexOptions.IgnoreCase)
                                )
                            {
                                Correction(ent, suffix: "_T", isContinuous: true);
                            }
                            else
                            {
                                var blockRef = ent as _AcDb.BlockReference;
                                if (blockRef != null)
                                {
                                    Correction(ent, suffix: "_B", isContinuous: true);
                                }
                                else
                                {
                                    var hatch = ent as _AcDb.Hatch;
                                    if (hatch != null)
                                    {
                                        if (Regex.IsMatch(hatch.PatternName, "SOLID", RegexOptions.IgnoreCase))
                                        {
                                            Correction(ent, suffix: "_F", isContinuous: true);
                                        }
                                        else
                                        {
                                            Correction(ent, suffix: "_S", isContinuous: true);
                                        }
                                    }
                                    else
                                    {
                                        var solid = ent as _AcDb.Solid;
                                        if (solid != null)
                                        {
                                            Correction(ent, suffix: "_F", isContinuous: true);
                                        }
                                        else
                                        {
                                            CorrectionRest(ent);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    _Tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2LayerAufteil): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2LayerAufteil");
            }
        }
Пример #3
0
        private static bool PolyInPoly(_AcDb.Transaction tm, _AcDb.Entity inner, _AcDb.Entity outer)
        {
            if (inner == outer)
            {
                return(false);
            }
            if (!OverlapExtents(inner, outer))
            {
                return(false);
            }

            NrOfOverlaps++;

            if (inner is _AcDb.Polyline)
            {
                _AcDb.Polyline poly = inner as _AcDb.Polyline;
                for (int i = 0; i < poly.NumberOfVertices; i++)
                {
                    _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i);
                    if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else if (inner is _AcDb.Polyline2d)
            {
                _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)inner;
                foreach (_AcDb.ObjectId Vertex2d in oldPolyline)
                {
                    using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false))
                    {
                        _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d;

                        if (vertex == null)
                        {
                            string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString());
                            throw new InvalidOperationException(string.Format(msg));
                        }

                        _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex);
                        if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            else if (inner is _AcDb.Polyline3d)
            {
                _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)inner;
                foreach (_AcDb.ObjectId Vertex3d in poly3d)
                {
                    using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false))
                    {
                        _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d;

                        if (vertex == null)
                        {
                            string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString());
                            throw new InvalidOperationException(string.Format(msg));
                        }

                        _AcGe.Point3d vertexPoint = vertex.Position;
                        if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown entitytype '{0}'!", inner.GetType().Name));
        }