コード例 #1
0
        public void Cmd_Scatter()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            var objIds = acCurEd.GetAllSelection(false);

            if (objIds.Length <= 0)
            {
                return;
            }

            var random = new Random();

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                var extents = acTrans.GetExtents(objIds, acCurDb);
                var extCen  = Solid3DExtensions.GetBoxCenter(extents.MinPoint, extents.MaxPoint);

                foreach (var obj in objIds)
                {
                    var acEnt = acTrans.GetObject(obj, OpenMode.ForWrite) as Entity;
                    if (acEnt == null)
                    {
                        continue;
                    }

                    var entExt = acTrans.GetExtents(new[] { acEnt.ObjectId }, acCurDb);
                    var entCen = Solid3DExtensions.GetBoxCenter(entExt.MinPoint, entExt.MaxPoint);

                    var cPower = extCen.GetVectorTo(entCen).MultiplyBy(random.NextDouble());

                    acEnt.TransformBy(Matrix3d.Displacement(cPower));
                }

                acTrans.Commit();
            }
        }
コード例 #2
0
ファイル: RcExplode.cs プロジェクト: chuongmep/RabCab
        public void Cmd_RcExplode()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            var objIds = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null,
                                                      "\nSelect solid assembly to explode: ");

            if (objIds.Length <= 0)
            {
                return;
            }

            var explodePoint = acCurEd.Get2DPoint("\nSelect insertion point for exploded view: ");

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                var extents    = acTrans.GetExtents(objIds, acCurDb);
                var extCen     = Solid3DExtensions.GetBoxCenter(extents.MinPoint, extents.MaxPoint);
                var centryMove = extCen.GetVectorTo(new Point3d(explodePoint.X, explodePoint.Y, extCen.Z));

                foreach (var obj in objIds)
                {
                    var acSol = acTrans.GetObject(obj, OpenMode.ForWrite) as Solid3d;
                    if (acSol == null)
                    {
                        continue;
                    }

                    var cSol = acSol.Clone() as Solid3d;
                    if (cSol == null)
                    {
                        continue;
                    }

                    var eInfo = new EntInfo(acSol, acCurDb, acTrans);
                    var cInfo = new EntInfo(cSol, acCurDb, acTrans);

                    acCurDb.AppendEntity(cSol, acTrans);

                    var pHandle = acSol.Handle;
                    var cHandle = cSol.Handle;

                    eInfo.ChildHandles.Add(cHandle);

                    cInfo.ParentHandle = pHandle;
                    cInfo.ChildHandles.Clear();

                    acSol.AddXData(eInfo, acCurDb, acTrans);
                    cSol.AddXData(cInfo, acCurDb, acTrans);

                    var cCen   = cSol.MassProperties.Centroid;
                    var cPower = extCen.GetVectorTo(cCen).MultiplyBy(SettingsUser.ExplodePower);

                    cSol.TransformBy(Matrix3d.Displacement(cPower));
                    cSol.TransformBy(Matrix3d.Displacement(centryMove));
                }

                acTrans.Commit();
            }
        }
