AnsweredAssumed Answered

InsertMoveCopyBody2 - Add mate

Question asked by Daniel Mattsson on May 7, 2019
Latest reply on May 9, 2019 by Daniel Mattsson

Hello!

 

I hope someone could give me some help.

I want to move a body within a part to make it aligned to the Front Plane.

 

My code works if i use it with SelectByRay and not Entity.Select4 command. But i don't want to select it by Ray.

 

I marked the area where the selecting is not working.

 

Hope someone has the answer

 

BR

 

 

 

 

 

swDoc = ((ModelDoc2)(swApp.OpenDoc6(i, (int)swDocumentTypes_e.swDocPART, 0, "", ref errors, ref warnings)));

swApp.ActivateDoc2(Path.GetFileNameWithoutExtension(i), true, ref longstatus);

swDoc = ((ModelDoc2)(swApp.ActiveDoc));

swPart = (PartDoc)swDoc;

swFeatMgr = (FeatureManager)swDoc.FeatureManager;

 

swDoc.ClearSelection2(true);

 

bodyArr = (object[])swPart.GetBodies2((int)swBodyType_e.swAllBodies, false);

SelectBodies(swApp, swDoc, bodyArr);

 

swBody = (Body2)bodyArr[0];

swFace = (Face2)swBody.GetFirstFace();

swEnt = (Entity)swFace;

 

object Component = null;

IMoveCopyBodyFeatureData FeatureData = null;

Feature varFeature = null;

varFeature = ((Feature)(swDoc.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 1)));

FeatureData = ((IMoveCopyBodyFeatureData)(varFeature.GetDefinition()));

swDoc.ClearSelection2(true);

boolstatus = swEnt.Select4(true, null);

boolstatus = swDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);

FeatureData.AddMate(null, 0, 1, 0, 0, out longstatus);

varFeature.ModifyDefinition(FeatureData, swDoc, Component);

 

 

 

 

 

 

 

public void SelectBodies(SldWorks swApp, ModelDoc2 swModel, object[] bodyArr)

{

// Select and mark the bodies to move

SelectionMgr swSelMgr = default(SelectionMgr);

SelectData swSelData = default(SelectData);

Body2 swBody = default(Body2);

bool status = false;

int i = 0;

 

 

swSelMgr = (SelectionMgr)swModel.SelectionManager;

swSelData = (SelectData)swSelMgr.CreateSelectData();

 

 

if ((bodyArr == null))

return;

for (i = 0; i <= bodyArr.GetUpperBound(0); i++)

{

 

 

swBody = (Body2)bodyArr[i];

swSelData.Mark = 1;

status = swBody.Select2(true, swSelData);

}

}

Outcomes