Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I thought that the API calls would be the same for VB.NET (Visual Basic) and C#, but for some reason, I cannot access
`Definition.FlatPattern` in Csharp the same way as in VB.NET.
Can someone be so kind and explain why do I get an error when trying to access `Definition.FlatPattern` from a component occurrence using Csharp but works fine in VB.NET?
Am I missing a reference to the API? See my imports in each language.
Here is the code...
VB.NET
Imports System.TypeC Sharp
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor
Dim asmDoc As AssemblyDocument asmDoc = _invApp.ActiveDocument Dim selSet As SelectSet selSet = asmDoc.SelectSet Try Dim compOcc As ComponentOccurrence Dim obj As Object For Each obj In selSet compOcc = obj If compOcc.Definition.Type = Inventor.ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then Dim oBend As FlatBendResult For Each oBend In compOcc.Definition.FlatPattern.FlatBendResults ' Do something Next End If Next Catch ex As Exception MsgBox("Is the selected item a Component?") MsgBox(ex.ToString()) Return End Try
using System.Runtime.InteropServices;
using Inventor;
AssemblyDocument asmDoc = default(AssemblyDocument); asmDoc =(AssemblyDocument)_invApp.ActiveDocument; SelectSet selSet = default(SelectSet); selSet = asmDoc.SelectSet; try { ComponentOccurrence compOcc = default(ComponentOccurrence); object obj = null; foreach (object obj_loopVariable in selSet) { obj = obj_loopVariable; compOcc = (ComponentOccurrence)obj; if (compOcc.Definition.Type == Inventor.ObjectTypeEnum.kSheetMetalComponentDefinitionObject) { foreach (FlatBendResult fBendResult in compOcc.Definition.FlatPattern.FlatBendResults)// error in this line { // Do something } Console.WriteLine(compOcc.Definition.Type);// output: kSheetMetalComponentDefinitionObject } } } catch (Exception ex) { MessageBox.Show("Is the selected item a Component?"); MessageBox.Show(ex.ToString()); return; }
ERROR Message:
'ComponentDefinition' does not contain a definition for 'FlatPattern' and no accessible extension method 'FlatPattern' accepting a first argument of type 'ComponentDefinition' could be found (are you missing a using directive or an assembly reference?)
Solved! Go to Solution.