I am working on a project were I need to select a face and create a workplane out of such face, see the figure attach. my language of choice is C#.
Here is what I think it should be done, my proble is that the oWork (the workplane I just created remains null) and the whole project crashes. Any ideas or recommendations?
private Inventor.Application mApp = null; ..... if (((mApp.ActiveDocument != null))) {
if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)) {
PartComponentDefinition oPartCom = mApp.ActiveDocument as PartComponentDefinition;
PartDocument oDoc = mApp.ActiveDocument as PartDocument; if ((oDoc.SelectSet[1]) is Face) {
System.Windows.Forms.MessageBox.Show("You just selected a surface", "Surface Evaluator"); Face oFace = oDoc.SelectSet[1] as Face;
WorkPlane oWorkpl = oFace as WorkPlane;
PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkpl, false);
//WHAT AM I DOING WRONG?
} } }
thank you in advance.
D
You say you want to create a work plane, but your code makes it look like you want to create a sketch directly on the face. Either one is possible. If you just want to sketch on the face, then just replace your first argument in the Sketches.Add method with oFace. If you do want to first create work plane you need to look at the various add methods on the WorkPlanes collection object.
So I try your suggestions but I am still having problems here is what I did:
Face oFace = oDoc.SelectSet[1] as Face; ==> MISSING LINK :-) ==> how to go from a selected face and transform that into a Workplane WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes ["THE SELECTED FACE"]; PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add (oWorkPlane, false);
How do I convert the selected face into a workplane?
I'm not sure what you're trying to accomplish here. If you just want to sketch on a face then you don't need to create a work plane. You can create the sketch directly on the face. If you need a work plane for some reason then you need to create a work plane on the face and then create the sketch. Below are some functions that demonstrate both.
private void btnFace_Click(object sender, EventArgs e) { Inventor.PartDocument partDoc = (Inventor.PartDocument)invApp.ActiveDocument; Inventor.Face oFace = (Inventor.Face) invApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFacePlanarFilter, "Pick a face."); Inventor.PlanarSketch oSketch = partDoc.ComponentDefinition.Sketches.Add(oFace, false); } private void btnWorkPlane_Click(object sender, EventArgs e) { Inventor.PartDocument partDoc = (Inventor.PartDocument)invApp.ActiveDocument; Inventor.Face oFace = (Inventor.Face)invApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFacePlanarFilter, "Pick a face."); Inventor.WorkPlane oPlane = partDoc.ComponentDefinition.WorkPlanes.AddByPlaneAndOffset(oFace, 0); Inventor.PlanarSketch oSketch = partDoc.ComponentDefinition.Sketches.Add(oPlane, false); }