4 Replies Latest reply on Sep 27, 2016 9:03 AM by Elmar Klammer

    Planar transformer winding

    Alexandre Christe



      I'm trying to build a 3D model of for a planar transformer winding that looks like the following image.

      Capture d’écran 2016-09-23 à 17.03.05.png



      As a first step I draw the elementary turn along which the wire will be swiped.


      Capture d’écran 2016-09-23 à 11.31.44.png

      From there the function "offset entities" is super useful, however strangely it cannot be repeated N times so that to directly get the desired number of turns.


      Then the wire is swiped along that line, leading to the image below

      Capture d’écran 2016-09-23 à 11.32.15.png

      Once again it leads to frustration as no function to duplicate that geometry to construct a planar winding is available.


      Am I really missing something?


      My objective from the result would be to parametrize the elementary turn and then be able to set the number of turns. Any good recommendations?

        • Re: Planar transformer winding
          John Alexander

          I'm not aware of a builtin tool to repeatedly offset entities. My naive approach would be to write macro that offset entities "N" times on the currently selected entities (growing outwards).


          The first problem would be figuring out which entities need the offset performed for N>1 as you would need to select the newly created sketch entities to perform the second, third, ...nth offset.


          One of the options will turn the "base" entities to construction geometry while the new entities are not. You could use this criteria to filter your selection for each successive offset that is performed by the macro.


          Alternatively, you can re-select the original entities and perform the offset with d_N = N*d_0 where d_0 was the original displacement.

            • Re: Planar transformer winding
              Alexandre Christe

              This is exactly the function I was using for obtaining the first image in my original question.


              I never worked with the scripting/macro in SolidWorks. Is is best to record a macro and then edit it?

                • Re: Planar transformer winding
                  John Alexander

                  It doesn't hurt to try the macro recorder. It isn't going to give you a working macro but sometimes it will reveal the function calls you need to use in the API.


                  If I were doing your task, I would break it into 3 sub-tasks.


                  1. Determine which API function call performs the "offset sketch entities". Find it in the documentation and read about what arguments you need to pass to the function and what state the application needs to be in for it to do what you want. For instance, regarding states, sometimes a function will require that certain entities or components be selected when it is called. The entities don't get passed to the function - you just have to make sure that they are selected by some other means (I'm predicting that this is the pattern that "offset sketch entities" will use because I've seen it in other places and the user-land version depicted in my screenshots above requires pre-selection).


                  2012 SOLIDWORKS API Help - SketchOffsetEntities2 Method (IModelDoc2)


                  2. Determine how you want to prompt for user input. There are builtin prompts (forms/windows) for getting this during runtime of your macro. You probably want the user to specify the number of turns. Additionally, if the function requires pre-selection of sketch entities, you can instruct the user to select entities before running your macro.


                  Excel VBA InputBox Function - EASY Excel Macros


                  3. Write a loop that performs the offset a specified number of times. Looking at the behavior of the user-land "offset entities", it will clear your selections when sketchoffsetentities2 is called. You will have to re-select the original entities on each iteration of the loop. If you store an array of references to the sketch entities at the beginning of your amcro, you can loop over them and call Select() on each one.


                  2012 SOLIDWORKS API Help - Select4 Method (ISketchSegment)