# Problems with EquationMgr & SelectionManger Solidworks Api C#

Question asked by Artur Dranchuk on May 20, 2018
Latest reply on May 22, 2018 by Artur Dranchuk

I'm trying to understand principles of solidworks API, but have several problems. Here is my 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, \$@"""D""={diameter}");      eqMgr.set_Equation(2, \$@"""L""={length}");      eqMgr.EvaluateAll(); locator.EditRebuild3();      locator.ForceRebuild3(false);      } else { // TODO: Handle other type of surface  } }``

1) I want to measure perimeter & diameter of the selected surface. But if a return value of `GetSelectedObjectCount()` method is greater than 1, `measure.Diameter & measure.Perimete`  both returns -1 .And I kinda understand why, 'cause such operation isn't possible via UI as well (at least with my experience), but can I do smth to solve the problem?
2) The code above has no influence on the equation of the inserted component, even if it writes it on the console. Help please!