.NET

Reply
Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 1 of 4 (619 Views)

JIG multiple entities

619 Views, 3 Replies
03-26-2013 01:37 AM

Hi Pro,

 

How to Jig multiple entities such as insert a block and add a line.

 

Thanks,

*Expert Elite*
_gile
Posts: 2,086
Registered: ‎04-29-2006
Message 2 of 4 (610 Views)

Re : JIG multiple entities

03-26-2013 02:10 AM in reply to: xdbk07

hi,

 

You can build a class which derives from DrawJig.

 

Here's a little example to drag multiple entities. The entites passed to DragEntitiesJig instance have to be opened within a transaction.

 

    class DragEntitiesJig : DrawJig
    {
        Point3d basePoint, dragPoint;
        IEnumerable<Entity> ents;

        public DragEntitiesJig(IEnumerable<Entity> ents, Point3d basePoint)
        {
            this.basePoint = basePoint;
            this.ents = ents;
        }

        protected override bool WorldDraw(WorldDraw draw)
        {
            WorldGeometry wGeom = draw.Geometry;
            Matrix3d disp = Matrix3d.Displacement(this.basePoint.GetVectorTo(this.dragPoint));
            wGeom.PushModelTransform(disp);
            foreach (Entity ent in this.ents)
            {
                wGeom.Draw(ent);
            }
            wGeom.PopModelTransform();
            return true;
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions options = new JigPromptPointOptions("\nSecond point: ");
            options.BasePoint = this.basePoint;
            options.UseBasePoint = true;
            options.Cursor = CursorType.RubberBand;
            options.UserInputControls = UserInputControls.Accept3dCoordinates;
            PromptPointResult ppr = prompts.AcquirePoint(options);
            if (ppr.Value.IsEqualTo(this.dragPoint))
                return SamplerStatus.NoChange;
            this.dragPoint = ppr.Value;
            return SamplerStatus.OK;
        }
    }

 

Gilles Chanteau
Moderator
Alexander.Rivilis
Posts: 1,417
Registered: ‎04-09-2008
Message 3 of 4 (609 Views)

Re: JIG multiple entities

03-26-2013 02:14 AM in reply to: xdbk07
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 4 (567 Views)

Re: JIG multiple entities

03-26-2013 12:59 PM in reply to: xdbk07

Here is code example very limited tested on A2010

see if this works,keep in mind, to change Clone method jn

DeepCloneObjects if your entities have Xdata embedded

        // based on Kean Walmsley example (jig mtext)
         [CommandMethod("dej")]
        public void MoveCopyJig()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = doc.Editor;
            try
            {
                using (Transaction tr = doc.TransactionManager.StartTransaction())
                {
                    SelectionSet sset = ed.GetSelection().Value;
                    Point3d basept = ed.GetPoint("\nBase point: ").Value;
                    IEnumerable<Entity> objs = sset.GetObjectIds().Select(x => (Entity)tr.GetObject(x, OpenMode.ForRead)).ToArray();
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (Entity e in objs)
                    {
                        Entity c = (Entity)e.Clone();// you may want to use DeepCloneObjects instead
                        btr.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);

                    }
                    ed.SetImpliedSelection(sset);

                    PromptSelectionResult psr = ed.SelectImplied();

                    // drag our jig

                    if (psr.Status == PromptStatus.OK)
                    {
                        // jig whole selection

                        PromptPointResult ppr =
                          ed.Drag(
                            psr.Value,
                            "\nSpecify displacement point: ",
                            delegate(Point3d pt, ref Matrix3d mat)
                            {
                                // If no change has been made, say so
                                if (basept == pt)
                                    return SamplerStatus.NoChange;
                                else
                                {
                                    // Otherwise we return the displacement
                                    // matrix for the current position
                                    mat = Matrix3d.Displacement(basept.GetVectorTo(pt)
                                      );
                                }
                                return SamplerStatus.OK;
                            }
                          );

                        // Assuming it works, transform our MText
                        // appropriately

                        if (ppr.Status == PromptStatus.OK)
                        {
                            // Get the final translation matrix

                            Matrix3d mat = Matrix3d.Displacement(basept.GetVectorTo(ppr.Value)
                              );

                            foreach (Entity en in objs)
                            {
                                en.UpgradeOpen();
                                en.TransformBy(mat);
                            }
                        }
                        // Finally we commit our transaction
                        tr.Commit();
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.ToString());
            }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.