3 Replies Latest reply on Jun 19, 2014 12:52 AM by Luis Castillo

    Large numbers in arguments with record macro

    Thomas Cornelissen

      Hello,

       

      I'm just starting out with SolidWorks API.

      I've just started with the C# tutorial in SolidWorks.

      Where you have to create a CutExtrude feature in a candle.

       

      Everything is just fine until I start to run the code.

      SolidWorks gives red colored sketshes (Item is Unsolvable)

       

      When I look at my code there are very large numbers as parameters

       

      public void Main()

      {

                  ModelDoc2 swDoc = null;

                  PartDoc swPart = null;

                  DrawingDoc swDrawing = null;

                  AssemblyDoc swAssembly = null;

                  bool boolstatus = false;

                  int longstatus = 0;

                  int longwarnings = 0;

                  swDoc = ((ModelDoc2)(swApp.ActiveDoc));

                  boolstatus = swDoc.Extension.SelectByID2("", "FACE", 27899090838445772, 21999999999985676, -14118678285342412, false, 0, null, 0);

                  swDoc.ClearSelection2(true);

                  SketchSegment skSegment = null;

                  skSegment = ((SketchSegment)(swDoc.SketchManager.CreateCircle(0, 0, 0, 2848, 13902, 0)));

                  swDoc.ClearSelection2(true);

                  boolstatus = swDoc.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);

                  Feature myFeature = null;

                  myFeature = ((Feature)(swDoc.FeatureManager.FeatureCut3(true, false, false, 0, 0, 2.5E+16, 2.5E+16, true, false, false, false, 2.6179938779915E+16, 2.6179938779915E+16, false, false, false, false, false, true, true, true, true, false, 0, 0, false)));

                  swDoc.ISelectionManager.EnableContourSelection = false;

      }

       

      I get the same problem with the macro tutorial for VB.NET

      But for VBA I don't get this problem.

       

      I'm doing everything according the tutorial

       

      Please help

       

      Thanks in advance

        • Re: Large numbers in arguments with record macro
          Artem Taturevych

          As I understand the macro itself's working but the result this macro produces is incorrect? Is it true? If so you should understand what is wrong with your model and find corresponding line in macro to fix it.

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

          • Re: Large numbers in arguments with record macro
            Keith Rice

            Thomas,

             

            The default units in the SolidWorks API are meters, so consider these lines:

             

            boolstatus = swDoc.Extension.SelectByID2("", "FACE", 27899090838445772, 21999999999985676, -14118678285342412, false, 0, null, 0);

             

            Here you are trying to a select a face at coordinates (27899090838445772, 21999999999985676, -14118678285342412) m, which is well beyond the size of the part modeling envelope (which is a 1000m cube as of SolidWorks 2010, I believe).

             

            Likewise, here you are creating a circle with the origin as the centerpoint and (2848, 13902, 0)m as the second pt.

             

            skSegment = ((SketchSegment)(swDoc.SketchManager.CreateCircle(0, 0, 0, 2848, 13902, 0)));

             

            Finally, your cut extrude is being made at a depth of 2.5E+16. Check out the API Help page for IFeatureManager::FeatureCut3 to see more about the arguments.

             

            myFeature = ((Feature)(swDoc.FeatureManager.FeatureCut3(true, false, false, 0, 0, 2.5E+16, 2.5E+16, true, false, false, false, 2.6179938779915E+16, 2.6179938779915E+16, false, false, false, false, false, true, true, true, true, false, 0, 0, false)));

             

            Since it sounds like you are new to API programming, I would highly recommend you read this document: 7 Mistakes New SolidWorks API Programmers Make

             

            Hope this helps.

             

            Keith

            Video Tutorials for the SolidWorks API

            • Re: Large numbers in arguments with record macro
              Luis Castillo

              Hi all,

               

              I know this post is old but I had exactly the same problem with large parameters in a macro. The cause in my case was the definition of the decimal symbol and the digit grouping symbol. If SW is in English US(for example) and the OS decimal definition is not(say Latinamerican), this will cause SW to handle the point symbol as grouping symbol and viceversa. Then a decimal digit as 45.89758978 will be read by VSTA(i guess) as 4589758978.(kind of...HUGE!!). I just simply changed my region configuration(say in Control Panel) to the same of SW.

              I just started learning SW API so my knowledge is limited too.

               

              Hope this helps.

               

              Lucho