×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks - VB x Borland Delphi

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources