Jump to content

Getting the last command typed from AutoCAD via .NET program


ChristinaSeay

Recommended Posts

Hello,

 

I am trying to get the last command typed from AutoCAD via a VB.NET program. Does anyone know how to do that... or a better way possibly to achieve this:

 

User Types "B1" on the command line, which uses a lisp routine to launch program A and put a Purchased Balloon on the drawing.

 

User Types "B2" on the command line, which uses a lisp routine to launch program B and put an Assembly Balloon on the drawing.

 

What I'd like to be able to do is to make programs A and B into a single program, X, and then when the user types "B1", launch program X and put a purchased balloon on the drawing, and when the user types "B2" launch program X again, but put an Assembly Balloon on the drawing.

 

Is this possible?

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • ChristinaSeay

    12

  • BlackBox

    7

  • stmoong

    5

  • Kerry Brown

    1

Without having more detailed information, the short answer is YES... it is possible.

 

More specifically though, you potentially require the source code for programs A and B.

 

If you do not have the source code, then you might consider using a reactor.

 

Sidebar: You have not specified which application you're using, but if this is simply a series of commands to insert some blocks, then why not use LISP instead?

(Does not apply to non-ActiveX API applications)

 

Hope this helps!

Link to comment
Share on other sites

I have the source code for everything since I wrote it all, so that won't be a problem.

 

The programs A and B are doing a lot more than just inserting a block into AutoCAD, so doing them in AutoLisp just isn't feasible, and VBA would be doable, but significantly more complicated... especially since the programs have already been written in .NET.

 

I think if there were some way to determine the last command entered in AutoCAD, that would probably give me what I need. Then I could launch program X no matter if the user types B1 or B2 and then the first thing X would do is to determine what the user typed last into AutoCAD to determine if they wanted a Purchased Balloon or Assembly Balloon... if that makes sense...?

Link to comment
Share on other sites

Yes that make perfect sense.

 

Would it not be simpler to add a condition to the beginning of program X, which seeks global variables defined at the end of programs A and B respectively?

 

For example:

 

If you were to run Program A, once complete, define variable *prgA* = True.

If you were to run Program B, once complete, define variable *prgB* = True.

 

In this case, when you run program X:

 

if *prgA* /= True, then run program A

if *prgB* /= True, then run program B

 

Make sense?

 

Note - Please forgive my lack of .NET syntax, as I am relegated to working with Visual LISP only at work.

Link to comment
Share on other sites

What I'm trying to go for is that there wouldn't be a Program A and Program B anymore... they would be combined into one Program X. (There are actually about 15 different programs that will combined into Program X.)

 

Currently the drafters are used to working with shortcuts on the command line and they want to keep those versus just popping up a form with all the options on it. So that leaves me forced to maintain 15 separate programs that have a lot of similar code in them and would be soooo much cleaner and easier for me to maintain as one program.

 

I wish I was stuck with one language... it would make it easier. The company I work for is more of the opinion that I should do whatever in whatever language it takes so long as it works... lol

Link to comment
Share on other sites

Conceptually speaking, let's consider Toolbox functions...

 

Instead of duplicating segments of code among your 15 separate programs, is it not possible to pick out a few representative segments and make a single toolbox function for each of those specific, repeated tasks?

 

For example:

 

If you repetitively need to extract the layer of an item, you make a toolbox function that does nothing but that, provided an argument (where the argument is the object, or reference item the layer is being extracted from). In the middle of your program, when you need the layer of an object, simply call that toolbox function.

 

As another example, I have a toolbox function that does nothing but return the blocks collection of my active drawing, as this can be updated within a command. Sort of like a snapshot, if you will. I can store this function (as it returns a snapshot) to a variable, within my current program.

 

I am speaking conceptually, and lacking .NET code for these examples, so I hope I am making sense...?

Link to comment
Share on other sites

What you're saying makes perfect sense... but I'm not repeating AutoCAD functions... my programs are connecting to our ERP system, our drawing database program, our file vault system, etc.... so toolbox functions wouldn't save much effort.

Link to comment
Share on other sites

Hi, just wondering, if your program X is going to be in .Net, can you skip the Lisp routine and just call the appropriate method in your .Net program directly? Just need to netload it on startup.

 

You could implement design pattern such as strategy pattern to take advantage of the object oriented methodology, or use procedural methods (if-else, switch-case) to call the appropriate methods based on user input on command line.

Link to comment
Share on other sites

It sounds like you've got the right idea for what I'm trying to accomplish, but I'm not sure how to do exactly what you're saying... Can you elaborate on it a bit...?

Link to comment
Share on other sites

Hi, I'm not sure if you already know how to set up the AutoCad project in Visual Studio. In case you don't, here are the steps you can take.

 

1) Download the appropriate ObjectArx SDK from AutoCad website. You need to download the correct SDK for the different version of AutoCad.

 

2) Either download the documentation or view it online from here.

 

The documentation will give you an idea how to set up a project in Visual Studio. There are also sample codes that you can work with to get a feel on how the methods are called via the command line in AutoCad.

Link to comment
Share on other sites

I've been programming to AutoCAD for a while, but I haven't used the ObjectARX method because we're using so many different versions of AutoCAD and it isn't available for some of the versions. Instead, I made my projects where they include a late-binding reference to AutoCAD so one program can communicate with all the versions.

 

We have AutoCAD 2002 Standard, 2010 Standard, 2010 Electrical, 2009 Standard and 2009 Mechanical.

Link to comment
Share on other sites

I'm not familiar with Lisp.

 

If purely on OO programming, you could use the strategy pattern. Basically, you declare an interface. Your various programs will be a concrete class that will implement this interface.

 

I assume you are able to pass in some value when your Lisp routine calls the .Net application. In order for your program X to know what concrete class to instantiate, you could use a factory pattern, which takes in the value and instantiate the right concrete class (your program A, B, C, etc).

 

Then, your main program X will just call the generic interface method.

Link to comment
Share on other sites

I'm just using LISP to kick off the program... they have a startup lisp set up that loads some base functions... when they type "B1" it will start Program A.exe for example.

 

I don't think I can pass values in because of the ClickOnce Application in .NET. I'm launching the setup.exe program, not the program application... so any values passed to the launching program go into the ClickOnce exe application and not the actual Program A.

 

Which leaves me, I think, stuck where I need to have Program X determine the last command typed by the user so I can say "If the user typed B1 then do this, if the user typed B2 then do this, etc"... which the switch-case statement would be perfect for.

Link to comment
Share on other sites

Yeah... that thought crossed my mind... it seemed a bit clunky... but doable.

 

It just seems like AutoCAD should have the information somewhere for the last commands typed by the user since ENTER, SPACEBAR both repeat the last command typed and you can press the up arrow key and scroll through the last commands as well... so AutoCAD has that information somewhere...

Link to comment
Share on other sites

It looks like this guy is doing what I'm needing to do somewhat:

http://www.visiblevisual.com/index.php/AutoCad-VB/VBA/last-command-stoolbar.html

 

He's making a toolbar of the last 10 commands used... but I'm not sure exactly how. It looks like the program is set to be launched each time a command is used in AutoCAD... but somehow he's getting the command they typed into the program as a string and using it... which is what I need to do...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...