.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Block and waiting for user input rotation

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Nk_long
1139 Views, 12 Replies

Insert Block and waiting for user input rotation

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

12 REPLIES 12
Message 2 of 13
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 13
Nk_long
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.

Message 4 of 13
Hallex
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
Message 5 of 13
Nk_long
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,

Message 6 of 13
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 13
Nk_long
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.

Message 8 of 13
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 9 of 13
Hallex
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
Message 10 of 13
Nk_long
in reply to: Hallex

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.

Message 11 of 13
Nk_long
in reply to: Alfred.NESWADBA

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,

Message 12 of 13
Alfred.NESWADBA
in reply to: Nk_long

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 13 of 13
Nk_long
in reply to: Alfred.NESWADBA

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

 

Regard.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost