8 Replies Latest reply on May 18, 2016 7:06 PM by Wayne Murphy

    SolidWorks Vb.Net "Listen Events"

    Darren Smith


      Can anybody help????

       

      I need a SolidWorks "Addin" Vb.Net programmer to help me with a modification to an existing "Addin" that I have. Please seethe attached file (.vb changed to .txt)

       

      I need the "addin" to do the following....

       

      1] Run a macro called "C:\MechTools\Default.swp" Module01 "OnNew". This will run every time the user presses the SolidWorks "New" button or Menu

       

      2] Run a macro called "C:\MechTools\Default.swp" Module02 "OnOpen". This will run every time the user presses the SolidWorks "Open" button or Menu

       

      3] Run a macro called "C:\MechTools\Default.swp" Module03 "OnSave". This will run every time the user presses the SolidWorks "Save" button or Menu

       

      4] Run a macro called "C:\MechTools\Default.swp" Module04 "OnClose". This will run every time the user closes a SolidWorks document (part, assembly or drawing)

       

      I am willing to pay (via PayPal) for somebody to help with this.

       

      Many thanks in advance!!!!

       

      Darren

        • Re: SolidWorks Vb.Net "Listen Events"
          Daniel Andersson

          I think this can be done with Macros only. Since Macros can call other macros.

          Using macros only will it easier for you to maintenance the code since it will not be compiled. Thinking of changing location etc of the macros.

           

          The only thing that I currently see is that the main macro has to be triggered when SolidWorks is started. This is possible be making a change of the startup icon. If you are allowed and ready to do this?

           

          I will play around tonight a bit with it....

           

          Best regards

          Daniel

          • Re: SolidWorks Vb.Net "Listen Events"
            Daniel Andersson

            Hello Darren,

             

            I have done a macro that you can load on start up of SolidWorks. The events I used is same as in the text file that you provided.

            You implement the eventListner macro as following:

             

            1) Unzip and place the macro file where you want it.

            2) Go to the SolidWorks installation directory and create and new shortcut to your desktop for the sldworks.exe file.

            3) Right click the new shortcut, choose properties.

            4) Go to tab "Shortcut"

            5) Add following to the target textbox: /m "your location of the macro"

            Capture.JPG

             

            6) Start SolidWorks with the new shortcut.

             

            Test run it... Please let me know if you have any issues with it.

            I would also like to point out that the provided events in the text file does not handle if user choose to do in SolidWorks "Windows->Close all".

             

            Please mark this answer as correct if it helped you.

             

            Best regards

            Daniel

            • Re: SolidWorks Vb.Net "Listen Events"
              Keith Rice

              Darren,

               

              You are correct that an add-in is the best approach for this if you plan on distributing it throughout your company. Moreover, while add-in might be able to run your macros using ISldWorks::RunMacro2, it would be a lot easier to just take the code that is in those macros and port it over to the add-in. Otherwise you're just creating more administrative work for yourself.

               

              Second, I would not recommend using event notifications. I would recommend simply having the add-in create a new menu when the add-in is loaded. For example, a company called Acme might have a menu called "Acme Tools" that has four buttons: New, Open, Save, Close. When you click these, it runs the appropriate code.

               

              If you want a quote from CADSharp then please fill out the New Program Specifications Form on this page, email it to keith@cadsharp.com, and I'll get you a quote within a day.

               

              Keith

              SolidWorks API Tutorials

                • Re: SolidWorks Vb.Net "Listen Events"
                  Daniel Andersson

                  Very good points Keith. Mixing macros and add-in using these events feels odd. Would be interesting to know why and what the macros do.

                    • Re: SolidWorks Vb.Net "Listen Events"
                      Keith Rice

                      Thanks, Daniel. I did not intend to detract from the work you did, by the way, because it is kind of you to offer your time and knowledge writing something he can use for free. If he is the only person who uses these macros, then that might get him  by. But when you start considering solutions that are distributed company-wide and must be able to adapt to a wide range of IT administrative changes, then a more robust solution is wise.

                       

                      Keith

                      SolidWorks API Services

                        • Re: SolidWorks Vb.Net "Listen Events"
                          Darren Smith

                          Hi Daniel & Keith,

                           

                          Many thanks for your replies!!!

                           

                          I am a Solidworks design engineer who has, in my spare time, created the program/macros. My intensions are to finally incorporate the macros into the "Addin" once I am happy that they work correctly. The program I am working on does the following. Please also see the picture!

                           

                          OnNew

                          This is a replacement of the "New Solidworks Document". It shows my own application that allows the user to specify the part number, description, material and part type prior to creating the document. In the configuration application that I have created you can turn off the above so that it goes back to the original "New Solidworks Document" dialog box.

                           

                          On Open

                          This is a replacement of "Open" that allows us to open a document easier by selecting from a drop down list that is associated with the assembly. In the configuration application that I have created you can turn off the above so that it goes back to the original open dialog .

                           

                          OnClose

                          Assemblies - Creates a B.O.M (in the form of a text file) that can be read by a separate application (see below) that can print/stamp drawings for the shop floor

                          Parts - Creates a AutoCAD 2d drawing of a part if that part is to be manufactured by laser cutting, flame cutting, water jet cutting etc

                          Drawings - Creates a Pdf file if the drawing for use by a separate application (see below) that can print/stamp drawings for the shop floor

                           

                          OnSave

                          Checks to see that a detail drawing is not being created for a laser cutting, flame cutting, water jet cutting profile (It does not need one as it is going to be a AutoCAD drawing.

                           

                          The only thing I can see with wrong with the macro that you attached is that I cannot run a macro on "New document" or "Open document" (File-New or File-Open)

                          I need it to run when I select "File-New or File-Open" or I press the new or open buttons.

                           

                          Once again, any thanks for your help!!!

                           

                          Many thanks

                           

                          Darren

                           

                          Screen.png

                            • Re: SolidWorks Vb.Net "Listen Events"
                              Daniel Andersson

                              After digging and trying to have the vba to cancel the "file-> new" (OnNew) dialog... I must say that I'm not able to manipulate that event you as want it to behave. With my narrow knowledge and shallow depth of experience I do not see that it even should be possible due to how the events is triggered.

                               

                              The OnOpen might be another story but I think you have to recap your software design.

                               

                              I would totally do as Keith said. Make separate menus (or macro buttons if you stay with VBA). It might be possible to hide the standard New and Open menus and buttons. personally I would keep them so users can work with out the add-in/macros.

                               

                              Keith Rice correct me now if I m wrong. Darren, please keep in mind that add menus is only possible for add-in and not for macros. Macros can hide menu items but not more than that. (At least with the regular API, dont know if tweaking the register could do other things. )

                               

                              So at the end I recommend these options.

                               

                              A) Get vb express from Microsoft. And make your add-in. You seem to have plenty of experience in vba and the step to vb.net is just fun. Vb express is free and ok for commercial use according to forums.

                               

                              B) Stay with the macros if you must quite soon implement the functions. But keep your custom New and Open to be triggered from Macro buttons in Solidworks. You could implement it by copy the settings with the copy setting wizard. Or find out the keys in the register and tgrn distribute it to other users. (Sounds maybe a bit cloumpsy but should be quite convenient wuth a batch or vb script).

                               

                              Last notes.  Do not forget to handle the Close All scenario. Do not mix add-in and macro. It is just messy and more difficult to keep track of updates. Choose one and go for it. (I do see an idea that you implement the macros first if there is a urgent need and if they are fully working.  After that you could switch to vb.net or c# in a controlled way)

                              • Re: SolidWorks Vb.Net "Listen Events"
                                Wayne Murphy

                                Hi Darren,

                                Any update on the progress of your Addin that you were creating for Solidworks? Your menus and methods appear to be pretty close to what I would like to implement at my own work and am wondering if you have any source code or example add in that I could take a look at.

                                 

                                Thanks, Wayne