[VB.Net] Issue with converting part to sheet metal in Add-in

[VB.Net] Issue with converting part to sheet metal in Add-in

S.Hørup
Contributor Contributor
940 Views
5 Replies
Message 1 of 6

[VB.Net] Issue with converting part to sheet metal in Add-in

S.Hørup
Contributor
Contributor

I am converting my VBA-code to a VB.Net Add-in as we are soon upgrading from Inventor 2018 to 2021.

 

I have one issue I cannot find the root cause in - So I hope there are a clever mind who can help solving this 🙂

 

I have a sub-routine containing the code to convert a part-template between a 3D model and sheet metal. The convertion is triggered by a Sheet Metal rule-value we assign to each material in or material library.

 

I have posted my Sub-routine below.

  • If I run the code as a Plug-In (easiest for testing), the code works in both Inventor 2018 and 2021. 
  • If I run the code as an Add-In, the code works only in Inventor 2018. In 2021 the part is not converted to a sheet metal.

The attached ScreenCast shows the difference in Inventor 2021 and Inventor 2018

 

Anyone 

 

The Sub:

 

[This is placed in a class called SharedVariables]

Public Shared invApp As Inventor.Application = GetObject(, "Inventor.Application"

Public Shared oDoc
[Sub routine to assign oDoc] 
Shared Sub DocType()

        '---------------------------- Description --------------------------------------'
        '                                                                               '
        ' This subassemblies determines if you are in a assembly or part environment.   '
        ' How the oDoc is assigned i depending on the environment                       '
        '                                                                               '
        '-------------------------------------------------------------------------------'

        If SharedVariables.invApp.ActiveDocument.DocumentSubType.DocumentSubTypeID = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Or
        SharedVariables.invApp.ActiveDocument.DocumentSubType.DocumentSubTypeID = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then
            'DocumentSubtypeID: Assembly; {E60F81E1-49B3-11D0-93C3-7E0706000000}, Weldment Assembly; {28EC8354-9024-440F-A8A2-0E0E55D635B0}
            '-- Assembly document
            SharedVariables.oDoc = SharedVariables.invApp.ActiveEditDocument
        Else
            '-- Part document
            SharedVariables.oDoc = SharedVariables.invApp.ActiveDocument
        End If
    End Sub

 

[Sub-routine to convert part - This is the one causing the issue]

'---------------------------- Description --------------------------------'

' This sub routine is executed when a "rectangular massive"-template part ' is updated. It converts the part between part and sheetmetal depending on         ' a Sheet metal rule assigned to each material.                                 


'-- List of Document subtypes:
'-- Sheet metal:    {9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}
'-- Part:           {4D29B490-49B2-11D0-93C3-7E0706000000}

'---------------------------- Declare variables --------------------------'
Dim customPropSet As PropertySet
customPropSet = SharedVariables.oDoc.PropertySets.Item("Inventor User Defined Properties")
Dim customSMR As [Property]
customSMR = customPropSet.Item("SHEET_METAL_RULE")

Dim oSheetMetalToPart As ControlDefinition = SharedVariables.invApp.CommandManager.ControlDefinitions.Item("PartConvertToStandardPartCmd")
Dim oPartToSheetMetal As ControlDefinition = SharedVariables.invApp.CommandManager.ControlDefinitions.Item("PartConvertToSheetMetalCmd")

'---------------------------- Convert part --------------------------'
If SharedVariables.SMRVal IsNot Nothing Then
     customSMR.Value = SharedVariables.SMRVal
Else
     customSMR.Value = ""
End If

'-- Convert the part to the correct type (Part or Sheetmetal). If the part has a flat pattern, do not convert the part.

If customSMR.Value <> "" Then
'-- If it have a number it is a sheet metal. convert to sheet metal
   If SharedVariables.oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
'-- If the part is different from sheet metal type, then set to sheet metal
        Call oPartToSheetMetal.Execute2(True)
  End If
Else
   If SharedVariables.oDoc.DocumentSubType.DocumentSubTypeID <> "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
      Dim oSheetMetalCompDef As SheetMetalComponentDefinition
      oSheetMetalCompDef = SharedVariables.oDoc.ComponentDefinition
      If Not oSheetMetalCompDef.HasFlatPattern = True Then
           Call oSheetMetalToPart.Execute()
      End If
  End If
End If

 

What I have found out so far, it is not the lines for convertion of the part that is the issue. If I isolate the code it works. When I introduce the if-statements the controlDefinition-commands are not triggered. I have tried placing msgbox before and after the controldefinition-command to make sure i the command should be executed.

 

But I really don't know what to look fore, as it is only in Inventor 2021 and as an Add-in the problem occures.

 

Kind regardds,

Steffen

 

0 Likes
Accepted solutions (1)
941 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

If you could share the add in file (*.addin) then we can take a look at the add in version for inventor.

Have you set the recommended reference to the correct inventor version in the references of VB?

 

regards,

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

0 Likes
Message 3 of 6

bradeneuropeArthur
Mentor
Mentor

If you could share the add in file (*.addin) then we can take a look at the add in version for inventor.

 

https://www.cadforum.cz/cadforum_en/products.asp

 

Have you set the recommended reference to the correct inventor version in the references of VB?

 

regards,

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

0 Likes
Message 4 of 6

S.Hørup
Contributor
Contributor

Addin file:

<Addin Type="Standard">
  <!--Created for Autodesk Inventor 2018 (Version 22.0)-->
  <ClassId>{f15f8de1-1372-448a-951c-79cbb2023f8d}</ClassId>
  <ClientId>{f15f8de1-1372-448a-951c-79cbb2023f8d}</ClientId>
  <DisplayName>xForm</DisplayName>
  <Description>x Addin version 2.0</Description>
  <Assembly>x_Addin.dll</Assembly>
  <LoadOnStartUp>1</LoadOnStartUp>
  <UserUnloadable>1</UserUnloadable>
  <Hidden>0</Hidden>
  <SupportedSoftwareVersionGreaterThan>21..</SupportedSoftwareVersionGreaterThan>
  <DataVersion>1</DataVersion>
  <UserInterfaceVersion>1</UserInterfaceVersion>
</Addin>

 

In references i have tried to change the Interop-reference from 2018 to 2021, but it hasn't changed anything.

Interop:

C:\Program Files\Autodesk\Inventor 2021\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll

Version: 25.1.0.0

 

I forgot to mention that I have used Ekins Solutions Addin-template

https://ekinssolutions.com/wp-content/uploads/2018/11/CreatingInventorAddIns-AU2018.pdf

 

0 Likes
Message 5 of 6

S.Hørup
Contributor
Contributor
Accepted solution

I have solved the issue.

I created a new Form in the same addin-solution and then copy pasted Sub modules  one by one and tested the form with each step. Thus hoping to find the culprit somewhere. No errors in the code.

 

Instead the issue was that I opened the form with Formname.ShowDialog() instead of Formname.Show().

 

Dim AdminForm As New FrmAdmin
AdminForm.ShowDialog()

 

I conclude, that the .showdialog() method does not allow to run controldefinitions.

 

By using .show() the Addin works as intented

 

Dim AdminForm As New FrmAdmin
AdminForm.Show()

 

0 Likes
Message 6 of 6

S.Hørup
Contributor
Contributor

An update:

I found a work-around to run the ControlDefinition in Modal form:

 

 

Dim oPartToSheetMetal As ControlDefinition = SharedVariables.invApp.CommandManager.ControlDefinitions.Item("PartConvertToSheetMetalCmd")

SharedVariables.invApp.UserInterfaceManager.UserInteractionDisabled = False

oPartToSheetMetal.Execute2(True)

SharedVariables.invApp.UserInterfaceManager.UserInteractionDisabled = True

 

 

 

Using Modeless form instead of Modal gives another issue: Space and Ente now triggers Inventors "Repeat Last Command". With the form open "Enter" will open an additional form, as open form was last used command.

 

To solve this I use the Form_Activated and Form_Deactivate to enable keyinput to my form instead of inventor:

 

Private Sub Form_Activated(sender As Object, e As EventArgs) Handles Me.Activated
    Inventor.Application.UserInterfaceManager.UserInteractionDisabled = True
End Sub

Private Sub Form_Deactivate(sender As Object, e As EventArgs) Handles Me.Deactivate
   Inventor.Application.UserInterfaceManager.UserInteractionDisabled = False
End Sub


Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Enter Then
            BtnOK.PerformClick()
        End If
End Sub

 

 

I hope this will help other developers in the future