B
B
beingofhabits2018-05-20 12:37:24
solidworks
beingofhabits, 2018-05-20 12:37:24

How to change values ​​through equation manager and how to get dimension values?

I'm trying to write a macro on a sharp under SolidWorks. Below is a broken piece of code

for (var i = 0; i < selMgr.GetSelectedObjectCount(); i++)
        {
            var Face = selMgr.GetSelectedObject(i+1);
            surfaces.Add(Face.GetSurface());
            measure = swModel.Extension.CreateMeasure();

            if (surfaces[i].IsCylinder())
            {

                // Problem # 1

                Console.WriteLine("Cylinder " + i);
                measure.Calculate(surfaces[i]);
                var diameter = measure.Diameter * 1000;
                var length = 1000 * measure.Perimeter  / (measure.Diameter * Math.PI);

                var temp = swApp.OpenDoc6(@"E:\OAK\Locator9.SLDPRT", 1, 1, "", 0, 0);
                var part = component.AddComponent5(@"E:\OAK\Locator9.SLDPRT", 0, "", true, "", 0, 0, 0.3);
                swApp.CloseDoc(@"E:\OAK\Locator9.SLDPRT");

                ModelDoc2 locator = part.GetModelDoc();

                var eqMgr = locator.GetEquationMgr();

                Console.WriteLine("Evaluated diameter " + diameter);
                Console.WriteLine("Evaluated length " + length);

                Console.WriteLine(eqMgr.Equation[1] + "   " + eqMgr.Equation[2]);


                //Problem #2


                eqMgr.set_Equation(1, [email protected]"""D""={diameter}");
                eqMgr.set_Equation(2, [email protected]"""L""={length}");
                eqMgr.EvaluateAll();
                locator.EditRebuild3();
                locator.ForceRebuild3(false);
            }
            else
            {
                // TODO: Handle other type of surface 
            }
        }

1) I'm trying to measure the diameter and perimeter of the selected surface, but if the number of selected faces is greater than 1, then both values ​​will return -1. I understand that you can’t do this with the UI either, but maybe there is some way to get around this?
2) The code does not affect the values ​​of the equation in any way, although I can get their values.
I hope to help...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question