I was trying to scale a surface body in one direction and having no success. I eventually came up with a work around to make it work, but I have no idea why it actually works. Or more importantly, why it didn't work before.
Here's the code that doesn't work.
I create a surface using an existing sketch - Works
I select the surface body. - Works
I scale the surface body. - Fails
namespace ScaleFace
{
public partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swDoc = null;
Feature myFeature = null;
bool boolstatus = true;
swDoc = ((ModelDoc2)(swApp.ActiveDoc));//Create face
swDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);
boolstatus = swDoc.InsertPlanarRefSurface();//change scale in x direction
boolstatus = swDoc.Extension.SelectByID2("", "SURFACEBODY", 0.000254, 0.000254, 0, false, 0, null, 0);
myFeature = ((Feature)(swDoc.FeatureManager.InsertScale(1, false, .5, 1, 1)));return;
}
// The SldWorks swApp variable is pre-assigned for you.
public SldWorks swApp;}
}
Here's the same code with the work around.
The only difference is that I added a solid body before scaling the surface body. I don't select the solid body or refer to it again in any way. It's just there, and the surface body scales.
namespace ScaleFace
{
public partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swDoc = null;
Feature myFeature = null;
bool boolstatus = true;
swDoc = ((ModelDoc2)(swApp.ActiveDoc));//Create face
swDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);
boolstatus = swDoc.InsertPlanarRefSurface();// need to create a solid body. It's the only way I could get the scale to work.
swDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);
myFeature = ((Feature)(swDoc.FeatureManager.FeatureExtrusion3(true, false, true, 0, 0, 0.00381, 0.00254, false, false, false, false, 0, 0, false, false, false, false, true, true, true, 0, 0, false)));//change scale in x direction
boolstatus = swDoc.Extension.SelectByID2("", "SURFACEBODY", 0.000254, 0.000254, 0, false, 0, null, 0);
myFeature = ((Feature)(swDoc.FeatureManager.InsertScale(1, false, .5, 1, 1)));return;
}
// The SldWorks swApp variable is pre-assigned for you.
public SldWorks swApp;}
}
Is there a way to scale the surface body without adding the solid body. I finished the macro, and it does what I want, but this is bugging me. I guess I'm hoping an explanation will shed some more light on how this API works, and make things easier on me in the future.
