Definition.FlatPattern works in VB.NET but not in C# - I get an Error - API

Definition.FlatPattern works in VB.NET but not in C# - I get an Error - API

fsdolphin
Collaborator Collaborator
537 Views
3 Replies
Message 1 of 4

Definition.FlatPattern works in VB.NET but not in C# - I get an Error - API

fsdolphin
Collaborator
Collaborator

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.Type
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
C Sharp
 
       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?)
 
 
FlatPattern Error.png
 
 
 
0 Likes
Accepted solutions (1)
538 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

first define you SheetMetalComponentDefinitions:

Dim x As Inventor.SheetMetalComponentDefinition				
x = compOcc.Definition
x.FlatPattern.FlatBendResults 

Seems that this also not works ( not elegant!) for vb.net 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 4

jjstr8
Collaborator
Collaborator
Accepted solution

Try casting your component definition to a SheetMetalComponentDefinition.

foreach (FlatBendResult fBendResult in ((SheetMetalComponentDefinition)compOcc.Definition).FlatPattern.FlatBendResults)

By default, VB automatically casts to the correct type, where C# requires strict typing in this case.

Message 4 of 4

fsdolphin
Collaborator
Collaborator

Casting it did the trick. Thanks a lot!

0 Likes