6 Replies Latest reply on Oct 12, 2012 11:24 AM by R. H

    Api basics (+ Why isn't the API section accessible for me?)

    R. H

      I am getting into solidworks API a little bit with the goal to be able to draw parts only by entering desired parameters. A gear in this case. i used Macro record to record a macro to make a simple gear. I am going to use that macro to start off with. i need some tips to be able to insert/adjust the gear thickness, the amount of teeth and diameter etc in the macro, but i have a hard time finding examples and tutorials about that.

       

      2nd. i do not seem to have the privileges to access the API section, why?

       

      (The full story, I worked out some formulas for designing geneva gears in mathcad, i only have to enter the desired amout of pins and slots and the dimensions and stuff rolls out. I want to use those outputs to autmatically draw my solidworks parts with a macro)

        • Re: Api basics (+ Why isn't the API section accessible for me?)
          Paul Marsman

          R.H,

            Well, a few things:

          1. Don't use the Macro Recorder - there are many examples of why around here and the web if you need to know why
          2. The question you ask is most definately not "API Basics" as your subject says because making a model from API alone is not basic, let alone that you are trying to generate a gear.
          3. Post what you do have (even though it was done with the recorder) so anyone not sitting next to you can see what you are doing.

           

          as for access to the API section, that's a SW Forum Admin thing... hopefully someone in that roll sees your post.

           

          Paul

            • Re: Api basics (+ Why isn't the API section accessible for me?)
              R. H

              I have gotten quite far experimenting, i will share my macro soon,

               

              I made a macro with record (to start off with)to draw a disk with an extruded cut(tooth), and a circular pattern to pattern the cut for the teeth. I have used macro buttons/instructions in a form to insert the desired dimensions. However i can't find the part of code that prescribes the number of instances for the circular pattern... does anyone know how to macro a circular pattern??

               

              Like Deepak said; It seems i have to contact my reseller, which is the university, so i am expecting it to take a loooong time till i get access to the API section. 

                • Re: Api basics (+ Why isn't the API section accessible for me?)
                  Paul Marsman

                  Create Circular Pattern Example (VBA)

                  This example shows how to create a circular-pattern feature using a preselected axis, a preselected feature, and equal spacing between instances.

                  '--------------------------------------------------------------
                  ' Preconditions: Make sure that the specified file exists.
                  '
                  ' Postconditions: A circular-pattern feature is created.
                  '
                  ' NOTE: Because the model is used elsewhere, do not
                  ' save any changes when closing it.
                  '--------------------------------------------------------------
                  Option Explicit

                   

                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ModelDoc2
                  Dim swModelDocExt As SldWorks.ModelDocExtension
                  Dim swFeatureMgr As SldWorks.FeatureManager
                  Dim swFeature As SldWorks.Feature
                  Dim status As Boolean
                  Dim warnings As Long
                  Dim errors As Long

                   

                  Sub main()

                   

                  Set swApp = Application.SldWorks

                   

                  Set swModel = swApp.OpenDoc6("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\FeatureCircularPattern.SLDPRT", swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
                  Set swModelDocExt = swModel.Extension
                  Set swFeatureMgr = swModel.FeatureManager

                   

                  ' Select boss feature to use for circular pattern; selection mark is 4
                  status = swModelDocExt.SelectByID2("Boss-Extrude2", "BODYFEATURE", 0, 0, 0, False, 4, Nothing, 0)
                  ' Select axis around which to create circular pattern; selection mark is 1
                  status = swModelDocExt.SelectByID2("Axis1", "AXIS", 0, 0, 0, True, 1, Nothing, 0)

                   

                  ' Create circular-pattern feature
                  Set swFeature = swFeatureMgr.FeatureCircularPattern3(6, 6.2831853071, False, "NULL", False, True)

                   

                  End Sub

              • Re: Api basics (+ Why isn't the API section accessible for me?)
                Deepak Gupta

                R. H wrote:

                 

                i do not seem to have the privileges to access the API section, why?

                Make sure you're on subscription to access that section (API example). If that is not the case please contact your VAR to get that fixed.

                • Re: Api basics (+ Why isn't the API section accessible for me?)
                  Glenn Schroeder

                  R. H wrote:

                   

                   

                  2nd. i do not seem to have the privileges to access the API section, why?

                   

                   

                  Are you using the SW Student Edition?  Please see this discussion.