Example #1
0
        } // form 结束

        public Hashtable TuliList()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            // 识别图例 开始
            Hashtable tuliListData = new Hashtable();

            List <Polyline>       allLengenPolyine  = new List <Polyline>();
            List <BlockReference> blockTableRecords = new List <BlockReference>();
            List <DBText>         dbtextList        = new List <DBText>();
            List <MText>          mtextList         = new List <MText>();

            TypedValue[] tvs3 =
                new TypedValue[1] {
                new TypedValue(
                    (int)DxfCode.LayerName,
                    "图例"
                    )
            };

            SelectionFilter       sf3  = new SelectionFilter(tvs3);
            PromptSelectionResult psr3 = ed.SelectAll(sf3);
            SelectionSet          SS3  = psr3.Value;

            if (psr3.Status == PromptStatus.OK)
            {
                ObjectId[] idArray = SS3.GetObjectIds();
                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    for (int j = 0; j < idArray.Length; j++)
                    {
                        DBObject ob = acTrans.GetObject(idArray[j], OpenMode.ForRead);

                        if (ob is Polyline && (ob as Polyline).Closed)
                        {
                            allLengenPolyine.Add((ob as Polyline));
                        }
                        else if (ob is BlockReference)
                        {
                            blockTableRecords.Add(ob as BlockReference);
                        }
                        else if (ob is DBText)
                        {
                            dbtextList.Add(ob as DBText);
                        }
                        else if (ob is MText)
                        {
                            mtextList.Add(ob as MText);
                        }
                    }

                    List <string> title  = new List <string>();
                    Hashtable     tuxing = new Hashtable();

                    ArrayList backGroud = new ArrayList();
                    Dictionary <string, Hashtable> canvas = new Dictionary <string, Hashtable>();

                    // 找到面积最大的多段线
                    Dictionary <int, List <Polyline> > plList = MethodCommand.FindMaxAreaPoline(allLengenPolyine);
                    if (plList[0].Count > 0)
                    {
                        foreach (MText dBText in mtextList)
                        {
                            if (MethodCommand.FindDBTextIsInPolyine(dBText, plList[0]))
                            {
                                title.Add(dBText.Text);
                            }
                        }
                    }

                    ArrayList geom  = new ArrayList();
                    ArrayList type  = new ArrayList();
                    ArrayList color = new ArrayList();

                    //tuxing.Add("geom", GetAllLengedGemo());
                    tuxing.Add("type", type);
                    tuxing.Add("color", color);

                    tuliListData.Add("title", title);
                    tuliListData.Add("tuxing", tuxing);
                }
            }

            MessageBox.Show(tuliListData.ToString());
            return(tuliListData);
        }  // 识别图例 结束
Example #2
0
        public void GetAllLengedGemo(T model)
        {
            List <BlockInfoModel> list             = new List <BlockInfoModel>();
            List <Polyline>       allLengenPolyine = new List <Polyline>();
            Document           doc = Application.DocumentManager.MdiActiveDocument;
            ObjectIdCollection ids = new ObjectIdCollection();

            TypedValue[] filList = new TypedValue[1] {
                new TypedValue((int)DxfCode.LayerName, "图例")
            };

            PromptSelectionResult ProSset   = null;
            SelectionFilter       sfilter   = new SelectionFilter(filList);
            LayoutManager         layoutMgr = LayoutManager.Current;

            string ss = layoutMgr.CurrentLayout;

            ProSset = doc.Editor.SelectAll(sfilter);
            //  List<ObjectId> idss=  GetEntitiesInModelSpace();
            Database db = doc.Database;
            List <BlockReference> blockTableRecords = new List <BlockReference>();

            if (ProSset.Status == PromptStatus.OK)
            {
                using (Transaction tran = db.TransactionManager.StartTransaction())
                {
                    SelectionSet sst = ProSset.Value;

                    ObjectId[] oids = sst.GetObjectIds();

                    int           ad = 0;
                    List <string> aa = new List <string>();
                    LayerModel    lm = new LayerModel();
                    LayerTable    lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                    foreach (ObjectId layerId in lt)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                        if (ltr.Name == MethodCommand.LegendLayer)
                        {
                            lm.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                        }
                    }
                    for (int i = 0; i < oids.Length; i++)
                    {
                        //  if (idss.Contains(oids[i]))
                        //  {
                        DBObject ob = tran.GetObject(oids[i], OpenMode.ForRead);
                        // if (!aa.Contains((ob as Polyline).BlockName)) { aa.Add((ob as Polyline).BlockName); }
                        if (ob is Polyline && (((ob as Polyline).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel)))
                        {
                            if (ob == null)
                            {
                            }
                            else
                            {
                                allLengenPolyine.Add((ob as Polyline));
                            }//  lengedList.Add(ob as Polyline);
                             //  model.LegendPoints.Add(ad, PolylineMethod.GetPolyLineInfoPt(ob as Polyline));
                             // ad++;
                        }
                        else if (ob is BlockReference && (((ob as BlockReference).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel)))
                        {
                            blockTableRecords.Add(ob as BlockReference);
                        }
                    }
                    Dictionary <int, List <Polyline> > plList = MethodCommand.FindMaxAreaPoline(allLengenPolyine);
                    model.LegendList = new List <LengedModel>();
                    this.lengedList  = plList[0];
                    foreach (Polyline polyline in plList[0])
                    {
                        LengedModel legm = new LengedModel();
                        legm.GemoModels = new List <BlockInfoModel>();

                        legm.BoxPointList = PolylineMethod.GetPolyLineInfoPt(polyline);
                        List <ObjectId> ois = GetCrossObjectIds(doc.Editor, polyline, sfilter, tran);

                        if (ois != null)
                        {
                            foreach (ObjectId lengGemo in ois)
                            {
                                DBObject       ob      = tran.GetObject(lengGemo, OpenMode.ForRead);
                                BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);

                                if (plModel != null)
                                {
                                    if (plModel.Hatch != null)
                                    {
                                        HatchModel rem = new HatchModel();
                                        foreach (HatchModel hatchModel in plModel.Hatch)
                                        {
                                            if (polyline.Closed && hatchModel.Area.ToString("F2") == polyline.Area.ToString("F2"))
                                            {
                                                legm.BackGround = hatchModel.loopPoints.Count > 0? hatchModel.loopPoints[0].Color:"";
                                                rem             = hatchModel;
                                                break;
                                            }
                                        }
                                        plModel.Hatch.Remove(rem);
                                    }
                                    List <object> obj = new List <object>()
                                    {
                                        plModel
                                    };
                                    legm.GemoModels.Add(plModel);
                                }
                                //if (ob is Polyline && (ob as Polyline).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.PolyLine = AutoCad2ModelTools.Polyline2Model(ob as Polyline);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is BlockReference && (ob as BlockReference).BlockName.ToLower() == "*model_space")
                                //{
                                //    legm.GemoModels.Add(BlockCommand.AnalysisEntryAndExitbr(ob as BlockReference));
                                //}
                                //else if (ob is DBText && (ob as DBText).BlockName.ToLower() == "*model_space")
                                //{

                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as DBText);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is MText && (ob as MText).BlockName.ToLower() == "*model_space")
                                //{

                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as MText);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Hatch && (ob as Hatch).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.Hatch = AutoCad2ModelTools.Hatch2Model(ob as Hatch);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Circle && (ob as Circle).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.Circle.Add(AutoCad2ModelTools.Circle2Model(ob as Circle));
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Entity)
                                //{

                                //}
                            }
                        }
                        model.LegendList.Add(legm);
                    }
                }
            }
        }