Startup macro

Discussion in 'SolidWorks' started by Dames, Jan 26, 2005.

  1. Dames

    Dames Guest

    Is there a way of getting a macro to run when you make a new part from
    a template. I have seen the /m switch around but this only runs a macro
    from startup.
     
    Dames, Jan 26, 2005
    #1
  2. Not that I can think of automatically. What is it that you want to do? Can
    you build it into your template?

    WT
     
    Wayne Tiffany, Jan 26, 2005
    #2
  3. Dames

    P. Guest

    Could a macro feature as part of the template do this?
     
    P., Jan 26, 2005
    #3
  4. Dames

    That70sTick Guest

    This is really something you need an addin to do. You would need a
    program constantly running and ready to respond to notifications. This
    is what addins are for. Macros are not suitable for this. Possible,
    but I recommend against it strongly.

    I have a project/presentation about creating addins in VB from macros.
    It is available at <http://www.esoxrepublic.com/devtools/>.

    If you program a macro on your own, I can convert and compile for
    minimal cost. If you have access to VB, I can guide you through the
    process for nothing.
     
    That70sTick, Jan 26, 2005
    #4
  5. Dames

    CS Guest

    If you need to do it through a macro I am currently doing exactly that with
    the /m switch you mentioned.

    You need to set up your macro like this.

    you will have Module1.Main it's code needs to look like this.

    Sub main()
    Set ThisLibrary.swApp = Application.SldWorks
    end sub

    Remove all of the variables at the top of the module
    like Dim swApp as Object and such

    then under SolidWorks Objects you will find ThisLibrary module. You will
    need this code as a minimum in ThisLibrary

    Public WithEvents swApp As SldWorks.SldWorks


    Private Function swApp_FileNewNotify2(ByVal newDoc As Object, _
    ByVal
    DocType As Long, _
    ByVal
    templateName As String _
    ) As Long

    Dim strDocType

    select case DocType
    Case swDocASSEMBLY
    strDoctype = "Assembly"
    Case swDocPART
    strDoctype = "Part"
    Case swDocDrawing
    strDoctype = "Drawing"
    End Function

    msgbox "You just created a new Document here's some info about it." & vbcrlf
    & _
    "Document type: " & strDoctype & vbcrlf &
    "Template used: " & templateName

    End Function


    Things you want to look out for. The code will stop running sometimes if
    someone edits a macro or hits End when a macro goes to the debugger because
    of an error or interupts a macro by hitting the stop button from the VB
    editor. These are the reasons that That70sTick says it is better to use an
    external application to monitor.

    Regards,

    Corey
     
    CS, Jan 26, 2005
    #5
  6. Dames

    Dave Guest

    Perhaps edit the macro you want to run to create a new part using the
    template? Kind of a different flow from what you are asking for, but
    should produce the same result. Instead of creating a new part using a
    template that would run a macro, you run a macro that would create a
    new part from a template and then continue with the functions you
    already have programmed. You would need a different macro for each
    template you would use.
     
    Dave, Jan 26, 2005
    #6
  7. I think at this point, you are definitely moving into the add-in realm.
    That way, you could add some new menu commands which would allow you to
    override the standard new part menu. You MIGHT be able to do this with a
    macro feature, but there may be some problems that I haven't thought of
    initially.

    Evan
     
    Evan T. Basalik, Jan 27, 2005
    #7
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.