コード例 #3
0
ファイル: RcVpConvert.cs プロジェクト: chuongmep/RabCab
        public void Cmd_VpToVb()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            var userCmdEcho = AcVars.CmdEcho;

            AcVars.CmdEcho = Enums.CmdEcho.Off;

            // Set up our selection to only select 3D solids
            var pso = new PromptSelectionOptions {
                MessageForAdding = "\nSelect viewports to convert: "
            };
            var sf = new SelectionFilter(new[] { new TypedValue((int)DxfCode.Start, "VIEWPORT") });

            //Get the 3d Solid Selection
            var res = acCurEd.GetSelection(pso, sf);

            if (res.Status == PromptStatus.OK)
            {
                // extract the viewport points
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    acCurDb.TransactionManager.QueueForGraphicsFlush();

                    using (
                        var pWorker = new ProgressAgent("Converting Viewports: ", res.Value.Count))
                    {
                        var deleteVps = false;

                        foreach (var objId in res.Value.GetObjectIds())
                        {
                            if (!pWorker.Progress())
                            {
                                acTrans.Abort();
                                return;
                            }

                            var psVpPnts = new Point3dCollection();

                            using (var psVp = acTrans.GetObject(objId, OpenMode.ForWrite) as Viewport)
                            {
                                // get the vp number
                                if (psVp != null)
                                {
                                    // now extract the viewport geometry
                                    psVp.GetGripPoints(psVpPnts, new IntegerCollection(), new IntegerCollection());

                                    // let's assume a rectangular vport for now, make the cross-direction grips square
                                    var tmp = psVpPnts[2];
                                    psVpPnts[2] = psVpPnts[1];
                                    psVpPnts[1] = tmp;

                                    var msVpPnts = new Point3dCollection();
                                    foreach (Point3d pnt in psVpPnts)
                                    {
                                        var xform = psVp.Dcs2Wcs() * psVp.Psdcs2Dcs();
                                        // add the resulting point to the ms pnt array
                                        msVpPnts.Add(pnt.TransformBy(xform));
                                    }

                                    var layoutName = LayoutManager.Current.CurrentLayout;

                                    LayoutManager.Current.CurrentLayout = "Model";

                                    var extents = acCurDb.TileMode
                                        ? new Extents3d(acCurDb.Extmin, acCurDb.Extmax)
                                        : (int)Application.GetSystemVariable("CVPORT") == 1
                                            ? new Extents3d(acCurDb.Pextmin, acCurDb.Pextmax)
                                            : new Extents3d(acCurDb.Extmin, acCurDb.Extmax);

                                    using (var view = acCurEd.GetCurrentView())
                                    {
                                        var viewTransform =
                                            Matrix3d.PlaneToWorld(psVp.ViewDirection)
                                            .PreMultiplyBy(Matrix3d.Displacement(view.Target - Point3d.Origin))
                                            .PreMultiplyBy(Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection,
                                                                             view.Target))
                                            .Inverse();

                                        extents.TransformBy(viewTransform);

                                        view.ViewDirection = psVp.ViewDirection;
                                        view.Width         = (extents.MaxPoint.X - extents.MinPoint.X) * 1.2;
                                        view.Height        = (extents.MaxPoint.Y - extents.MinPoint.Y) * 1.2;
                                        view.CenterPoint   = new Point2d(
                                            (extents.MinPoint.X + extents.MaxPoint.X) / 2.0,
                                            (extents.MinPoint.Y + extents.MaxPoint.Y) / 2.0);
                                        acCurEd.SetCurrentView(view);
                                    }

                                    // once switched, we can use the normal selection mode to select
                                    var selectionresult = acCurEd.SelectCrossingPolygon(msVpPnts);

                                    if (selectionresult.Status != PromptStatus.OK)
                                    {
                                        return;
                                    }

                                    var layout =
                                        (Layout)
                                        acTrans.GetObject(LayoutManager.Current.GetLayoutId(layoutName),
                                                          OpenMode.ForRead);

                                    LayoutManager.Current.CurrentLayout = layoutName;

                                    try
                                    {
                                        var ext   = acTrans.GetExtents(selectionresult.Value.GetObjectIds());
                                        var cenPt = Solid3DExtensions.GetBoxCenter(ext.MinPoint, ext.MaxPoint);
                                        var insPt = cenPt.TransformBy(psVp.Ms2Ps());

                                        CreateBaseViewFromVp(selectionresult, psVp, acCurEd, acCurDb, layout, insPt);

                                        deleteVps = true;
                                    }
                                    catch (Exception e)
                                    {
                                        deleteVps = false;
                                        acCurEd.WriteMessage(e.Message);
                                        MailAgent.Report(e.Message);
                                    }
                                }
                            }
                        }

                        if (deleteVps)
                        {
                            foreach (var objId in res.Value.GetObjectIds())
                            {
                                var vp = acTrans.GetObject(objId, OpenMode.ForWrite);
                                vp.Erase();
                                vp.Dispose();
                            }
                        }

                        acTrans.Commit();
                    }
                }
            }

            AcVars.CmdEcho = userCmdEcho;
        }