.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Somebody help me how to insert block, but waiting for user input rotation.
Solved! Go to Solution.
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
-------------------------------------------------------------------------
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D
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.
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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,
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
-------------------------------------------------------------------------
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
-------------------------------------------------------------------------
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Insert Block and waiting for user input rotation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.


