News:

Please note new Forum URL: forum.designcad.com

Main Menu

DesignCad 17 and Lazarus

Started by Zarathustra, October 23, 2012, 02:09:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zarathustra

Dear DesignCad users,

now it's possible to write DesignCad-Macro with Lazarus and FreePascal. You need a Snapshot of Lazarus IDE with fpc 2.6.1.

In Folder ...\lazarus\fpc\2.6.1\bin\i386-win32 is a File called importtl.exe for importing the typlibrary.

Or you have a look at http://wiki.freepascal.org/LazActiveX. There is a gui-tool to import the library.

It is a little bit tricky, because there are a lot of warnings in the pas-File of the library.

I used "SetCommandPoints" Function SetCommandPoints(iNumberOfPoints As Integer, pXYZPoints As Array of Double) As Integer
and there was trouble because of the pXYZPoints. They should be a PSafeArray. I changed it to Variant an after that to PsafeArray.

I hope that the following code explain what is to do:


procedure ZeichneKurve(Kurve: Integer);
var
  S: String;
  i, j, n, SkalFak: Integer;
  ZWArray: Variant;
  ZVArray: PVarArray;
  Punkte: PSafeArray;
  xStart, yStart, zStart: Double;
begin
  S := InputBox('Skalierfaktor für DesginCad','1 s entspricht ?? Meter','1');
  If S = '' then Exit;
  ShowMessage('Bitte den Startpunkt der Kurve wählen');
  DcPts.GetUserPoint(xStart,yStart,zStart);
  SkalFak := StrToInt(S);
  j := 0;
  n := Serie[Kurve].Count;
  ZWArray := VarArrayCreate([0, 3*n], varDouble);
  for i:=0 to (n div 3) do begin
       j := 3 * i;
       ZWArray[j] := (Serie[Kurve].GetXValue(j) + xStart) * SkalFak;
       j :=j + 1;
       ZWArray[j] := (Serie[Kurve].GetYValue(j-1) + yStart);
       j := j + 1;
       ZWArray[j] := 0.0 + zStart;
  end;
  [color=red]ZVArray := VarArrayAsPSafeArray(ZWArray);[/color]
  [color=red]Punkte := PSafeArray(ZVArray);[/color]                      // The red lines switch the Array to PSafeArray!!!!!
  DcDoc.Application.BusyCursor(True);
  DcDoc.SilentMode:=True;
  [color=green]DcPts.SetCommandPoints((n div 3)+1,Punkte);[/color]  // And Punkte (Points) are PSafeArray.
  DcLine.Draw;
  DcApp.BusyCursor(False);
  DcDoc.Application.BusyCursor(False);
end;


Please sorry about my mad and silly english.

Greetings

Zarathustra


dcadRob

Interesting.
Have you compared speed to native BasicCAD?

DrollTroll

The speed should be very similar to what you get with an external Delphi or C++ program -- it's still out-of-process communication with DesignCAD, where as BasicCAD is in-process.
25 years with DesignCAD