14 Replies Latest reply on Aug 30, 2013 3:30 AM by Oleg Bezyaev

    Light geometry

    Oleg Bezyaev

      Is there some sort of way to create sketch geometry without visibility to the user and not resource intensive?

      For example, to draw a line so that it will not appear on the screen and when it was available all of its parameters (StartPoint, EndPoint ...)

        • Re: Light geometry
          Artem Taturevych

          Use ICurve interface which is the definition of sketch segments.

            • Re: Light geometry
              Oleg Bezyaev

              Modeler swModeler = (Modeler)SwApp.GetModeler(); //not null

              ICurve myCurve2 = (ICurve)swModel.CreateLine2(0D, 0D, 0D, 1D, 0D, 0D); //return null

                • Re: Light geometry
                  Artem Taturevych

                  Hi Oleg,

                   

                  Here is the C# sample:

                   

                  static ICurve CreateLine(IModeler modeler, double[] startPoint, double[] endPoint)

                  {

                      double[] dir = new double[] { endPoint[0] - startPoint[0], 

                                                    endPoint[1] - startPoint[1],

                                                    endPoint[2] - startPoint[2]};

                      ICurve curve = modeler.CreateLine(startPoint, endPoint) as ICurve;

                      if (curve != null)

                      {

                      }

                      return curve.CreateTrimmedCurve2(startPoint[0], startPoint[1], startPoint[2],

                  endPoint[0], endPoint[1], endPoint[2]);

                  }

                   

                  static void Main(string[] args)

                  {

                      ISldWorks app = Activator.CreateInstance<SldWorksClass>();

                   

                      if (app != null)

                      {

                          ICurve curve = CreateLine(app.IGetModeler(), new double[] { 0, 0, 0 }, new double[] { 1, 0, 0 });

                   

                          System.Diagnostics.Debug.Assert(curve != null);

                   

                          //get line params

                          double[] lineParams = curve.LineParams as double[];

                         

                          double start;

                          double end;

                          bool isClosed;

                          bool isPeriodic;

                   

                          curve.GetEndParams(out start, out end, out isClosed, out isPeriodic);

                   

                          double[] evalData = curve.Evaluate2(start, 1) as double[];

                          //evalData[0]...evalData[2] - evaluated point

                          //evalData[3]...evalData[5] - evaluated derivative 1 (tangent vector)

                      }

                  }

                  ____________________________________________________

                  Regards,

                  Artem Taturevych, Application Engineer at Intercad (Australia)

                   

                  translationXpert – add-in to translate SolidWorks models

                  myIntercad an integrated tool for SolidWorks Professionals

                  LinkedIn SolidWorks API Education Group

                    • Re: Light geometry
                      Oleg Bezyaev

                      I missed CreateTrimmedCurve2

                      Thank you, Artem!

                      • Re: Light geometry
                        Oleg Bezyaev

                        Hi Artem,

                        can you help me again?

                         

                        myCenter.ArrayData[0] = 0.0000023202759685468531

                        myCenter.ArrayData[0] = 0.0000065053843365034717

                        myCenter.ArrayData[0] = 0.0000041851083679566182

                         

                        firstVector.ArrayData[0] = 1.0

                        firstVector.ArrayData[0] = 0

                        firstVector.ArrayData[0] = 0

                         

                         

                         

                        1. private double[] GetPoint(IBody2 myBody, MathPoint myCenter, MathVector firstVector) 
                        2.         { 
                        3.             double[] pointOnEdge; 
                        4.             Face2[] swFaceArr = new Face2[1]; 
                        5.             Face2 swFace = (Face2)myBody.GetFirstFace(); 
                        6.  
                        7.             while ((null != swFace)) 
                        8.             { 
                        9.                 Loop2 myLoop = swFace.GetFirstLoop(); 
                        10.                 if (myLoop.IsOuter()) 
                        11.                 { 
                        12.                     object[] myEdjes = myLoop.GetEdges(); 
                        13.                     IEdge[] myEdjes1 = Array.ConvertAll<object, IEdge>((object[])myEdjes, delegate(object obj) { return obj as IEdge; }); 
                        14.                     foreach (IEdge myEdje in myEdjes1) 
                        15.                     { 
                        16.                         ICurve myCurve = myEdje.GetCurve(); 
                        17.  
                        18.                         ICurve curve = CreateLine(SwApp.IGetModeler(), new double[] { myCenter.ArrayData[0], myCenter.ArrayData[1], myCenter.ArrayData[2] }, 
                        19.                                                                        new double[] { firstVector.ArrayData[0], firstVector.ArrayData[1], firstVector.ArrayData[2] }); 
                        20.  
                        21.  
                        22.                         double[] lineParams = curve.LineParams as double[];//NullReferenceException 
                        23.                         object myPoint = myCurve.IntersectCurve(curve, myEdje.GetStartVertex().GetPoint(), myEdje.GetEndVertex().GetPoint(), new double[] { lineParams[0], lineParams[1], lineParams[2] }, 
                        24.                                                                                                                                              new double[] { lineParams[3], lineParams[4], lineParams[5] }); 
                        25.                         Type UUU = myPoint.GetType(); 
                        26.                         if (UUU.Name != "DBNull"
                        27.                         { 
                        28.                             return pointOnEdge = (double[])myPoint; 
                        29.                         } 
                        30.                     } 
                        31.                     myLoop.GetNext(); 
                        32.                 } 
                        33.                 swFace = (Face2)swFace.GetNextFace(); 
                        34.             } 
                        35.             return null
                        36.         } 
                        37.  
                        38.         static ICurve CreateLine(IModeler modeler, double[] startPoint, double[] endPoint) 
                        39.         { 
                        40.             double[] dir = new double[] { endPoint[0] - startPoint[0],  
                        41.                                   endPoint[1] - startPoint[1], 
                        42.                                   endPoint[2] - startPoint[2]}; 
                        43.             ICurve curve = modeler.CreateLine(startPoint, endPoint) as ICurve; 
                        44.             if (curve != null
                        45.             { 
                        46.             } 
                        47.             ICurve myCurve = curve.CreateTrimmedCurve2(startPoint[0], startPoint[1], startPoint[2], 
                        48.         endPoint[0], endPoint[1], endPoint[2]);//return null 
                        49.             ICurve myCurve1 = curve.CreateTrimmedCurve2(startPoint[0], startPoint[1], startPoint[2], 
                        50.             dir[0], dir[1], dir[2]);//return null 
                        51.             return myCurve; 
                        52.         } 
                    • Re: Light geometry
                      Oleg Bezyaev

                      Is there any simple examples? Please

                    • Re: Light geometry
                      Simon Turner

                      I use SketchManager::AddToDB and DisplayWhenAdded.