11 Replies Latest reply on Apr 16, 2017 10:58 AM by Simon Turner

    Save As * Marcro

    Mark Matthews
      I am a total idiot when it comes to making a Marcro. I have not made a sucessful one yet. A simple one I thought I could make was create a button to save a file as an STL as I have a bunch of them to make from the same file (Saving out bodies into their own seperate STL files), and I have to do this for multiple parts.

      I ran the Marcro recorder and now I have a button set up that works just great at makeing and STL of the current part, but it has the same name every time, even when using it different parts than the marcro was recorded from. What I woul really like to do is to have the Marcro pause, or stop after it has opened the Save dialouge and selected STL as the file format. I have no idea how to edit the macro to do this. I've posted the macro if anyone wants to look.
        • Save As * Marcro
          Jorn Bjarning

           

          Originally posted by: Mark Matthews I am a totalidiot when it comes to making a macro. I have not made a successfulone yet. A simple one I thought I could make was create a button tosave a file as an STL as I have a bunch of them to make from thesame file [...] What I would really like to do is to have the macropause, or stop after it has opened the Save dialogue and selectedSTL as the file format..



          Mark,
          Welcome to the macro world - a world of opportunities.

          As far as I know it is not possible to stop the macro with theSaveAs dialogue open as you requests. I have made another verysimple solution just to show you how it can be done. It has asimple user form where you manually enter the name of the folderand the filename and then press the save button.

          Many things could be done to make this macro smoother - for examplea button to browse for a folder and some basic errorhandling/validation should also be added to make it more secure(did the user specify a valid folder name for example).

          There are also plenty of possibilities for improvements, forexample: If you always want the STL file to be saved in the samedirectory as the SW file it is possible to add code which grabs thefolder name for the active SW part so you don't have to enter itfor every part. In the current solution I have just made a constantnamed DefaultFolder (in the Main procedure). Change it to yourneeds.

          Notice that some of the code is attached to the form instead ofbeing a part of the Main procedure.

          I hope you can use it and give you some ideas for furtherimprovements.
            • Save As * Marcro
              Mark Matthews
              Jorn,

              Thanks! That works like a charm. Where do I go to learn the basics of this stuff? I'm talking basic basics. Things like how did you know to create a form and what code to write to get it. Is the macro editing interface common to Visual basic or is this editor SW specific?

              Like I said, I'm really good at creating geometry and renderings, but when it comes to this I feel like I did when I first used a "T" square and triangle.
                • Save As * Marcro
                  Jorn Bjarning

                   

                  Originally posted by: Mark Matthews Jorn, Thanks!That works like a charm. Where do I go to learn the basics of thisstuff? I'm talking basic basics. Things like how did you know tocreate a form and what code to write to get it. Is the macroediting interface common to Visual basic or is this editor SWspecific?



                  Getting started, hmm... I believe that most of the folks in thisforum (including myself) has a background as a mechanical engineeror similar. At a certain point we have been facing a trivial taskto be done many times manually in SW - triggering a wish toautomate the task using a macro.

                  People have different ways of learning new skills. Some prefertraining, others book, or... I don't know which type you are?Personally I bought a book introducing programming with VB just toget the basics right (important!). I have made a bunch of the sillyexamples in the book and then I have been searching the internetfor help. The best way to learn is definitely to have a relevantproject (for example creating STL-files). It is much more fun andinspiring than making school examples. I have had plans joiningsome real training but I never found the time. You can for examplejoin internet based training in virtual classrooms.

                  I have attended a SW API training at my VAR a couple of years ago,which I felt was a good way to get started with programming againstSW. Can be recommended.

                  The macro editing interface is Microsoft VBA Editor - it is not aSW product. It is a lightweight version of the full VB package. Allthe basic and most used VB functionality is available in VBA.

                  So my recipe is: Buy (or borrow) a book, spend hours trying andtrying and ask for help in this forum for SW API questions and inVB forums for 'clean' VB questions.
                • Re: Save As * Marcro
                  Jakob Olrik

                  Hi Jorn and Mark,

                   

                  I have exactly the same problem as Mark, and I have tried the same but it did not work ourt. Could you please share the macro again, I would much apriciate it.