Witam zainteresowanych!
Od razu lepiej napisze, że programista ze mnie żaden :-D. Mam następujący problem:
Znalazłem na stronce http://www.artoflog.com/cao/solidworks-delphi/delphi-solidworks.htm
kod programiku napisanego w delphi. Spodobał mi się do sporo projektuje w SolidWorks.
po nieznacznym zmodyfikowaniu kodu:
unit uMainTestSolidworksWithDelphi;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj, Math;
type
TformTest = class(TForm)
butTest: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure butTestClick(Sender: TObject);
private
public
end;
var
formTest: TformTest;
implementation
{$R *.dfm}
procedure TformTest.butTestClick(Sender: TObject);
var SldWorks : IDispatch;
SldDoc : IDispatch;
kolo1, szyk : IDispatch;
y, r, n : extended;
begin
y := (StrToFloat(Edit1.Text))/1000;
r := (StrToFloat(Edit2.Text))/1000;
n := StrToFloat(Edit3.Text);
try
SldWorks := GetActiveOleObject('SldWorks.Application');
if (SldWorks = nil) then
ShowMessage('nie moge nawiąza połączenia z SolidWorks')
else
begin
SldDoc := Variant(SldWorks).NewPart;
if SldDoc = nil then
ShowMessage('Nie mogę utworzyc nowej czesci')
else
begin
Variant(SldDoc).SetTitle2('Delphi-Solidworks-ArtOfLog');
Variant(SldDoc).SetAddToDB(TRUE);
kolo1 := Variant(SldDoc).CreateCircleByRadius2(0, y, 0, r/2);
szyk := Variant(SldDoc).CreateCircularSketchStepAndRepeat(y, DegToRad(270), n, 0, True, 0);
end
end
except
on E: Exception do
begin
ShowMessage(E.Message)
end;
end;
end;
end.
end
mam 2 problemy których nie mogę rozwiązać (z pewnością ze względu na nikłe wiadomości programistyczne).
problem 1:
jeśli SolidWorks nie jest uruchomiony nie wyświetla się informacja:
ShowMessage('nie moge nawiąza połączenia z SolidWorks')
oraz jeśli SW jest zajenty:
ShowMessage('Nie mogę utworzyc nowej czesci')
problem 2:
na tym najbardziej mi zależy!
Wszystko się pięknie rysuje ale na sam koniec, kiedy program tworzy szyk kołowy aplikacja wywala błąd : Could not convert variand of type (Boolean) into type (Dispatch)
kompletnie nie wiem o co chodzi!!
Jeśli ktoś jest w stanie mi pomóc to bardzo bym o to prosił.
a to może się przydać:
Syntax (OLE Automation)
retval = ModelDoc2.CreateCircularSketchStepAndRepeat ( arcRadius, arcAngle, patternNum, patternSpacing, patternRotate, deleteInstances )
Input:
(double) arcRadius
Radius to be used in the circular sketch patternInput:
(double) arcAngle
Angle relative to the sketch entities being patternedInput:
(long) patternNum
Total number of instances, including the seed geometryInput:
(double) patternSpacing
Spacing between pattern elements in radiansInput:
(BOOL) patternRotate
Rotate the patternInput:
(BSTR) deleteInstances
Instance numbers to delete passed as a string in the format: "(a) (b) (c) "Return:
(BOOL) retval
TRUE if the sketch pattern was created successfully, FALSE otherwiseSyntax (COM)
status = ModelDoc2->CreateCircularSketchStepAndRepeat ( arcRadius, arcAngle, patternNum, patternSpacing, patternRotate, deleteInstances, &retval )
Input:
(double) arcRadius
Radius to be used in the circular sketch patternInput:
(double) arcAngle
Angle relative to the sketch entities being patternedInput:
(long) patternNum
Total number of instances, including the seed geometryInput:
(double) patternSpacing
Spacing between pattern elements in radiansInput:
(VARIANT_BOOL) patternRotate
Rotate the patternInput:
(BSTR) deleteInstances
Instance numbers to delete passed as a string in the format: "(a) (b) (c) "Output:
(VARIANT_BOOL) retval
TRUE if the sketch pattern was created successfully, FALSE otherwiseReturn:
(HRESULT) status
S_OK if successful