7 Replies Latest reply on Nov 14, 2016 10:44 AM by roberto gennari

    Create temporary geometry via API

    Jana Fischer

      I am looking for a way to create temporary geometry via API, like lines or circles. Can someone point me to some API commands for this?

       

      For example, when I use the evaluate -> measure tool via the user interface and select two vertices, several lines emerge showing their distance (red, green, blue, black). There are also black circles on the two selected vertices. This is the kind of temporary geometry I am looking for.

       

      MeasureTempLines.png

      Note: I do not want to use temporary bodies, as their visible width changes when I zoom in and out. I want the objects to have the same size no matter what zoom level I have.

        • Re: Create temporary geometry via API
          Josh Brady

          I'm about 90% certain you're going to have to go in this direction:

           

          API: Drawing into the OpenGL Context

          Help me about OpenGL!

           

          I have not tried this at all, although I'm curious if it will work in VBA.

          • Re: Create temporary geometry via API
            roberto gennari

            Hi Jana,

            Have you tried WireBody interface, the width don't change when you zoom in and out.

            Take this exsample for test the solution.

             

            Sub main()

            Dim swApp As SldWorks.SldWorks
            Dim swPart As SldWorks.PartDoc
            Dim swCurve As SldWorks.Curve
            Dim trimmed_curve As SldWorks.Curve
            Dim swFeature As SldWorks.Feature
            Dim swModeler As SldWorks.Modeler
            Dim swBody As SldWorks.Body2

            Dim nPt(2) As Double
            Dim nPte(2) As Double
            Dim vPt As Variant
            Dim vDir As Variant
            Dim retval As Long
            Set swApp = CreateObject("SldWorks.Application")
            Set swPart = swApp.ActiveDoc
            Set swModeler = swApp.GetModeler
            nPt(0) = 0
            nPt(1) = 0
            nPt(2) = 0
            vPt = nPt
            nPte(0) = 0
            nPte(1) = 0
            nPte(2) = 0.0000001
            vDir = nPte
            Set swCurve = swModeler.CreateLine(vPt, vDir)

            '
            Set trimmed_curve = swCurve.CreateTrimmedCurve2(0, 0, 0, 0, 0, 0.1)

            Set swBody = trimmed_curve.CreateWireBody()

            'swPart.SetLineStyle "CHAIN"
            retval = swBody.Display3(swPart, 255, swTempBodySelectable)

            Stop

            End Sub

             

            Thanks

            Roberto

              • Re: Create temporary geometry via API
                Jana Fischer

                Hi Roberto,

                 

                thanks for the suggestion. I did not use your example but modified it for my case. In my case, I have an assembly document, not a part document. This is what I wrote (in C#):

                 

                            IModeler modeler = sldWorks.GetModeler(); // sldWorks is the ISldWorks object (not defined in this snippet)

                            ICurve curve = modeler.CreateLine(new double[] { 0, 0, 0 }, new double[] { 0.01, 0.01, 0.01 });

                            IBody2 wire = curve.CreateWireBody();

                            int retval = wire.Display3(sldWorks.ActiveDoc, 256, (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);

                            Debug.WriteLine("return value for display: " + retval); // this returns 0 which means "success"

                 

                The strange thing is, even though displaying is successful according to the return value, I cannot see the wire at all.

                Any ideas what could be wrong?

                  • Re: Create temporary geometry via API
                    roberto gennari

                    Hi Jana,

                    I can't help you in c# becouse I program in VB.Net,

                    but I see that you lack the piece of code (in vba)

                    Set trimmed_curve = swCurve.CreateTrimmedCurve2(0, 0, 0, 0, 0, 0.1)

                     

                    You must trimming the ICurve becouse when you made it, it's with infinity lenght.

                    I hope you help your application.

                    Let me know

                     

                    Roberto

                      • Re: Create temporary geometry via API
                        Jana Fischer

                        Hi Roberto,

                         

                        I omitted the trimming because I thought I wouldn't need it - so thanks for the hint about infinte length!

                        So this time I added the trimming, but still nothing is to be seen...

                         

                        Have you ever tried drawing a WireBody in an assembly?

                        Unfortunately it is no help to me if these WireBodies only work in parts.

                        But thank you for trying to help!