• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 15
    Registered: ‎05-31-2012
    Accepted Solution

    Insert Block and waiting for user input rotation

    279 Views, 12 Replies
    06-14-2012 12:57 AM

    Somebody help me how to insert block, but waiting for user input rotation.

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Insert Block and waiting for user input rotation

    06-14-2012 01:17 AM in reply to: Nk_long

    Hi,

     

    as there are muliple methods available of how to insert a block (starting with sendcommand, using com or doing it with managed coding) show what you have currently, so we know where to continue/step in.

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎05-31-2012

    Re: Insert Block and waiting for user input rotation

    06-14-2012 02:14 AM in reply to: alfred.neswadba

    My work is insert a block (waiting for user input rotation) then delete a polyline. I used 'SendStringToExecute' method.

     

    My solution:

            public static ObjectId DgiongID;
            public static event EventHandler eRainManhole;

            [CommandMethod("RainManhole")]
            public static void RainManhole()
            {
                if (eRainManhole != null)
                {
                    eRainManhole(null, null);
                }
            }

     

            [CommandMethod("Rman")]
            public static void InsertRman()
            {


                ......

                Get one point form user

                Offset from one center line to this point, this offset objectID store in DgiongID

                User pick a  point in offset object store in Pchen
                Insert a block at that point and waiting for user input rotation, then delete object: DgiongID

                ......


                string command = "(command " + '"' + "Insert" + '"' + " " + '"' + "$RSman$ ";
                command = command + "'(" + Pchen.X + " " + Pchen.Y + ") ";
                command = command + "1 1 pause " + '"' + "RainManhole" + '"' + ") ";

                eRainManhole += new EventHandler(DeleteGiong);
                acDoc.SendStringToExecute(command, false, false, false);
            }

     

            public static void DeleteGiong(object sender, EventArgs e)
            {
                Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;
                Transaction acTrans = acCurDb.TransactionManager.StartTransaction();
                using (acTrans)
                {
                    DBObject Dgiong = (DBObject)acTrans.GetObject(DgiongID, OpenMode.ForWrite, true, true);
                    Dgiong.Erase();
                    acTrans.Commit();
                }
            }

     

     

    With this solution everyhing is done. But the problem is if user hit the UP ARROW KEY in AutoCAD command history is not my defined command, they have to hit twice if want to get 'RMAN' command. It's not flexible for user when they want to do this function continuously. So I ask for a better solution.

     

    thanks.

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,338
    Registered: ‎10-08-2008

    Re: Insert Block and waiting for user input rotation

    06-14-2012 02:42 AM in reply to: Nk_long

    Perhaps, you might want to use Getangle method?
    Here is my 2 cents:

            [CommandMethod("insRot")]
            public void InsertSample()
            {
                // put your block name here
                string blkname = "ARW";
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
    
                //Specify insertion point
                PromptPointOptions ppo = new PromptPointOptions("\nPick Insertion point:");
                PromptPointResult ppr = ed.GetPoint(ppo);
                if (ppr.Status != PromptStatus.OK)
                    return;
                Point3d p1 = ppr.Value;
                //Specify rotation angle
                PromptAngleOptions pae = new PromptAngleOptions("\nSpecify an angle:");
                pae.DefaultValue = 0.0;
                pae.BasePoint = p1;
                pae.UseBasePoint = true;
                PromptDoubleResult ares = ed.GetAngle(pae);
                if (ares.Status != PromptStatus.OK)
                    return;
                double ang = ares.Value;
    
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        // get the block table
                        BlockTable bt =  tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                        // check if block exists
                        if (!bt.Has(blkname))
                        {
                            ed.WriteMessage("\nBlock does not exist!");
                            return;
                        }
                        // get objectid of BlockTableRecord
                        ObjectId blkid = bt[blkname];
                        // get the current space
                        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                        // create  new BlockReference
                        BlockReference bref = new BlockReference(p1, blkid);
                        bref.SetDatabaseDefaults();
                        // set block rotation
                        bref.Rotation = ang;
                        // set scale
                        bref.ScaleFactors = new Scale3d(1);
                        //set layer
                        bref.Layer = "0";
                        //' ETC...
                        // add block to database and transaction
                        btr.AppendEntity(bref);
                        tr.AddNewlyCreatedDBObject(bref, true);
    
                        // < rest your work with attributes here > '
    
                        //commits the drawing changes
                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
                    }
                }
    
            }

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎05-31-2012

    Re: Insert Block and waiting for user input rotation

    06-14-2012 03:12 AM in reply to: Hallex

    thank you Mr. Hallex. It's really usefull. But I need when waiting for input rotation. We already insert the block. The user can see how the block rotate in screen.

    regard,

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Insert Block and waiting for user input rotation

    06-14-2012 03:35 AM in reply to: Nk_long

    Hi,

     

    >> With this solution everyhing is done. But the problem is if user hit the UP ARROW KEY in AutoCAD command history

    >> is not my defined command, they have to hit twice if want to get 'RMAN' command. It's not flexible for user when

    >> they want to do this function continuously. So I ask for a better solution.

    If you already use LISP in your SendCommand, then make a string based on your current one with defun():

    (defun C:XX() ( .... place your command here ....) )

    then send this with the first SendCommand

    After that start the following string with an extra SendCommand

    (command "XX")

    If your customer now repeats the last command, he will repeat XX and that is what you wanted, isn't it?

     

    - alfred -

     

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎05-31-2012

    Re: Insert Block and waiting for user input rotation

    06-14-2012 04:42 AM in reply to: alfred.neswadba

    Before I already did this way. The main function name is: Rman and the define new one in LISP is XX. But I need the lasted command in command history is the main function Rman, no more. In my solution. If user hit up key, command will return to (command .....) but right click (with settings in AutoCad options at 'User Preferences': No ShortCut menu..) it will launch my main function (Rman).

    In my thinking, if we use send command any way. the lasted command will be not main command. Is there another way to do it without sending command.

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Insert Block and waiting for user input rotation

    06-14-2012 04:52 AM in reply to: Nk_long

    Hi,

     

    then try for the last command not to start (command "XX") but just start XX

     

    HTH, - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,338
    Registered: ‎10-08-2008

    Re: Insert Block and waiting for user input rotation

    06-14-2012 05:00 AM in reply to: Nk_long

    Then you change your command string like this

     

                

                 string command = "(command " + '"' + "-insert" + '"' + " " + '"' + "Your block name" + '"';
                        command = command + "(list " + p1.X + " " + p1.Y + ") ";
                        command = command + "1 1 " + "pause" + ") "; //+'"' + "RainManhole" + '"' + ") ";
    
                        //eRainManhole += new EventHandler(DeleteGiong);
                        doc.SendStringToExecute(command, true, false, false);

     where p1 is picked point from my code above

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎05-31-2012

    Re: Insert Block and waiting for user input rotation

    06-14-2012 05:55 AM in reply to: Hallex

    can not remove calling RainManhole in command. Also add event to it ( eRainManhole += new EventHandler(DeleteGiong):smileywink: Because of waiting finish this command, I need to continuous more work.

    Please use plain text.