Author Topic: Command Line Prompt - left over garbage  (Read 1909 times)

0 Members and 1 Guest are viewing this topic.

dugk

  • Guest
Command Line Prompt - left over garbage
« on: July 23, 2010, 11:21:02 AM »
I've got this EntityJig that on the first run when canceled leave the Command Line prompt as the Jig prompt.  It only happens on the first run after being canceled.

In the video link http://screencast.com/t/ZTNjODJmMG you can see the command is started, after I hit the Place button on the dialog, the block(s) for the part are created, I drag it for a little bit and then I hit the Esc key.  The command cancels but as you'll see the Command Line is left as the Jig prompt "\nInsertion point".  I repeat the command and the Esc key and the Command Line is again the right Command Line prompt.

Any suggestions on how to correct this?

Thank you,
Doug

Code: [Select]
using System.Collections.Generic;
using System.Linq;

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

using AcApSrvApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace psPlc
{
    class BlockJig : EntityJig
    {
        private static BlockJig currentJig;
        private Point3d mPosition;
        private int mOffsetIdx;
        private Vector3d[] mOffset;
        private JigMessageFilter mMsgFilter;
        private Point3d _pos;
        private Dictionary<ObjectId, AttInfo> _attInfo;
        private Transaction _tr;

        public BlockJig(Transaction acTrans, BlockReference br, Dictionary<ObjectId, AttInfo> attInfo,
            ObjectId btrId, Vector3d[] nodeVectors)
            : base(br)
        {
            _pos = br.Position;
            _attInfo = attInfo;
            _tr = acTrans;
            mOffset = nodeVectors;
            mPosition = Point3d.Origin;
            Editor ed = AcApSrvApp.DocumentManager.MdiActiveDocument.Editor;
            Matrix3d ucsRotation = ed.CurrentUserCoordinateSystem;

            //cancel translation component of UCS matrix
            ucsRotation = ucsRotation.PostMultiplyBy(Matrix3d.Displacement(ucsRotation.Translation));

            //Respects UCS orientation
            Entity.TransformBy(ucsRotation);

            mOffsetIdx = 0;

            //We need to transform also those offsets depending of the UCS
            for (int idx = 0; idx < mOffset.Length; ++idx)
            {
                mOffset[idx] = mOffset[idx].TransformBy(ucsRotation);
            }

            //Setup message filter for SPACE keydown -> change the offset (could be any other key or controlled by jig key word...)
            mMsgFilter = new JigMessageFilter();
            System.Windows.Forms.Application.AddMessageFilter(mMsgFilter);
            currentJig = this;
        }

        public new BlockReference Entity
        {
            get
            {
                return base.Entity as BlockReference;
            }
        }

        protected override bool Update()
        {
            BlockReference br = Entity as BlockReference;

            Entity.Position = mPosition;
            br.Position = _pos;
            Entity.Position = mPosition;

            if (br.AttributeCollection.Count != 0)
            {
                foreach (ObjectId id in br.AttributeCollection)
                {
                    DBObject obj = _tr.GetObject(id, OpenMode.ForRead);
                    AttributeReference ar =
                      obj as AttributeReference;

                    // Apply block transform to att def position
                    if (ar != null)
                    {
                        ar.UpgradeOpen();
                        AttInfo ai = _attInfo[ar.ObjectId];
                        ar.Position =
                          ai.Position.TransformBy(br.BlockTransform);
                        if (ai.IsAligned)
                        {
                            ar.AlignmentPoint =
                              ai.Alignment.TransformBy(br.BlockTransform);
                        }
                        if (ar.IsMTextAttribute)
                        {
                            ar.UpdateMTextAttribute();
                        }
                    }
                }
            }
            return true;
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions jigOpts = new JigPromptPointOptions("\nInsertion point");
            jigOpts.UserInputControls = UserInputControls.NoZeroResponseAccepted |
                UserInputControls.NullResponseAccepted |
                UserInputControls.GovernedByOrthoMode |
                UserInputControls.Accept3dCoordinates;
            PromptPointResult res = prompts.AcquirePoint(jigOpts);
            psPlc.insertPn.basePoint = new Point3d(res.Value.X, res.Value.Y, res.Value.Z);
            if (res.Status == PromptStatus.Cancel)
                return SamplerStatus.Cancel;
            Point3d newPos = res.Value.Add(mOffset[mOffsetIdx]);
            if (mPosition == newPos)
                return SamplerStatus.NoChange;
            mPosition = newPos;
            return SamplerStatus.OK;
        }

        public PromptStatus Run()
        {
            PromptResult promptResult = AcApSrvApp.DocumentManager.MdiActiveDocument.Editor.Drag(this);

            return promptResult.Status;
        }

        public void MoveOffsetIndex()
        {
            mOffsetIdx = (++mOffsetIdx) % mOffset.Count();
        }

        public void Cleanup()
        {
            System.Windows.Forms.Application.RemoveMessageFilter(mMsgFilter);
        }

        class JigMessageFilter : System.Windows.Forms.IMessageFilter
        {
            int WM_KEYDOWN = 0x100;

            public bool PreFilterMessage(ref System.Windows.Forms.Message m)
            {
                if (m.Msg == WM_KEYDOWN)
                {
                    if ((int)m.WParam == 32 || (int)m.WParam == 9) //is this a tab or space?
                    {
                        currentJig.MoveOffsetIndex();

                        //triggers graphic update without the need to move the mouse
                        System.Windows.Forms.Cursor.Position = System.Windows.Forms.Cursor.Position;

                        //Block message for AutoCAD
                        return true;
                    }
                }
                return false;
            }
        }
    }
}


Bryco

  • Water Moccasin
  • Posts: 1883
Re: Command Line Prompt - left over garbage
« Reply #1 on: July 23, 2010, 07:20:11 PM »
Are you using CommandFlags.Session in the command call?

dugk

  • Guest
Re: Command Line Prompt - left over garbage
« Reply #2 on: July 24, 2010, 12:10:16 AM »
I found this (http://www.theswamp.org/index.php?topic=8204.0) to educate myself about CommandFlags and I tried it but it had no affect.

Thank you for the suggestion.

Any other suggestions?

Thanks,
Doug