.NET

Reply
Active Contributor
farrukhw
Posts: 26
Registered: ‎05-07-2009
Message 1 of 19 (851 Views)
Accepted Solution

Calling -INSERT Command from AutoCAD.net (2012).

851 Views, 18 Replies
07-03-2012 03:39 AM

Hi Guys

I'm using CSharp and I want to call -INSERT command while passing it the path of my dwg files. This call would be done via my DragDrop class.

I tried doc.SendStringToExecute(InsertCmd, true, false, true); but it then waits for user to press enter there...

 

So how can we call AutoCAD's Commands from our .Net code?

 

Any help?

 

Thanks

Hi,

 

Try this (with your blockname):

   Dim tCmd as String = "_INSERT" & vbCr & "C:\TEMP\myBlock.DWG" & vbCr

   doc.SendStringToExecute(tCmd, true, true, false)

 

The orange parts show how to send <ENTER>

 

- alfred -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 2 of 19 (849 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-03-2012 04:00 AM in reply to: farrukhw

Hi,

 

Try this (with your blockname):

   Dim tCmd as String = "_INSERT" & vbCr & "C:\TEMP\myBlock.DWG" & vbCr

   doc.SendStringToExecute(tCmd, true, true, false)

 

The orange parts show how to send <ENTER>

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
farrukhw
Posts: 26
Registered: ‎05-07-2009
Message 3 of 19 (844 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-03-2012 04:52 AM in reply to: Alfred.NESWADBA

Hi Alferd,

Thanks a lot for quick reply....It worked... I also was reading similar thing (in the example code) here:
http://adndevblog.typepad.com/autocad/2012/06/use-log-file-and-setvar-command-to-get-a-list-of-autoc...

 

So equivalent of VbCrlf is \r \n and Here is my little code:
        [CommandMethod("cmdTest")]
        static public void SendCmd()
        {
            string File_DWG = @"D:\sym\1047.DWG";
            string InsertCmd = @"_.-INSERT " + File_DWG + '\r' + '\n';
            Document doc = Application.DocumentManager.MdiActiveDocument;
            doc.SendStringToExecute(InsertCmd, true, false, false);
        }

 

Thanks a bunch

 

:smileyhappy:

Contributor
matinau
Posts: 25
Registered: ‎05-03-2010
Message 4 of 19 (822 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-04-2012 02:02 AM in reply to: farrukhw

Having the same problem using C#

string InsertCmd = @"_.-INSERT " + File_DWG + '\r' + '\n';

 

still didn't work? and causes CAD to crash? Any ideas?

Active Contributor
farrukhw
Posts: 26
Registered: ‎05-07-2009
Message 5 of 19 (819 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-04-2012 02:23 AM in reply to: matinau

Mine is working properly at this time by adding \r and \n.. Try using only \n...I'm using AutoCAD 2012...

Is that closing AutoCAD? or there is some crash report???

 

can you please post your code segment?

Contributor
matinau
Posts: 25
Registered: ‎05-03-2010
Message 6 of 19 (816 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-04-2012 02:58 AM in reply to: farrukhw

I've tried various combinations to no avail? Not sure what's wrong? I'm running 2012, my code passes a blkNam which is present in the block table. It asks for the insertion point and then crashes.

 

string InsertCmd = @"_.-INSERT " + blkNam + '\r' + '\n';

doc.SendStringToExecute(InsertCmd, true, false, false);

 

I've also tried this approach, which works but I can't figure out how to pass the scales prompt?

 

string InsertCmd = "(command \"_insert\" \"" + blkNam + "\" " + ")\n";

 

...confused

*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 7 of 19 (813 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-04-2012 04:17 AM in reply to: matinau

Hi,

 

you can always try it manually by typing the commands/options/values into the command-line .. .and for every <ENTER> you have to use \n instead.

 

So start typing

_-INSERT<ENTER>

TABLE<ENTER>              ...or whatever your block's name is

....and now see the options you can set before the block is inserted, e.g.

 

_SCALE<ENTER>

1<ENTER>

...

 

So the LISP-result (without C#-conventions) may look like that:

(command "_-INSERT" "TABLE" "_SCALE" "1")

 

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
farrukhw
Posts: 26
Registered: ‎05-07-2009
Message 8 of 19 (809 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-04-2012 05:48 AM in reply to: matinau

As far I remember, when you issue -INSERT, it will give your Scale, Move and rotate prompt. In addition, while experimenting with different *.dwg files, it also prompted to enter Tag number and at some file, it prompted to Select Tag.

I guess, that is due to the Block Attributes present in that dwg, but I'm not sure...

And -INSERT automate those Prompts for you.

 

 

Valued Contributor
CommCorp
Posts: 98
Registered: ‎03-19-2007
Message 9 of 19 (794 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-05-2012 05:08 AM in reply to: farrukhw

Is there a reason you have to use "-Insert"?

It is my understanding, and general rule to avoid using "Sendcommand" and "Sendstringtoexecute" whenever possible.

Why can't you use dot net and add the desired block to the current drawing database?

Contributor
matinau
Posts: 25
Registered: ‎05-03-2010
Message 10 of 19 (791 Views)

Re: Calling -INSERT Command from AutoCAD.net (2012).

07-05-2012 05:15 AM in reply to: CommCorp
Simplicity, I wrote a block insert function in .net but found adding rotate and attribute values overly complicated. Managed to get the sendcommand working, can post later Thanks for everyone's help Sent from my iPhone
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.