Solved

Catching Autocad events with Delphi

Posted on 2006-11-09
6
1,008 Views
Last Modified: 2012-06-21
I'm writing an application with dephi 5 that control Autocad 2005. In term of getting Autocad to draw what I need its working just fine but   I would like my application to be notify when either an application or a document event is trigged like " Application activate" or "Begin save" . I read on the web that I have to write "an event sink generator" for which I need code example. For now my application crash when I try the following code :

 unit Unit2;

interface
uses AutoCAD_TLB,ComObj,windows;
procedure ActivateAcad();
implementation
 var
  AutoCADApplication:IAcadApplication;
  AcadDoc:TAcadDocument;

procedure ActivateAcad();
begin
AutoCADApplication := CreateOleObject('AutoCAD.Application')as IAcadApplication;
AutoCADApplication.Visible := true;

AcadDoc.ConnectTo(AutoCADApplication.ActiveDocument); // This is the problematic line....

end;

end.



0
Comment
Question by:jboivin2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17911872
Maybe you do it elsewhere, but from the code you list above, you never instantiate an instance of AcadDoc (which I assume is the TOleServer component wrapper).

eg:

 AcadDoc:=TAcadDocument.Create(Application); // Or form, etc, whatever the owner is desired to be
 AcadDoc.ConnectTo(AutoCADApplication.ActiveDocument);
 ....


Regards,
Russell

 
0
 

Author Comment

by:jboivin2
ID: 17913714
Thanks Russell. A good start but what about this event sink generator ?
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 17913897

Show me what the compiler genertated for the TAcadDocument ole server component. Usually you will find that the event sink interface has already been handled and exposed as delphi events.

Russell

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jboivin2
ID: 17921345
Following your comment I had look at AutoCAD_TLB and  as you said, Delphi eventsare exposed  in the TAcadDocument component wrapper ;
...

TAcadDocument = class(TOleServer)
 
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    property Server: TAcadDocumentProperties read GetServerProperties;
{$ENDIF}
    property OnBeginSave: TAcadDocumentBeginSave read FOnBeginSave write FOnBeginSave;
    property OnEndSave: TAcadDocumentEndSave read FOnEndSave write FOnEndSave;
    property OnBeginCommand: TAcadDocumentBeginCommand read FOnBeginCommand write FOnBeginCommand;
    property OnEndCommand: TAcadDocumentEndCommand read FOnEndCommand write FOnEndCommand;
    property OnBeginLisp: TAcadDocumentBeginLisp read FOnBeginLisp write FOnBeginLisp;
...
I had therefore drop on my form the TAcadDocument component, which i wasn't using at all up to now, and got only " No such interface supported" messsage when I was setting Autoconnect to true;
I then tried to get the connection form a procedure similar to the one we already discuss:

Procedure ActivateAcad();
begin
        Acad := CreateOleObject('AutoCAD.Application')as IAcadApplication;
        Acad.Visible := true;
        form1.AcadDoc:=TAcadDocument.Create(Application); // not sure this one is necessary
        form1.AcadDoc.ConnectTo(Acad.ActiveDocument);
end;

I did not get any error messages but no result  for :



procedure TForm1.AcadDocActivate(Sender: TObject);
begin

showmessage('youppi');
end;

procedure TForm1.AcadDocWindowMovedOrResized(Sender: TObject;
  HWNDFrame: Integer; bMoved: WordBool);
begin
showmessage('youppi');
end;

procedure TForm1.AcadDocBeginSave(Sender: TObject;
  var FileName: OleVariant);
begin
showmessage('youppi');


What is wrong ?

Regards
Johnny


0
 

Author Comment

by:jboivin2
ID: 17921417
I found what was missing

 procedure ActivateAcad();
begin
        Acad := CreateOleObject('AutoCAD.Application')as IAcadApplication;
        Acad.Visible := true;
        form1.AcadDoc.ConnectTo(Acad.ActiveDocument);
        form1.AcadDoc.OnActivate(application);// was missinn

        end;

Thanks Russel for your guidance
0
 

Expert Comment

by:paulo_psa
ID: 22694171
He is doing what I need but it's not working to me.
They are using D5 and Autocad 5. I'm using D7 Autocad 8.
Things looks similar but doesn't work.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 104
Delphi selector screen 2 91
Firemonkey DbLookupComboBox equivalent ? 2 66
Tidtcpserver listening on multiports? 1 42
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question