SolidWorks - VB x Borland Delphi
SolidWorks - VB x Borland Delphi
(OP)
Hi All,
I am trying to use Borland Delphi to write a code in our system.
In VB i have the follow code:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swBom As SldWorks.BomTableAnnotation
Dim i As Long
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
MsgBox "Running...."
Set swView = swDraw.GetFirstView
MsgBox "View: " & swView.Name
While Not swView Is Nothing
Set swBom = swView.GetBomTable
If Not swBom Is Nothing Then
MsgBox swBom.GetColumnCount
End If
Set swView = swView.GetNextView
Wend
---
In Borland Delphi i create this code:
swApp: TSldWorks;
swModel: TModelDoc2;
swSelMgr: TSelectionMgr;
swAnnotation: TAnnotation;
swTable: TTableAnnotation;
swBomTable: TBomTableAnnotation;
swDrawing: TDrawingDoc;
swView: TView;
varConfiguracoes, varFeature: OleVariant;
nrModel, nrConfiguracoes: integer;
flAtivar, flTopLevelOnly: WordBool;
stNome: WideString;
begin
swApp := TSldWorks.Create(Self); // Dim swApp As SldWorks.SldWorks
swModel := TModelDoc2.Create(Self); // Dim swModel As SldWorks.ModelDoc2
swDrawing := TDrawingDoc.Create(Self); // Dim swDraw As SldWorks.DrawingDoc
swView := TView.Create(Self); // Dim swView As SldWorks.View
swTable := TTableAnnotation.Create(Self); // Dim swTable As SldWorks.TableAnnotation
bRet := False; // Dim bRet As Boolean
try
swApp.Connect; // Set swApp = Application.SldWorks
except
begin
MessageDlg('SolidWorks 2007 don't installed !!!', mtWarning,[mbOk],0);
raise;
end;
end;
swModel.ConnectTo(swApp.IActiveDoc2); // Set swModel = swApp.ActiveDoc
swDrawing.ConnectTo(swApp.INewDrawing(-1)); // I want get the current view here, and the system create a new view.
MessageDlg('File : ' + swDrawing.GetNamePath,mtWarning,[mbOk],0);
swApp.Disconnect;
----------------
The code run efficiently, but i want to take the current view, and not insert a new view.
The purpose of this code, at last, is to get the BOMTable, to transfer the materials to ERP Application. This code is the just the initial of function.
Thanks,
Adriano
I am trying to use Borland Delphi to write a code in our system.
In VB i have the follow code:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swBom As SldWorks.BomTableAnnotation
Dim i As Long
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
MsgBox "Running...."
Set swView = swDraw.GetFirstView
MsgBox "View: " & swView.Name
While Not swView Is Nothing
Set swBom = swView.GetBomTable
If Not swBom Is Nothing Then
MsgBox swBom.GetColumnCount
End If
Set swView = swView.GetNextView
Wend
---
In Borland Delphi i create this code:
swApp: TSldWorks;
swModel: TModelDoc2;
swSelMgr: TSelectionMgr;
swAnnotation: TAnnotation;
swTable: TTableAnnotation;
swBomTable: TBomTableAnnotation;
swDrawing: TDrawingDoc;
swView: TView;
varConfiguracoes, varFeature: OleVariant;
nrModel, nrConfiguracoes: integer;
flAtivar, flTopLevelOnly: WordBool;
stNome: WideString;
begin
swApp := TSldWorks.Create(Self); // Dim swApp As SldWorks.SldWorks
swModel := TModelDoc2.Create(Self); // Dim swModel As SldWorks.ModelDoc2
swDrawing := TDrawingDoc.Create(Self); // Dim swDraw As SldWorks.DrawingDoc
swView := TView.Create(Self); // Dim swView As SldWorks.View
swTable := TTableAnnotation.Create(Self); // Dim swTable As SldWorks.TableAnnotation
bRet := False; // Dim bRet As Boolean
try
swApp.Connect; // Set swApp = Application.SldWorks
except
begin
MessageDlg('SolidWorks 2007 don't installed !!!', mtWarning,[mbOk],0);
raise;
end;
end;
swModel.ConnectTo(swApp.IActiveDoc2); // Set swModel = swApp.ActiveDoc
swDrawing.ConnectTo(swApp.INewDrawing(-1)); // I want get the current view here, and the system create a new view.
MessageDlg('File : ' + swDrawing.GetNamePath,mtWarning,[mbOk],0);
swApp.Disconnect;
----------------
The code run efficiently, but i want to take the current view, and not insert a new view.
The purpose of this code, at last, is to get the BOMTable, to transfer the materials to ERP Application. This code is the just the initial of function.
Thanks,
Adriano





