Compiling DesignCAD add-ons using Lazarus

Started by DrollTroll, July 10, 2015, 12:19:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DrollTroll

Lazarus is a free, mostly-Delphi-compatible programming environment that utilizes FreePascal.

It can be used to create DesignCAD OLE Automation programs in much the same way as Delphi.

First thing you need to do is download and install Lazarus. The latest version can be found here:
http://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/

Once Lazarus is installed, you will also need to install the LazActiveX add-on, which allows you to import type libraries. You'll need to import the DesignCAD type library in order to access the OLE Automation commands exposed by DesignCAD.
To install LazActiveX, start Lazarus.
From the Package menu, choose Install/Uninstall Packages.
In the right-hand panel, labeled "available for installation", choose the LazActiveX package (as of this writing it's labeled "LazActiveX 0.1").
Click on "Install Selection", then "Save and rebuild IDE".
Lazarus will re-compile itself to include the new LazActiveX package.
When it's done, the Tools menu should now include an "Import Type Library" option.

From here on out, using Lazarus is just about the same as using Delphi.

Example:
Start a new lazarus project. By default it will include a form named Form1.
Save the project with the name "LazarusTestProject", and the form with the name "LazarusTestProjectForm".
From the Tools menu, choose "Import Type Library". Browse to the folder containing your version of DesignCAD, and select dcadnn.tlb, where nn is the DesignCAD version. Save the resulting DesignCAD_nn_n_Tlb file to the same folder as your new project.
In the LazarusTestProject file, remove the new uses entry for DesignCAD_nn_n_Tlb.
Add a button to your form, and double-click it to open the form's code.
Add DesignCAD_nn_n_Tlb to the form's uses clause. Also add ComObj to the uses clause.
In the button click function, add a var clause and the following variables:
DcApp: IDcadApp;
DcDocs: IDcadDocuments;
DcDoc; IDcadDocument;

In the function's code, add these lines:
DcApp := GetActiveOleObject('DesignCAD.Application');
DcApp.Visible := True;
DcDocs := DcApp.Documents;
DcDoc := DcDocs.Add;
ShowMessage('There are ' + IntToStr(DcDocs.Count) + ' documents open at this time.');

Compile and run the project. If a copy of DesignCAD was not open, it'll probably throw an error. If a copy of DesignCAD was open, a new drawing should be created, and a message will appear indicating how many drawings are currently open.

Note that you may have to run DesignCAD once by right-clicking on the icon and choosing "Run as Administrator". This will load the DesignCAD class information into the registry.

Attached is a Lazarus project for DesignCAD 3D Max 24 which touches a few properties of the PrintOption class.

25 years with DesignCAD

SFA

DT,

Thank you very much.

I can't find dcadnn.tlb or dcad24.tlb or dcad241.tlb anywhere to rename. Am I being a bit daft?

Stan
SEMPER IN EXCRETIA

magic

Hi SFA,

You'll find Dcadnn.tlb in the DesignCAD program folder.

For instance:

On a 32 bit Windows machine the type library for DesignCAD 3D MAX 24 is called Dcad24.tlb, and you'll find it at c:\Program Files\IMSIDesign\DesignCAD 3D Max 24\Dcad24.tlb

On a 64 bit Windows machine the type library for DesignCAD 3D MAX 24 is called Dcad24.tlb, and you'll find it at c:\Program Files (86)\IMSIDesign\DesignCAD 3D Max 24\Dcad24.tlb

If Windows Explorer doesn't show the .tlb extension, you can let the cursor hover over the Dcad24 files one at a time and you'll get a box showing the Type of file you're looking at.

Hope this helps.
It's a kind of magic!




DrollTroll

Also, you don't rename the .tlb file.

When you import a DesignCAD type library using Lazarus, it creates a new Pascal file named DesignCAD_nn_n_TLB.pas. That's the file I was referring to when discussing the uses clause. the "nn_n" part is based on the internal version number of the type library.

DT
25 years with DesignCAD


SFA

THANK YOU

I can't believe it !

It has worked and I can now compile a Lazarus application (if that is what they are called?) so all I have to do now is write the application.

I will keep you posted.

Stan
SEMPER IN EXCRETIA

Zarathustra

Dear Members,

now, after my Python experiments are abortive, I'm using Lazarus again. But I have a problem while starting my Macro as exe-file from my own macro-toolbox.

I think that my program did not know that a dc-session ist started if i start my exe-Program as macro. If I start with doubleclick from explorer or desktop my program/macro is still working.

If I start it from DesignCAD there is no connection to DC.

I think that line

DcApp := GetActiveOleObject('DesignCAD.Application.24') as IDcadApp;

would not work if the program was starting as  macro.

Did anyone know about this problem?

Best regards

Zarathustra

DrollTroll

#7
I'd need to see how you're starting the exe from the macro.
Typically, if you're running an OLE Automation program from within a macro, in the macro you'd use something like

RUN "MyAutomationProgram.exe", 2

Note the uses of the 'status' flag after the program name in the RUN statement documentation for macros, and also the ResumeBasicCAD command in the OLE Automation docs.


CAVEAT: I haven't done any of this in some time now, so I may mis-remember, or behaviors may have been changed.
25 years with DesignCAD