Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document Routine Needed 1

Status
Not open for further replies.

JpPhysics

Mechanical
Mar 25, 2002
35
I am trying to automate the process of converting thousands of MDT files to Solidworks. We have already broken down our product lines into part types and have begun the process of creating part files and configurations. What I need now is an automated way to output drawing files. I have a template drawing set up with the dimension scheme that I like. I just need to be able to cycle through the configurations and do a save copy as with the configuration name as the name of the file.

The only part of this routine that I am having problems with is the cycling through the configurations. I cannot seem to grab the available configurations from the view. Am I doing something wrong? Do I need to load the part/assembly file to grab the configurations?

Any Ideas?

My Sample Code:

Option Explicit

Dim swApp As Object
Dim Drawing As SldWorks.DrawingDoc

Sub main()
Dim View As SldWorks.View
Dim Model As String
Dim Configuration As String

Set swApp = CreateObject("SldWorks.Application")
Set Drawing = swApp.ActiveDoc
Set View = Drawing.IGetFirstView()
Set View = View.GetNextView
Model = View.GetReferencedModelName
Configuration = View.ReferencedConfiguration

End Sub
 
Replies continue below

Recommended for you

First, you should define Drawing As Object in your VBA code. The method you have is for early binding, which is not needed.

I will look into the rest of it and get back to you. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Here you go. This will loop through all of the drawing views on the active drawing. NOTE: It does not test to make sure the active document is a drawing. I think the main problem with your code was your use of IGetFirstView instead of GetFirstView.
Code:
Option Explicit

Dim swApp As Object
Dim swDwg As Object
Dim swView As Object

Sub main()
    Dim sViewName As String
    Dim sModelName As String
    Dim sConfigName As String
    Dim sMsg As String
    
    Set swApp = CreateObject("SldWorks.Application")
    Set swDwg = swApp.ActiveDoc
    Set swView = swDwg.GetFirstView()   'Drawing Template
    
    sMsg = "VIEW NAME : MODEL NAME : COFIGURATION NAME" & vbCrLf
    On Error Resume Next
    Set swView = swView.GetNextView
    Do While Not swView Is Nothing
        sViewName = swView.Name
        sModelName = swView.GetReferencedModelName
        sConfigName = swView.ReferencedConfiguration
        'Build String
        sMsg = sMsg & sViewName & " : " & _
                      sModelName & " : " & _
                      sConfigName & vbCrLf
        Set swView = swView.GetNextView
        If Err.Number <> 0 Then
            Err.Clear
            Exit Do
        End If
    Loop
    MsgBox sMsg

    Set swView = Nothing
    Set swDwg = Nothing
    Set swApp = Nothing
End Sub
Hope this helps... DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
That's great! Thanks for the help.

Will I need to open the part or assembly file sModelName in order to get a list of available configurations? I think that is the only to do it.
 
I am not sure. You may be able to reference the part directly from the drawing document. You just need a handle to the part.

For a list of available configurations:
Code:
Dim swApp As Object
Dim Part As Object

Dim ConfigNames As Variant
Dim iConfigs As Long    
Dim i As Long

Set swApp = GetObject(, &quot;SldWorks.Application&quot;)
Set Part = swApp.ActiveDoc

'Get a list of Configurations
iConfigs = Part.GetConfigurationCount
ConfigNames = Part.GetConfigurationNames

For i = 0 To (iConfigs - 1)
    MsgBox ConfigNames(i)
Next
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Thanks again for your help, but this does not appear to work in the .SLDDRW file. I will try opening the part file to see if that works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor