Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create a workplane from a selected face?

4 REPLIES 4
Reply
Message 1 of 5
bravaiser
1464 Views, 4 Replies

How to create a workplane from a selected face?

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

4 REPLIES 4
Message 2 of 5
ekinsb
in reply to: bravaiser

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.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 5
bravaiser
in reply to: ekinsb

Thank you for the rapid response let me check what I can do....

Message 4 of 5
bravaiser
in reply to: ekinsb

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? 

Message 5 of 5
ekinsb
in reply to: bravaiser

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); 
}

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report