Ejemplo n.º 1
0
        public void 零件自动套料()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acDb  = acDoc.Database;
            Editor   acEd  = acDoc.Editor;

            //if (Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("NEXTFIBERWORLD").ToString() != "0") Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("NEXTFIBERWORLD", 0);
            if (acEd.CurrentUserCoordinateSystem.IsEqualTo(Matrix3d.Identity) == false)
            {
                acEd.CurrentUserCoordinateSystem = Matrix3d.Identity;
            }
            List <Part>            listParts = new List <Part>();
            PromptSelectionOptions pso       = new PromptSelectionOptions();

            pso.RejectObjectsFromNonCurrentSpace = true;
            pso.AllowDuplicates  = false;
            pso.MessageForAdding = "选择零件" + Environment.NewLine;
            SelectionFilter sf  = new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.Start, RXClass.GetClass(typeof(Polyline)).DxfName) });
            var             psr = acEd.GetSelection(sf);

            if (psr.Status != PromptStatus.OK)
            {
                return;
            }
            int i = 1;

            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            foreach (SelectedObject dbobj in psr.Value)
            {
                using (Transaction trans = acDb.TransactionManager.StartTransaction())
                {
                    Polyline pline = trans.GetObject(dbobj.ObjectId, OpenMode.ForWrite) as Polyline;
                    Part     p     = new Part(pline, i, acEd);
                    DBText   t     = new DBText()
                    {
                        Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 171), TextString = "Part" + p.partNumber, Position = p.CenterPnt, Rotation = p.RotateAngle
                    };
                    if (p.Length < p.Width)
                    {
                        t.Height = p.Length / 5;
                    }
                    else
                    {
                        t.Height = p.Width / 5;
                    }
                    p.itemInsidePart.Add(Tools.AddToModelSpace(acDb, t));
                    listParts.Add(p);
                    trans.Commit();
                }
                i++;
            }
            var orderParts = listParts.OrderBy(c => c.Length).ThenBy(c => c.Width).ToList();

            if (orderParts.Count > 0)
            {
                if (this.mfrm == null)
                {
                    this.mfrm = new MainForms {
                        listParts = orderParts, acDoc = acDoc
                    };
                    this.mfrm.FormClosing += Mfrm_FormClosing;
                    Application.ShowModelessDialog(this.mfrm);
                }
            }
            else
            {
                Application.ShowAlertDialog("未找到零件请重新选择零件!");
            }
            //Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("NEXTFIBERWORLD", 1);
        }
Ejemplo n.º 2
0
 private void Mfrm_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
 {
     this.mfrm = null;
 }