Exemplo n.º 1
0
        public static void Create(Polyline CenterLine, double Width, Color C)
        {
            #region PRE
            Document     acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database     acDb    = acDoc.Database;
            DocumentLock acDL    = acDoc.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, true);
            Editor       acDocEd = acDoc.Editor;
            #endregion

            #region T
            using (Transaction T = acDb.TransactionManager.StartTransaction())
            {
                var BT  = (BlockTable)T.GetObject(acDb.BlockTableId, OpenMode.ForRead);
                var BTR = (BlockTableRecord)T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                var ObjColl1 = CenterLine.GetOffsetCurves(Width / 2);
                var ObjColl2 = CenterLine.GetOffsetCurves(-Width / 2);

                foreach (Entity obj in ObjColl1)
                {
                    obj.Color = C;
                    BTR.AppendEntity(obj);
                    T.AddNewlyCreatedDBObject(obj, true);
                }
                foreach (Entity obj in ObjColl2)
                {
                    obj.Color = C;
                    BTR.AppendEntity(obj);
                    T.AddNewlyCreatedDBObject(obj, true);
                }

                T.Commit();
            }
            #endregion
        }
Exemplo n.º 2
0
 modifyLayer(ObjectId idLayer, short colorIndex, LineWeight weight, string nameLineType = null)
 {
     try
     {
         using (BaseObjs._acadDoc.LockDocument())
         {
             using (Transaction tr = BaseObjs.startTransactionDb())
             {
                 LayerTableRecord Ltr = (LayerTableRecord)tr.GetObject(idLayer, OpenMode.ForWrite);
                 Ltr.Color      = Color.FromColorIndex(ColorMethod.ByBlock, colorIndex);
                 Ltr.LineWeight = weight;
                 if (nameLineType != null)
                 {
                     LinetypeTable LTT = Base_Tools45.LineType.getLineTypeTable();
                     if (LTT.Has(nameLineType) == false)
                     {
                         BaseObjs._db.LoadLineTypeFile(nameLineType, "acad.lin");
                     }
                     Ltr.LinetypeObjectId = LTT[nameLineType];
                 }
                 tr.Commit();
             }
         }
     }
     catch (System.Exception ex)
     {
         BaseObjs.writeDebug(ex.Message + " Layer.cs: line: 346");
     }
 }
Exemplo n.º 3
0
        manageLayer(string strLayerName, short color = 256, bool layerOff = false, bool layerFrozen = false)
        {
            manageLayers(strLayerName);
            Database DB = BaseObjs._db;

            try
            {
                using (BaseObjs._acadDoc.LockDocument())
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        LayerTable       LT  = (LayerTable)tr.GetObject(DB.LayerTableId, OpenMode.ForRead);
                        LayerTableRecord Ltr = tr.GetObject(LT[strLayerName], OpenMode.ForWrite) as LayerTableRecord;
                        Ltr.Color    = Color.FromColorIndex(ColorMethod.ByLayer, color);
                        Ltr.IsOff    = layerOff;
                        Ltr.IsFrozen = layerFrozen;
                        tr.Commit();
                    } //end using
                }     //end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Layer.cs: line: 238");
            }
        }
Exemplo n.º 4
0
        public static Hatch CreateHatch(ObjectId ID, string Type, Color C)
        {
            var Return = new Hatch();

            using (Transaction T = Doc.TransactionManager.StartTransaction())
            {
                var BT  = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Return.SetDatabaseDefaults();

                var OC = new ObjectIdCollection();
                OC.Add(ID);

                Return.SetDatabaseDefaults();
                Return.SetHatchPattern(HatchPatternType.PreDefined, Type);
                Return.Associative = true;
                Return.AppendLoop(HatchLoopTypes.Default, OC);
                Return.EvaluateHatch(true);
                Return.Color = C;

                BTR.AppendEntity(Return);
                T.AddNewlyCreatedDBObject(Return, true);
                T.Commit();
            }

            return(Return);
        }
Exemplo n.º 5
0
        public static Polyline CreateRectangle(Point3d SP, double W, double H, Color C)
        {
            var Return = new Polyline();

            using (Transaction T = Doc.TransactionManager.StartTransaction())
            {
                var BT  = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                var P = new Point2d(SP.X, SP.Y);

                Return.SetDatabaseDefaults();

                Return.AddVertexAt(0, P, 0, 0, 0);
                Return.AddVertexAt(1, MoveP(P, W, 0), 0, 0, 0);
                Return.AddVertexAt(2, MoveP(P, W, H), 0, 0, 0);
                Return.AddVertexAt(3, MoveP(P, 0, H), 0, 0, 0);
                Return.AddVertexAt(4, MoveP(P, 0, 0), 0, 0, 0);

                Return.Color = C;

                BTR.AppendEntity(Return);
                T.AddNewlyCreatedDBObject(Return, true);
                T.Commit();
            }

            return(Return);
        }
