- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.