.NET

Reply
Active Contributor
42 Posts
0 Kudos
Registered: ‎11-06-2012
Post 1 of 4

JIG multiple entities

692 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*
2,142 Posts
255 Kudos
Registered: ‎04-29-2006
Post 2 of 4

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
1,467 Posts
277 Kudos
Registered: ‎04-09-2008
Post 3 of 4

Re: JIG multiple entities

03-26-2013 02:14 AM in reply to: xdbk07
*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 4

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!