Exemplo n.º 6
0
        public static List <Triangle> ToCeometricCADDataTriangleList(ObjectId[] faceIDs)
        {
            Database        workingDatabase = HostApplicationServices.WorkingDatabase;
            List <Triangle> list            = new List <Triangle>();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                string     blockModelSpaceName = SymbolUtilityServices.BlockModelSpaceName;
                LayerTable arg_30_0            = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                for (int i = 0; i < faceIDs.Length; i++)
                {
                    Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(faceIDs[i], (OpenMode)0, true);
                    LayerTableRecord layerTableRecord           = (LayerTableRecord)transaction.GetObject(face.LayerId, (OpenMode)0);
                    Autodesk.AutoCAD.Colors.Color color         = face.Color;
                    if (color.IsByLayer)
                    {
                        color = layerTableRecord.Color;
                    }
                    System.Drawing.Color empty = System.Drawing.Color.Empty;
                    short colorIndex           = 256;
                    Conversions.GetColors(color, ref empty, ref colorIndex);
                    CADData cADData = new CADData();
                    cADData.Layer.Name = layerTableRecord.Name;
                    cADData.Color      = empty;
                    cADData.ColorIndex = colorIndex;
                    cADData.BlockName  = blockModelSpaceName;
                    Point3d vertexAt  = face.GetVertexAt(0);
                    Point3d vertexAt2 = face.GetVertexAt(1);
                    Point3d vertexAt3 = face.GetVertexAt(2);
                    Point3d vertexAt4 = face.GetVertexAt(3);
                    ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                    ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                    ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                    ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                    if (point != point2 && point != point3 && point != point4 && point2 != point3 && point2 != point4 && point3 != point4)
                    {
                        list.Add(new Triangle(point, point2, point4, false)
                        {
                            CADData = cADData
                        });
                        list.Add(new Triangle(point2, point3, point4, false)
                        {
                            CADData = cADData
                        });
                    }
                    else
                    {
                        list.Add(new Triangle(point, point2, point3, false)
                        {
                            CADData = cADData
                        });
                    }
                }
            }
            return(list);
        }
