check if in zero document state

Discussion in 'AutoCAD' started by weslleywang, Mar 22, 2005.

  1. weslleywang

    weslleywang Guest

    Hi:
    I am working on a layer state management routine. I like to know when autocad is in zero document state, so I can disable all the control in my form. since there are no ThisDrawing, how I can get the AcadApplication? I am going to play with GetObject, GetInterfaceObject. If anyone can give me a right direction, I will appreciate a million.


    thank you,
    Wes
     
    weslleywang, Mar 22, 2005
    #1
  2. weslleywang

    Jackrabbit Guest

    In Delphi but you should be able to adapt it:

    Code:
    unit Unit1;
    
    interface
    
    uses
    Windows,
    Messages,
    SysUtils,
    Variants,
    Classes,
    Graphics,
    Controls,
    Forms,
    Dialogs,
    ComObj,
    StdCtrls,
    AutoCAD_TLB;
    
    type
    TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    
    var
    Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    //------------------------------------------------------------------------------
    
    procedure ConnectToAcad(var Acad: AcadApplication);
    var
    Msg: string;
    begin
    try
    Acad := IDispatch(GetActiveOleObject('AutoCAD.Application.16')) as
    AcadApplication;
    if not Acad.Visible then
    begin
    Acad.Visible := True;
    end;
    except
    try
    Acad := IDispatch(CreateOleObject('AutoCAD.Application.16')) as
    AcadApplication;
    Acad.Application.WindowState := acMax;
    Acad.Visible := True;
    except
    Msg := 'Could not establish a connection to AutoCAD.';
    ShowMessage(Msg);
    Exit;
    end;
    end;
    end;
    
    //------------------------------------------------------------------------------
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Acad: AcadApplication;
    DocCount: Integer;
    begin
    ConnectToAcad(Acad);
    DocCount := Acad.Application.Documents.Count;
    Edit1.Text := IntToStr(DocCount);
    Acad := nil;
    end;
    
    //------------------------------------------------------------------------------
    
    end.
    
     
    Jackrabbit, Mar 23, 2005
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.