5 Replies Latest reply on Sep 4, 2015 5:55 AM by Alfonso Cartagena

    New to API need some help

    Alfonso Cartagena

      Hello Everyone,

       

      I am new to SolidWorks API and I am having a few issues. What I am trying to create a macro to accomplish this .

       

                I have a "main assembly" with a part in it that we will call "plate2". Putting tapped holes in plate 2 is the goal. I also have a "sub assembly" which is inserted into the "main      assembly". Within this "sub assembly" I have a part we will call "male". Within the "male" part I have a sketch called "Sketch8". This sketch contains 2 points that are needed to      locate the tapped holes being cut into "plate2".

       

      I currently have an action preformed before this part of the code which creates cavities for the "male" part to be located in "plate2". This part of the code does work. I have attached a portion of the code and where I'm the having issue.  I know I need to grab the SldWorks.PartDoc interface for the "male" part, but that is where I'm confused.Code.PNG

       

      Thank you for the help,

      Alfonso

        • Re: New to API need some help
          Deepak Gupta

          You need to specify the full path of that file with extension and in quotes. For e.g.

           

          Set Part2 = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\swutilities\bracket_a.sldprt"

           

          OR

           

          Part.ClearSelection2 True

          Part.Extension.SelectByID2 "File Name @ Assembly Name", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

          Set swComponent = Part.SelectionManager.GetSelectedObject6(1, -1)

          Set Part2 = swComponent.GetModelDoc

            • Re: New to API need some help
              Alfonso Cartagena

              Deepak,

               

              Thank you for the help! I've almost got it. I'm using the second option of your answer as the file locations might differentiate from system to system here. I am also not understanding the last two lines of that code though and what they do. The reason being the error I am currently getting.Code.PNG

              • Re: New to API need some help
                Alfonso Cartagena

                Deepak Gupta,

                 

                I got the macro to work! The initial code I used for reference had this command line in it:

                 

                swWzdHole.InitializeHole swWzdCounterBore, swStandardISO, swStandardISOHexBolt, "M48", swEndCondBlind

                 

                 

                This is not the correct hole that I will need. I modified the code to reflect a 10-32 tapped hole. Below is the modified code.

                 

                swWzdHole.InitializeHole swWzdTap, swStandardPCS, swStandardPCSTappedHole, "#10-32", swEndThreadTypeBLIND

                 

                 

                This code crashes SolidWorks. Is there anything you see here that is causing this issue?

                 

                Thank you!