.NET

.NET

Reply
Contributor
Nk_long
Posts: 15
Registered: ‎05-31-2012
Message 1 of 13 (463 Views)
Accepted Solution

Insert Block and waiting for user input rotation

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

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

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 -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,598
Registered: ‎06-29-2007
Message 2 of 13 (461 Views)

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
-------------------------------------------------------------------------
Contributor
Nk_long
Posts: 15
Registered: ‎05-31-2012
Message 3 of 13 (455 Views)

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.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 13 (450 Views)

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
Contributor
Nk_long
Posts: 15
Registered: ‎05-31-2012
Message 5 of 13 (446 Views)

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,

*Expert Elite*
Alfred.NESWADBA
Posts: 9,598
Registered: ‎06-29-2007
Message 6 of 13 (444 Views)

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
-------------------------------------------------------------------------
Contributor
Nk_long
Posts: 15
Registered: ‎05-31-2012
Message 7 of 13 (442 Views)

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.

*Expert Elite*
Alfred.NESWADBA
Posts: 9,598
Registered: ‎06-29-2007
Message 8 of 13 (439 Views)

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
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 9 of 13 (437 Views)

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
Contributor
Nk_long
Posts: 15
Registered: ‎05-31-2012
Message 10 of 13 (434 Views)

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.