Solved

Catching Autocad events with Delphi

Posted on 2006-11-09
6
1,026 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
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.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

623 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