×
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

API Question - Getting the list of child files for a drawing
2

API Question - Getting the list of child files for a drawing

API Question - Getting the list of child files for a drawing

(OP)
I am writing a VB routine to determine all of the children files for a given SolidWorks file and have been quite successful for assemblies but the routines I use utilize the swFile.GetActiveConfiguration() and then the Configuration.GetRootComponent() routines to insure that I have the root component.  Drawings are not particularly fond of that API call.

I only need the first level children as the system handles the recursion by keeping a table of all parent - child pairs and applying the relationships downward.

I guess my question is - how do I (in VB using the SW API) determine which files a drawing (.SLDDRW) uses?

Frank

RE: API Question - Getting the list of child files for a drawing

This is a fragment from a program I wrote not long ago with help from dsi (the top expert).
It checks the current sw document and, if it is a drawing, jumps to the first view which is the drawing template, then goes to the next view and gets the file name of the model used to create that view. My program stops there but probably you can loop thru the views with

Set View = View.GetNextView     

until you get nothing or error (I dont know what the above statement returns when there is no next view.)

Dim docType As Integer
Dim swApp As Object
Dim Part As Object

Dim View As Object
Dim sModelName As String

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc

If Part Is Nothing Then
    msg = "A SolidWorks document needs to be loaded!"
    Style = vbExclamation           ' Error style dialog
    Titlemsg = "Model Properties"      ' Define title
    Call MsgBox(msg, Style, Titlemsg) 'Display error message
    End           ' If no model currently loaded, then exit
Else
     docType = Part.GetType
End If

If (docType = swDocDRAWING) Then
        Set View = Part.GetFirstView 'dwg template is the first view
        Set View = View.GetNextView     'first dwg view
'get referenced model
        sModelName = View.GetReferencedModelName()
End If


Hope this helps,

Andrew

RE: API Question - Getting the list of child files for a drawing

I am not getting any results with this.  When the code reaches 'Set View = Part.GetFirstView', I get an error.  'Object doesn's support this property or method'.  Am I doing something wrong?

RE: API Question - Getting the list of child files for a drawing

JP:

Are you doing this in VB or SolidWorks VBA?
Are you running with Option Explicit?
Have you defined swDocDRAWING = 3?

The GetFirstView method is only available for the DrawingDoc object.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: API Question - Getting the list of child files for a drawing

I am running Option Explicit.  As I understand it, the error that I am getting is because VBA doesn't know that .GetFirstView is a method of the Part Object.  I am hoping that all I have to do is register a .dll or something.  This could also come from a missing reference.  I just don't know which one.  I am trying to get running with VBA for Solidworks, but am finding that the lack of documentation and examples is really setting me back.

RE: API Question - Getting the list of child files for a drawing

This should work in VBA as well. Could you post your code?

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: API Question - Getting the list of child files for a drawing

Please check my new post "Document Routine Needed"

This will more accurately depict what I am trying to do.

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