Visual Basic Save - Type Mismatch

Discussion in 'SolidWorks' started by ahoneyfield, Mar 28, 2007.

  1. ahoneyfield

    ahoneyfield Guest

    Hi,

    I have a SolidWorks macro that saves filetypes from a part drawing,
    ie. with the drawing open, you select the filetypes to save, and the
    macro opens the model and saves the files.

    I am trying to make a DLL using Visual Basic, and have copied across
    the macro to Visual Basic 2005 Express.

    When I run the macro, it creates a 'Type Mismatch' error when it runs
    the segment of code that saves the filetype.

    The segment of code looks like:

    If WantParasolid.Checked = True Then
    'Save off Parasolid File
    bRet = swDrawModel.SaveAs4("C:\fred.x_t", _
    swSaveAsCurrentVersion, _
    swSaveAsOptions_Silent, _
    nErrors, _
    nWarnings)
    End If

    Earlier the declarations were:

    Dim iSwApp As SldWorks.SldWorks
    Dim iSwModel As SldWorks.ModelDoc2
    Dim swDrawModel As Object

    Dim bRet As Boolean
    Dim swSaveAsCurrentVersion As Long
    Dim swSaveAsOptions_Silent As Long
    Dim nErrors As Long
    Dim nWarnings As Long

    swDrawModel = iSwApp.OpenDoc6(sFullFilePath, DocType, 0, "",
    nErrors, nWarnings)
    swDrawModel = iSwApp.ActivateDoc(ModelName)

    Can anyone help?

    Thanks
     
    ahoneyfield, Mar 28, 2007
    #1
  2. ahoneyfield

    ahoneyfield Guest

    Got the answer from another source. Trick is to declare swDrawModel
    at the start of the file as:

    Dim swDrawModel As SldWorks.ModelDoc2

    Strangely, this was not necessary as a macro - it was only needed once
    we switched to VB2005 Express to create a DLL.
     
    ahoneyfield, Mar 29, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.