コード例 #1
0
ファイル: MarkingCalc.cs プロジェクト: Lufan/Genplan2012
        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;
        }
コード例 #2
0
ファイル: AreaLinearCalc.cs プロジェクト: Lufan/Genplan2012
        private double[] CalcRes(Autodesk.AutoCAD.EditorInput.SelectionSet sset, Boolean isOnlyModelSpace, Boolean isOnlyPlineAllowed)
        {
            try
            {
                using (var trans = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                {
                    double length = 0;
                    double area = 0;
                    int count = 0;
                    foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId id in sset.GetObjectIds())
                    {

                        Autodesk.AutoCAD.DatabaseServices.BlockTableRecord BTR = (Autodesk.AutoCAD.DatabaseServices.BlockTableRecord)trans.GetObject(
                                                  trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead).OwnerId,
                                                  Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
                        string BTR_name = (BTR.Name).ToUpper();
                        if (isOnlyModelSpace && BTR_name != "*MODEL_SPACE")
                        {
                            continue;
                        }

                        if (isOnlyPlineAllowed)
                        {
                            Autodesk.AutoCAD.DatabaseServices.Polyline pline;
                            pline = (Autodesk.AutoCAD.DatabaseServices.Polyline)trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
                            length += pline.Length;
                            area += pline.Area;
                            count++;
                        }
                        else
                        {
                            Autodesk.AutoCAD.DatabaseServices.DBObject selOb;
                            selOb = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
                            if (selOb.GetType().Name == "Polyline")
                            {
                                length += ((Autodesk.AutoCAD.DatabaseServices.Polyline)selOb).Length;
                                area += ((Autodesk.AutoCAD.DatabaseServices.Polyline)selOb).Area;
                                count++;
                            }
                            else if (selOb.GetType().Name == "Line")
                            {
                                length += ((Autodesk.AutoCAD.DatabaseServices.Line)selOb).Length;
                                count++;
                            }
                            else if (selOb.GetType().Name == "Arc")
                            {
                                length += ((Autodesk.AutoCAD.DatabaseServices.Arc)selOb).Length;
                                area += ((Autodesk.AutoCAD.DatabaseServices.Arc)selOb).Area;
                                count++;
                            }
                            else if (selOb.GetType().Name == "Circle")
                            {
                                length += ((Autodesk.AutoCAD.DatabaseServices.Circle)selOb).Circumference;
                                area += ((Autodesk.AutoCAD.DatabaseServices.Circle)selOb).Area;
                                count++;
                            }
                        }
                    }
                    double[] result = { length, area, count };
                    return result;
                }// using transaction
            }
            catch (System.Exception ex)
            {
                LufsGenplan.AcadApp.AcaEd.WriteMessage("\nERROR: AcadApp.CalcRes() " + ex + "\n");
            }
            double[] result_error = { -1, -1, -1 };
            return result_error;
        }