4 Replies Latest reply on Apr 25, 2014 7:55 PM by Jason Hsu

    How to create sketches in the background?

    Jason Hsu

      Hello,

       

      I need to create a series of sketches but I found that Solidworks would create those sketches interactively. Can I create them in the background? I mean after running the macro, I would see a series of sketches in the feature tree, no any drawing animation in the creating process. My codes look like....

       

      sketchMgr.AddToDB = true;

      sketchMgr.InsertSketch(true);

      sketchMgr.CreateCenterRectangle(S.ArrayData[0], S.ArrayData[1], 0,S1.ArrayData[0], S1.ArrayData[1], 0);

      sketchMgr.InsertSketch(true);

      sketchMgr.AddToDB = false;

        • Re: How to create sketches in the background?
          Keith Rice

          Jason,

           

          Using IModelView::EnableGraphicsUpdate set to False should give the results you need. This method will also cause your macro to run faster, since the screen requires less updating. Remember to set this back to true at the end.

           

          Also be sure to turn off the "Input dimension value" system setting if you plan on adding dimensions. Like this:

           

          swApp.SetUserPreferenceToggle swInputDimValOnCreate, False

           

          Turn it back on later by changing the last argument to True.

           

          Keith

          SolidWorks API Tutorials

            • Re: How to create sketches in the background?
              Jason Hsu

              Keith,

               

              I had set EnablegraphicUpdate to false and found that SolidWorks didn't enter sketching mode but the property page still flash there. Any way to also disable showing property page?

              Thank a lot

               

              Jason

                • Re: How to create sketches in the background?
                  Keith Rice

                  Jason,

                   

                  I have never experienced any flashing when using this method, so perhaps it is related to your graphics card or driver. When I use this property, the screen is not updated or changed in any way.

                   

                  Beyond this, the only other option I can think of that might appeal to you is to make the document invisible (IModelDoc2::Visible).

                   

                  Keith

                  SolidWorks API Tutorials

                    • Re: How to create sketches in the background?
                      Jason Hsu

                      Keith,

                       

                      I set both the parameter to false,

                       

                      modelView.EnableGraphicsUpdate = false;

                      iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);

                       

                      When running the macro, no drawing activities in the drawing area except still showing up dimension value box

                      However, the whole Solidworks was still switching between FeatureManager and PropertyManager(Show up the rectangle drawing selection information). My codes looke like this,

                       

                                  ModelView modelView = modelDoc.ActiveView ;

                                  modelView.EnableGraphicsUpdate = false;

                                  iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);

                                  //iSwApp.DocumentVisible(false, (int)swDocumentTypes_e.swDocPART);

                                  sketchMgr.AddToDB = true;

                       

                                  for(int i=0; i<M; i++)

                                  {

                                      for(int j=0; j<N; j++)

                                      {

                                          MathPoint S = S0.AddVector(V1.Scale((double)i / M)).AddVector(V2.Scale((double)j / N));

                                          MathPoint S1 = S.AddVector(deltaV1).AddVector(deltaV2);

                                               

                                          reference.Select(false);          

                                          sketchMgr.InsertSketch(false);

                                          Sketch thisSketch = modelDoc.GetActiveSketch2();

                                          Feature swFeat = (Feature)thisSketch;

                                          swFeat.Name = "test" + i + j;

                                          MathTransform xform2 = thisSketch.ModelToSketchTransform;

                                          S = S.MultiplyTransform(xform2);

                                          S1 = S1.MultiplyTransform(xform2);

                                          sketchMgr.CreateCenterRectangle(S.ArrayData[0], S.ArrayData[1], 0,

                                                                          S1.ArrayData[0], S1.ArrayData[1], 0);

                       

                                          //sketchMgr.CreateCenterRectangle(0, 0, 0,

                                          //                                10, 10, 0);

                       

                                          sketchMgr.InsertSketch(false );

                                      }

                                  }

                                  sketchMgr.AddToDB = false;

                                  modelView.EnableGraphicsUpdate = true;

                                  iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, true);

                       

                      And the DocumentVisible has no effect to this, I think it only works when you are loading file.

                      btw, your website is very cool, I like it

                       

                      Jason