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: 

WorkPlanes does not contain a definition for Item

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
snappyjazz
246 Views, 5 Replies

WorkPlanes does not contain a definition for Item

Hello,

I'm trying to create a new part document, and make a model in it. After creating the part document, I create a part component definition. When trying to add a sketch to the workplane, I get the following error:

'WorkPlanes' does not contain a definition for 'Item' and no accessible extension method 'Item' accepting a first argument of type 'WorkPlanes' could be found (are you missing a directive or an assembly reference?)

 

My code shows failed attempts at getting the WorkPlane first, but also a failed attempt at just creating a sketch on the plane. All attempts have the same error. Why doesn't WorkPlanes.Item work?

 

Inv.PartDocument InvDoc = (Inv.PartDocument)g_InvApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
Inv.PartComponentDefinition PrtDef = g_InvDoc. ComponentDefinition;

Inv.WorkPlane Wplane = PrtDef.WorkPlanes.Item(3);
Inv.WorkPlane _Wplane = (Inv.WorkPlane)PrtDef.WorkPlanes.Item(3);
Inv.PlanarSketch CurSketch = PrtDef.Sketches.Add(PrtDef.WorkPlanes.Item(3));

 

5 REPLIES 5
Message 2 of 6

@snappyjazz 

 

I don't know if this will help, but I tried this with an iLogic / vb.net rule and it worked. I didn't try your code as C#/add-in, but I don't see any issue with it.

Edit: maybe see the example here for a C# workplanes example:

https://forums.autodesk.com/t5/inventor-programming-ilogic/creategeometryproxy-function-throwing-exc...

 

InvDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
PrtDef = InvDoc.ComponentDefinition

Wplane = PrtDef.WorkPlanes.Item(3)

CurSketch = PrtDef.Sketches.Add(Wplane)
CurSketch.name = "Test1"

CurSketch = PrtDef.Sketches.Add(PrtDef.WorkPlanes.Item(3))
CurSketch.name = "Test2"

 

Message 3 of 6
Michael.Navara
in reply to: snappyjazz

It is about C# syntax. Access to the item in collection should be in [square brackets] instead of (round brackets)

 

// PrtDef.WorkPlanes.Item(3);
// Should be
PrtDef.WorkPlanes.Item[3];

 

 

Message 4 of 6
snappyjazz
in reply to: snappyjazz

@Curtis_Waguespack 

Thanks for testing. I didn't mention this, but I am building an exe instead of an addin. does that change how to get a workplane or start a sketch? I have included more code below for clarity.

 

@Michael.Navara 

Thanks for replying. I started switching from vb.net to c# 6 months ago and I am still getting used to the C# syntax. Thank you. However, after trying the square brackets I still get the error. 

 

*More info:

I am referencing the Inventor interop: C:\Program Files\Autodesk\Inventor 2024\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll

Target Framework: .NET Framework 4.7.2

 

using Inv = Inventor;

namespace SimplifiedValve
{
    public partial class MainForm : WinFrm.Form
    {
        public static Inv.Application g_InvApp;
        public static Inv.PartDocument g_InvDoc;

private void MainForm_Load(object sender, EventArgs e)
        {
            InitiateConstants();

            // Setup the form
            FormSetup();
            //this.Show();

            // Initiate Inventor
            InitInventor();

            // Make the filename
            UpdateFileName();

            // Model the valve
            //ModelValve();
        }


        #region Initialize Inventor Application
        /// <summary>
        /// Load this to initialize the Inventor application before using it globally.
        /// </summary>
        public void InitInventor()
        {
            // Open a session if it doesn't exist
            // Try gettin a running Inventor session
            try 
            {
                g_InvApp = (Inv.Application)SysInter.Marshal.GetActiveObject("Inventor.Application"); // Get the running Inventor session
                g_InvDoc = (Inv.AssemblyDocument)g_InvApp.ActiveDocument; // Get the active document
            }
            catch (Exception ex) { TryAgain("App"); }

            // Try to get the document again if it wasn't captured
            if (g_InvDoc == null) { TryAgain("Doc"); }

        }
        #endregion

        #region ModelValve
        /// <summary>
        /// Builds the model in Inventor.
        /// </summary>
        public void ModelValve()
        {
            Inv.PartDocument InvDoc = (Inv.PartDocument)g_InvApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
            Inv.PartComponentDefinition PrtDef = g_InvDoc.ComponentDefinition;

            Inv.WorkPlane Wplane = PrtDef.WorkPlanes.Item[3];
            Inv.WorkPlane _Wplane = (Inv.WorkPlane)PrtDef.WorkPlanes.Item[3];
            Inv.PlanarSketch CurSketch = PrtDef.Sketches.Add(PrtDef.WorkPlanes.Item[3]);

            //PrtDef.Sketches.Add()
        }
        #endregion
    }

}

 

Message 5 of 6

@snappyjazz, I didn't test, but using the link I posted above for reference I would try this:

 

PrtDef.WorkPlanes[3]

 

 

 

nv.PlanarSketch CurSketch = PrtDef.Sketches.Add(PrtDef.WorkPlanes[3]);

 

 

Message 6 of 6

That did it. Thank you!

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

Post to forums  

Autodesk Design & Make Report