Exemplo n.º 7
0
        public static void GetColors(Autodesk.AutoCAD.Colors.Color acColor, ref System.Drawing.Color color, ref short colorIndex)
        {
            color      = System.Drawing.Color.Empty;
            colorIndex = 256;
            switch ((int)acColor.ColorMethod)
            {
            case 192:
                color      = System.Drawing.Color.Empty;
                colorIndex = 256;
                return;

            case 193:
                color      = System.Drawing.Color.Empty;
                colorIndex = 0;
                return;

            case 194:
                color = System.Drawing.Color.FromArgb((int)acColor.ColorValue.A, (int)acColor.ColorValue.R, (int)acColor.ColorValue.G, (int)acColor.ColorValue.B);
                return;

            case 195:
                color      = System.Drawing.Color.Empty;
                colorIndex = acColor.ColorIndex;
                return;

            case 196:
                color      = System.Drawing.Color.Empty;
                colorIndex = 7;
                return;

            case 197:
                color      = System.Drawing.Color.Empty;
                colorIndex = 7;
                return;

            case 198:
                color      = System.Drawing.Color.Empty;
                colorIndex = 7;
                return;

            case 199:
                color      = System.Drawing.Color.Empty;
                colorIndex = 7;
                return;

            case 200:
                color      = System.Drawing.Color.Empty;
                colorIndex = 7;
                return;

            default:
                return;
            }
        }
 private void OnCommandEnd(object sender, CommandEventArgs e)
 {
     if (e.GlobalCommandName.CompareTo("REVCLOUD") == 0)
     {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         Database db  = doc.Database;
         PromptSelectionResult lastRes = doc.Editor.SelectLast();
         if (lastRes.Value != null && lastRes.Value.Count == 1)
         {
             //先给云线改颜色
             using (Transaction tr = db.TransactionManager.StartTransaction())
             {
                 //绑定数据
                 Autodesk.AutoCAD.Colors.Color selectedColor = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0);
                 int index = ToolPanel.currentConnectedType;
                 if (index == 1)
                 {
                     selectedColor = Autodesk.AutoCAD.Colors.Color.FromRgb(233, 150, 122);
                 }
                 else if (index == 2)
                 {
                     selectedColor = Autodesk.AutoCAD.Colors.Color.FromRgb(30, 144, 255);
                 }
                 else if (index == 3)
                 {
                     selectedColor = Autodesk.AutoCAD.Colors.Color.FromRgb(102, 249, 207);
                 }
                 doc.Editor.WriteMessage(index.ToString());
                 if (index != 0)
                 {
                     Entity ent = (Entity)tr.GetObject(lastRes.Value[0].ObjectId, OpenMode.ForRead);
                     ent.UpgradeOpen();
                     ent.Color = selectedColor;
                     //是否继续循环
                 }
                 tr.Commit();
                 //Utility.makeImageBottom();
             }
             District district = new District(currentSolution);
             district.BaseObjectId = lastRes.Value[0].ObjectId;
             Error err = district.CheckAndSave(ToolPanel.currentConnectedType);
             if (err.Err != Error.ErrorCode.NoErr)
             {
                 System.Windows.MessageBox.Show(err.Message);
                 district.RemoveSelf();
             }
             currentSolution.Districts.Add(district.BaseObjectId, district);
             //MessageBox.Show("in");
             ToolPanel.DrawCloudLine();
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 레이어를 추가하는 메소드입니다. 레이어가 존재한다면, 그 레이어의 색깔만 바꿔줍니다.
        /// </summary>
        /// <param name="LayerName">추가할 레이어의 이름입니다.</param>
        /// <param name="AcadColor">추가할 레이어의 색깔입니다.</param>
        /// <returns>추가한 레이어의 ObjectId를 리턴합니다.</returns>
        public static ObjectId AddLayer(string LayerName, AcColor.Color AcadColor = null)
        {
            Document doc      = AcadApp.DocumentManager.MdiActiveDocument;
            Database db       = doc.Database;
            ObjectId oLayerId = ObjectId.Null;

            try
            {
                using (doc.LockDocument())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        LayerTable       oLayers = tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
                        LayerTableRecord oLayer  = null;

                        if (oLayers.Has(LayerName)) // 가지고 있다면 속성을 변경해준다.
                        {
                            oLayer = tr.GetObject(oLayers[LayerName], OpenMode.ForWrite) as LayerTableRecord;
                            if (AcadColor != null)
                            {
                                oLayer.Color = AcadColor;
                            }
                        }
                        else
                        {
                            oLayer      = new LayerTableRecord();
                            oLayer.Name = LayerName;
                            if (AcadColor != null)
                            {
                                oLayer.Color = AcadColor;
                            }

                            oLayers.Add(oLayer);
                            tr.AddNewlyCreatedDBObject(oLayer, true);
                        }

                        oLayerId = oLayer.Id;

                        tr.Commit();
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.Print(string.Format("************에러발생************\n위치 : AddLayer\n메시지 : {0}", ex.Message));
                return(ObjectId.Null);
            }

            return(oLayerId);
        }
Exemplo n.º 10
0
        public static Line CreateLine(Point3d SP, Point3d EP, Color C)
        {
            var Return = new Line();

            using (Transaction T = Doc.TransactionManager.StartTransaction())
            {
                var BT  = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Return = new Line(SP, EP);

                Return.Color = C;

                BTR.AppendEntity(Return);
                T.AddNewlyCreatedDBObject(Return, true);
                T.Commit();
            }

            return(Return);
        }
Exemplo n.º 11
0
        public static Polyline CreateCenterRectangle(Point3d SP, double W, double H, Color C)
        {
            var Return = new Polyline();

            using (Transaction T = Doc.TransactionManager.StartTransaction())
            {
                var BT  = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                var P = MoveP(SP, -W / 2, -H / 2);

                CreateCenterRectangle(P, W, H, C);

                BTR.AppendEntity(Return);
                T.AddNewlyCreatedDBObject(Return, true);
                T.Commit();
            }

            return(Return);
        }
Exemplo n.º 12
0
        public Layer(LayerTableRecord layer)
        {
            _id = layer.Id;
            _name = layer.Name;
            _color = layer.Color;
            _visibility = !layer.IsOff;

            _points = new ObservableCollection<Point>();
            _lines = new ObservableCollection<Line>();
            _circles = new ObservableCollection<Circle>();

            _selectedPoint = new Point();
            _selectedLine = new Line();
            _selectedCirle = new Circle();
        }
Exemplo n.º 13
0
        public Layer()
        {
            _id = new ObjectId();
            _name = "layer";
            _color = AcadC.Color.FromRgb(255, 255, 255);
            _visibility = true;

            _points = new ObservableCollection<Point>();
            _lines = new ObservableCollection<Line>();
            _circles = new ObservableCollection<Circle>();

            _selectedPoint = new Point();
            _selectedLine = new Line();
            _selectedCirle = new Circle();
        }
Exemplo n.º 14
0
 public void SetProperties(Autodesk.AutoCAD.Colors.Color color)
 {
     mColor = color;
 }
Exemplo n.º 15
0
 private CountOverrule()
 {
     mColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 1);
     SetCustomFilter();
 }