Insert Block and waiting for user input rotation

Insert Block and waiting for user input rotation

Anonymous
Not applicable
2,864 Views
12 Replies
Message 1 of 13

Insert Block and waiting for user input rotation

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
2,865 Views
12 Replies
Replies (12)
Message 2 of 13

Alfred.NESWADBA
Consultant
Consultant

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
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 13

Anonymous
Not applicable

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.

0 Likes
Message 4 of 13

Hallex
Advisor
Advisor

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
Message 5 of 13

Anonymous
Not applicable

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,

0 Likes
Message 6 of 13

Alfred.NESWADBA
Consultant
Consultant

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
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 13

Anonymous
Not applicable

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.

0 Likes
Message 8 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

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

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 9 of 13

Hallex
Advisor
Advisor

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
0 Likes
Message 10 of 13

Anonymous
Not applicable

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

0 Likes
Message 11 of 13

Anonymous
Not applicable

Yes, correctly the last command is XX. But I need lasted is: Rman (with my code). That why, I told for another solution not send command.

Regard,

0 Likes
Message 12 of 13

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

sorry, then I totally misunderstood your need ;(

 

Well then there are two options, one is you use JIG's, the other one is to sendcommand RMAN as you last command with a built in break, so the command was called (for command history) but you have an option to cancel it when called at this specific way (but that's not a solution I would preferre).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 13 of 13

Anonymous
Not applicable

thanks a lot. I'll try to use JIG's.

 

Regard.

0 Likes