5 Replies Latest reply on Apr 9, 2015 9:23 AM by Ivana Kolin

    Macro is not behaving correctly

    Paul Ryan

      I have a bunch of macros that I use to export information from SolidWorks.  The last time I used these macros was early March.  I am trying to export information again and my macros are not behaving the same way.  I am using Solidworks 2102 SP5.  The two issues:


      1) In all of my macros I have a Windows Folder Dialog Box open up asking me to select an output file.  The VBA language is straight forward:


      Filter = "Excel File (*.xls; *.xlsx)|*.xls;*.xlsx"

      FullFileName = swApp.GetOpenFileName("Excel File ", "", Filter, fileOptions, fileConfig, fileDispName)


      Recently, if I include the word "Excel" at the beginning when the window pops up I get a lot of other file filter options (the pull down in the bottom right hand corner) and most of them are random characters or Asian characters.  If I get rid of the word "Excel", the pull down only had one option and that is "File (*.xls; *.xlsx)".


      What would cause this? 


      2)  One of my macros would export CAD to parasolid files.  In the parasolid file only the solid geometry was being exported.  Now, if there is a composite curve, that is being exported along with the solid geometry.  This did not happen a month ago and the macro has not been updated since then. What would cause this?


      I have noticed both of these things happening together, but they might be unrelated.   I have recently upgraded my machine to IE 10 and there was a HotFix from Windows for Daylight Savings time.  Both these issues exist on another machine that was updated the same way.


      Any help would be greatly appreciated.



        • Re: Macro is not behaving correctly
          Deepak Gupta

          Could you attached that macro to check/test.


          Please check #18 here on how to attach a files (in case you don't know): Forum Posting

          • Re: Macro is not behaving correctly
            Keith Rice

            1. Try this for your filter string. I added a pipe on the end.


            Filter = "Excel File (*.xls; *.xlsx)|*.xls;*.xlsx|"


            2. Did the parasolid save options change? In the Save As dialog, after you select parasolid as Save As Type, click the Options button. If that doesn't change things, please upload a simple part and instructions to repeat the problem.



            SolidWorks API Tutorials

              • Re: Macro is not behaving correctly
                Paul Ryan

                1.  Adding the Pipe did the trick.  It is weird because it only started this behavior recently and only with certain words in the filter (like Excel).  Thanks.


                2.  Here is a snippet of the code.  A little background first, I loop through the assembly and build a list of parts that are not to be exported.  I then hide them, export the parasolid and then unhide those parts.



                   'Hide the others

                   ChangeVisState swHidColl, swComponentHidden

                   'Save as parasolid

                   Set SwModExt = SwModel.Extension

                   RetBool = SwModExt.SaveAs(OutputPath & "/" & partname & ".x_b", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, 0, 0)

                   'Reset hiding collection

                   ChangeVisState swHidColl, swComponentVisible


                Some variable explanation

                     swHidColl is a variant that is a listing of SolidWorks part or assembly names that should be hidden (not included in export)

                     OutputPath is a string that is a path to a folder

                     partname is a string that is the "human" name of the part (I chose to call it something like beam)


                Some of the parts have a Composite Curve.  Last month they were not exported with parasolid, now they are.  I should mention that this macro has not been touched (edited) in over a year, so there has been no update to the macro itself.  Also, SolidWorks has not been updated in quite some time.