Inventor Customization

Inventor Customization

Reply
Contributor
bravaiser
Posts: 25
Registered: ‎08-16-2012
Message 1 of 5 (236 Views)

How to create a workplane from a selected face?

236 Views, 4 Replies
11-14-2012 05:52 AM

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

ADN Support Specialist
ekinsb
Posts: 300
Registered: ‎07-21-2006
Message 2 of 5 (233 Views)

Re: How to create a workplane from a selected face?

11-14-2012 07:33 AM 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
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Contributor
bravaiser
Posts: 25
Registered: ‎08-16-2012
Message 3 of 5 (230 Views)

Re: How to create a workplane from a selected face?

11-14-2012 08:31 AM in reply to: ekinsb

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

Contributor
bravaiser
Posts: 25
Registered: ‎08-16-2012
Message 4 of 5 (229 Views)

Re: How to create a workplane from a selected face?

11-14-2012 08:37 AM 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? 

ADN Support Specialist
ekinsb
Posts: 300
Registered: ‎07-21-2006
Message 5 of 5 (226 Views)

Re: How to create a workplane from a selected face?

11-14-2012 08:56 AM 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
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.