×
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

Document Routine Needed

Document Routine Needed

Document Routine Needed

(OP)
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

RE: Document Routine Needed

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.

RE: Document Routine Needed

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.

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.

RE: Document Routine Needed

(OP)
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.

RE: Document Routine Needed

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:

Dim swApp As Object
Dim Part As Object

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

Set swApp = GetObject(, "SldWorks.Application")
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.

RE: Document Routine Needed

(OP)
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.

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