예제 #1
0
        private RazmCollection CalcRazm(Autodesk.AutoCAD.EditorInput.SelectionSet sset)
        {
            using (var trans = AcadApp.StartTransaction())
            {
                try
                {
                    //result ********************************************
                    RazmCollection result = new RazmCollection();
                    //***************************************************
                    foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId id in sset.GetObjectIds())
                    {
                        //подсчет длин и площадей для Polyline Line Arc Circle и штук для BlockReference
                        Autodesk.AutoCAD.DatabaseServices.DBObject selOb;

                        selOb = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);

                        if (selOb.GetType().Name == "Polyline" || selOb.GetType().Name == "Line" || selOb.GetType().Name == "Arc" ||
                            selOb.GetType().Name == "Circle" || selOb.GetType().Name == "BlockReference")
                        {
                            foreach (var lineType in listOfTypes)
                            {
                                if ((lineType.EntityType == RazmType.typeOfEntity.Block) && (selOb.GetType().Name == "BlockReference"))
                                {
                                    Autodesk.AutoCAD.DatabaseServices.BlockReference blr = selOb as Autodesk.AutoCAD.DatabaseServices.BlockReference;
                                    if (blr.Name == lineType.Type)
                                    {
                                        string area = "";
                                        foreach (var paint in lineType.Paints)
                                        {
                                            area += paint.ShortTitle + ":" + paint.Amount + " ";
                                        }
                                        //For block references calculated only total amount and area inside RazmCollection into RazmData.NPP
                                        result.Add(new RazmData("1", lineType.Description, lineType.Type, "0.0", area, lineType.EntityType));
                                        break; // lineType
                                    }
                                }//BlockReference
                                else if ((lineType.EntityType == RazmType.typeOfEntity.Area) && (selOb.GetType().Name != "BlockReference"))
                                {
                                    Autodesk.AutoCAD.DatabaseServices.Curve cur = selOb as Autodesk.AutoCAD.DatabaseServices.Curve;
                                    if (cur.Linetype == lineType.LineTypeName)
                                    {
                                        string area = "";
                                        foreach (var paint in lineType.Paints)
                                        {
                                            area += paint.ShortTitle + ":" + (paint.Amount * GetArea(selOb)).ToString() + " ";
                                        }
                                        //For the area type calculated only area
                                        result.Add(new RazmData("1", lineType.Description, lineType.Type, "0.0", area, lineType.EntityType));
                                    }
                                }//Area
                                else if (((lineType.EntityType == RazmType.typeOfEntity.Line) ||
                                          (lineType.EntityType == RazmType.typeOfEntity.DoubleLineCenter) ||
                                          (lineType.EntityType == RazmType.typeOfEntity.DoubleLineSide)) && (selOb.GetType().Name != "BlockReference"))
                                {
                                    Autodesk.AutoCAD.DatabaseServices.Curve cur = selOb as Autodesk.AutoCAD.DatabaseServices.Curve;
                                    if (cur.Linetype == lineType.LineTypeName)
                                    {
                                        string area = "";
                                        foreach (var paint in lineType.Paints)
                                        {
                                            //This area without width. Width applayed in DisplayResult
                                            area += paint.ShortTitle + ":" + (paint.Amount * GetPaintedLength(GetLength(selOb), lineType)).ToString() + " ";
                                        }
                                        //For the line type calculated length and area
                                        result.Add(new RazmData("1", lineType.Description, lineType.Type, GetLength(selOb).ToString(), area, lineType.EntityType));
                                    }
                                }//Line
                            }// Foreach in listOfTypes
                        }//If allowed entity
                    }// Foreach in ssget
                    return result;
                }
                catch (System.Exception ex)
                {
                    AcadApp.AcaEd.WriteMessage("ERROR: MarkingCalc().CalcRazm " + ex + "\n");
                }
            }// using transaction
            return null;
        }