Author Topic: Compiling DesignCAD add-ons using Lazarus  (Read 1139 times)

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4121
Compiling DesignCAD add-ons using Lazarus
« on: July 10, 2015, 12:19:59 PM »
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.

2016 marks my 24th year in DesignCAD-Land!

SFA

  • Full Member
  • ***
  • Posts: 227
  • *
    • Stanley Fyffe Associates
Re: Compiling DesignCAD add-ons using Lazarus
« Reply #1 on: July 13, 2015, 02:24:12 PM »
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

  • Hero Member
  • *****
  • Posts: 1329
  • hokus pokus
    • Magic Systems
Re: Compiling DesignCAD add-ons using Lazarus
« Reply #2 on: July 14, 2015, 12:20:47 AM »
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

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4121
Re: Compiling DesignCAD add-ons using Lazarus
« Reply #3 on: July 14, 2015, 06:39:20 AM »
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
2016 marks my 24th year in DesignCAD-Land!

SManMTB

  • Jr. Member
  • **
  • Posts: 78
Re: Compiling DesignCAD add-ons using Lazarus
« Reply #4 on: July 15, 2015, 12:14:17 AM »
Great info.

SFA

  • Full Member
  • ***
  • Posts: 227
  • *
    • Stanley Fyffe Associates
Re: Compiling DesignCAD add-ons using Lazarus
« Reply #5 on: July 15, 2015, 02:42:55 AM »
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