Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Catching Autocad events with Delphi

Posted on 2006-11-09
6
Medium Priority
?
1,055 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
  • 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 1500 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
Industry Leaders: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

927 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