Solid Convert to Sheet VB.NET API

Solid Convert to Sheet VB.NET API

florian_wenzel
Advocate Advocate
1,038 Views
16 Replies
Message 1 of 17

Solid Convert to Sheet VB.NET API

florian_wenzel
Advocate
Advocate

Hi

 

Inventor 2022 

VB.NET API  with Visual Studio

 

I try to Convert Solid Modell to Sheet Metall

 

The Goal is, we are in Part Document and we make a Autmation to Convert Solid do Sheet Metall, with declaration of Thickness of material.

 

I have a half of this.

I need manually:

  • click Convert to SheetMetall
  • Set the Material Thickess

 

then i use the CODE:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32


Module CommandFunctionButton_07

Public Sub CommandFunctionfweButton_07()

 

Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

 


Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)

 

Dim oSheetCompDef As SheetMetalComponentDefinition
oSheetCompDef = oPartDoc.ComponentDefinition

Dim oSheetMetallFeatures As SheetMetalFeatures


oSheetMetallFeatures = oSheetCompDef.Features

Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )


End Sub

End Module

 

florianwenzelEJNZZ_0-1650484697838.pngflorianwenzelEJNZZ_1-1650484725172.png

 

florianwenzelEJNZZ_2-1650484759437.png

florianwenzelEJNZZ_3-1650484778622.png

 

 

florianwenzelEJNZZ_0-1650487839630.png

 

 

How to make the Convert to SheetMetal?

I was looking in help.Autodesk.Inventor

in:

SheetFeatures

PartFeatures

PartDocument.SubType Property

SheetMetalCheckGUID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

DocumentTypeEnum Enumerator

etc...

but i was Find Nothing.

 

Thanks for any Sugestion.

 

 

0 Likes
Accepted solutions (4)
1,039 Views
16 Replies
Replies (16)
Message 2 of 17

Michael.Navara
Advisor
Advisor

Conversion is made this way:

'To standard part
ThisApplication.ActiveDocument.SubType  = "{4D29B490-49B2-11D0-93C3-7E0706000000}"

'To sheetmeatl part
ThisApplication.ActiveDocument.SubType  = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
Message 3 of 17

florian_wenzel
Advocate
Advocate

Hi,

thanks very much.

 

hmm, that's not all.

I need figure out, how to define the Material Thickness and all necessary info, to make the Unfold.

Because without this data, it crash.

 

 

0 Likes
Message 4 of 17

florian_wenzel
Advocate
Advocate

 

My CODE:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32


Module CommandFunctionButton_07

Public Sub CommandFunctionfweButton_07()

 

Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

 

'To sheetmeatl part
g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

 

Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

 

Dim oStyle As SheetMetalStyle
oStyle = oSheetCompDef.SheetMetalStyles.Item(1)

oStyle.Material = oPartDoc.Materials.Item(1)

 

Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)


Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )

 

End Sub

End Module

 

florianwenzelEJNZZ_0-1650565001157.png

 

Is possible to use default settings, or that will automaticly recognize the Thickenss of the Material?

 

Thanks for any sugestion

0 Likes
Message 5 of 17

Michael.Navara
Advisor
Advisor

This is sample iLogic code, how to convert standard part to sheetmetal and setup basic properties and unfold.

'get target document
Dim part As PartDocument = ThisDoc.Document

'Convert to Sheetmatel part
part.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

'Select top and bottom face
Dim topFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select top face")
Dim bottomFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select bottom face")

'Calculate thickness
Dim thickness As Double = ThisApplication.MeasureTools.GetMinimumDistance(topFace, bottomFace)

'Get sheetmetal component definition
Dim smCompDef As SheetMetalComponentDefinition = part.ComponentDefinition

'Setup thickness
smCompDef.UseSheetMetalStyleThickness = False
smCompDef.Thickness.Value = thickness

'Setup ASide (top face for unfolding)
smCompDef.ASideFace = topFace

'Create flat pattern
smCompDef.Unfold()

 

 

 

0 Likes
Message 6 of 17

florian_wenzel
Advocate
Advocate

Hi,

thanks very much.

 

I need to do this in VB.NET with Visual Studio.

i dont want to jump between Autmatization in VS and ilogic.

im not a fun of ilogic 🙂

 

Thanks

 

This my CODE, but still error:

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32


Module CommandFunctionButton_07


Public Sub CommandFunctionfweButton_07()

Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

 


g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

Dim oStyle As SheetMetalStyle
oStyle = oSheetCompDef.SheetMetalStyles.Item(1)

oStyle.Thickness = "5"
oStyle.BendRadius = "Thickness * 1.5"
oStyle.BendReliefDepth = "Thickness * 1.5"
oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
oStyle.BendReliefWidth = "Thickness / 2"
oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
oStyle.BendTransitionArcRadius = "Thickness * 2.0"
oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
oStyle.CornerReliefSize = "Thickness * 2.0"
oStyle.MinimumRemnant = "Thickness * 2.0"

Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )

 

End Sub

End Module

 

florianwenzelEJNZZ_0-1650643202724.png

 

0 Likes
Message 7 of 17

WCrihfield
Mentor
Mentor
Accepted solution

Hi @florian_wenzel.  I can not read what the error message says, because it is in a language that I'm not fluent in, but it seems to be acting like it doesn't recognize the "Thickness" parameter name.  That is a standard Parameter that is created within all sheet metal parts, and I don't think it changes in other languages, for stability.  So, maybe try including a line of code to update the document after the SubType conversion (oPartDoc.Update).  It may just need a moment to process all the changes, before accessing sheet metal specific parameters.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 17

florian_wenzel
Advocate
Advocate

Hi,

no, still error

Wrong Parameter

 

Maybe, i dont understand this well, and i put this wrong

 

florianwenzelEJNZZ_0-1650648362967.png

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32


Module CommandFunctionButton_07


    Public Sub CommandFunctionfweButton_07()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        oPartDoc.Update()

        Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
        Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

        Dim oStyle As SheetMetalStyle
        oStyle = oSheetCompDef.SheetMetalStyles.Item(1)


        oStyle.Thickness = "5"
        oStyle.BendRadius = "Thickness * 1"
        oStyle.BendReliefDepth = "Thickness * 1"
        oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
        oStyle.BendReliefWidth = "Thickness / 2"
        oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
        oStyle.BendTransitionArcRadius = "Thickness * 2.0"
        oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
        oStyle.CornerReliefSize = "Thickness * 2.0"
        oStyle.MinimumRemnant = "Thickness * 2.0"
        oPartDoc.Update()

        Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
        Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )


    End Sub

End Module

 

i need to make Automatization of this Button or Method

"Sheet Metal Defaults" - In Englisch

 

florianwenzelEJNZZ_0-1650648705913.png

 

florianwenzelEJNZZ_1-1650648733116.png

 

0 Likes
Message 9 of 17

WCrihfield
Mentor
Mentor
Accepted solution

When you look in your Parameters dialog box on a 'new' sheet metal part, do you see a Parameter named "Thickness", or is your named "Starke"?  In my English version of Inventor, when I open a new sheet metal part, there are 9 default 'sheet metal parameters' in their own parameter group above the 'model parameters'.  If your parameter is named "Starke" instead of "Thickness", then you will have to use "Starke" within your quoted values, for them to reference the correct parameter name.

WCrihfield_0-1650649673764.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 17

florian_wenzel
Advocate
Advocate

yes, you right :), thanks

 

but still not working

florianwenzelEJNZZ_0-1650650306370.png

 

It is strange, because now i get Error by UnfolfFeature.

This Line should working Fine.

 

Because the Code below is working, when i manually convert Part to SheetMetall and manually Set the Thickness.

Then the UnfoldFeature work fine.

florianwenzelEJNZZ_1-1650650352713.png

 

 

As you mentioned before, the Paramter dialogBox.

Maybe this Error is because the Parameter Value is wrong etc..

 

florianwenzelEJNZZ_2-1650650555130.png

 

 

0 Likes
Message 11 of 17

florian_wenzel
Advocate
Advocate

Hi,

ok is Working !

Thanks 🙂

 

florianwenzelEJNZZ_0-1650651394510.png

florianwenzelEJNZZ_1-1650651428453.png

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_07
    Public Sub CommandFunctionfweButton_07()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry


        g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        oPartDoc.Update()

        Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
        Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

        Dim oStyle As SheetMetalStyle
        oStyle = oSheetCompDef.SheetMetalStyles.Item(1)


        oStyle.Thickness = "50"
        oStyle.BendRadius = "Stärke"
        oStyle.BendReliefDepth = "Stärke * 0,5"
        oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
        oStyle.BendReliefWidth = "Stärke"
        oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
        oStyle.BendTransitionArcRadius = "Stärke * 2.0"
        oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
        oStyle.CornerReliefSize = "Stärke * 4.0"
        oStyle.MinimumRemnant = "Stärke * 2.0"
        oPartDoc.Update()

        Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
        Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )


    End Sub

End Module

 

it is Strange, because i was Thinking, that the units is "cm" and not "mm"

 

in foto from Viusal Studio Line 24

the Value is 50

before was 5, because i was thinking, that should be "cm"

 

And in other Script, i was using cm.

 

But the Function Works.

Thanks

0 Likes
Message 12 of 17

WCrihfield
Mentor
Mentor

Glad to hear you finally got everything working.  When using quoted input for parameter values, like when setting the Expression of a Parameter, the units will Not be automatically converted.  They will be understood the same as if you typed it into the expression box within the parameters dialog box.  That is often the best way to deal with parameters.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 17

florian_wenzel
Advocate
Advocate

Hi, 

still a question to this Topic:

 

how to set/change the "kFactor"

for exampe on value 0.5

 

I got a Errror, this is my Code:

 

 

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_07
    Public Sub CommandFunctionfweButton_07()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

        g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        oPartDoc.Update()

        Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
        Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

        Dim oStyle As SheetMetalStyle
        oStyle = oSheetCompDef.SheetMetalStyles.Item(1)

        oStyle.Thickness = dist * 10
        oStyle.BendRadius = "Stärke"
        oStyle.BendReliefDepth = "Stärke * 0,5"
        oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
        oStyle.BendReliefWidth = "Stärke"
        oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
        oStyle.BendTransitionArcRadius = "Stärke * 2.0"
        oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
        oStyle.CornerReliefSize = "Stärke * 4.0"
        oStyle.MinimumRemnant = "Stärke * 2.0"
        oPartDoc.Update()

        Dim okFactor As String
        okFactor = "0.5"

        Dim okFactorUnfoldMethod As UnfoldMethod
        okFactorUnfoldMethod = oSheetCompDef.UnfoldMethods.kFactor(okFactor)
        oPartDoc.Update()

        Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
        Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )

    End Sub

End Module

 

 

 

 

The Error:

The Public Member kFactor for UnfoldMethods, not found

 

florianwenzelEJNZZ_0-1650701636642.png

 

When i change the UnfoldMethods on UnfoldMethod,

the i got Error:

The Value of type Char, can not be Convert to UnfoldMethod

 

florianwenzelEJNZZ_1-1650701877024.png

 

 

 

0 Likes
Message 14 of 17

WCrihfield
Mentor
Mentor
Accepted solution

Hi @florian_wenzel.  It looks to me like you are going a step too far with that one line of code (line 38).  The code on line 37 just created a variable of Type UnfoldMethod, without setting its value, then line 38 should only be setting the value of that UnfoldMethod type variable, not also attempting to set a property value within the UnfoldMethod too.  You can attempt to set the value of the UnfoldMethod's kFactor on the next line after that, just before the update code.

Also, up on line 45, I noticed that you used a comma within your specified numerical value "Starke * 0,5", instead of a dot (.), but then you are using a dot in all your other numerical values.  Is that a mistake, or intentional.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 17

florian_wenzel
Advocate
Advocate

hi,

not exactly undertood this

 

My Code:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_07
    Public Sub CommandFunctionfweButton_07()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

        g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        oPartDoc.Update()

        Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
        Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

        Dim oStyle As SheetMetalStyle
        oStyle = oSheetCompDef.SheetMetalStyles.Item(1)

        oStyle.Thickness = dist * 10
        oStyle.BendRadius = "Stärke"
        oStyle.BendReliefDepth = "Stärke * 0.5"
        oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
        oStyle.BendReliefWidth = "Stärke"
        oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
        oStyle.BendTransitionArcRadius = "Stärke * 2.0"
        oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
        oStyle.CornerReliefSize = "Stärke * 4.0"
        oStyle.MinimumRemnant = "Stärke * 2.0"
        oPartDoc.Update()

        Dim okFactor As String
        okFactor = "0.5"

        Dim okFactorUnfoldMethod As UnfoldMethod.kFactor(okFactor)

        oPartDoc.Update()

        Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
        Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )

    End Sub

End Module

 

 

Still Error

 

or like this?

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32

Module CommandFunctionButton_07
    Public Sub CommandFunctionfweButton_07()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

        g_inventorApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        oPartDoc.Update()

        Dim oSheetCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
        Dim oSheetMetallFeatures As SheetMetalFeatures = oSheetCompDef.Features

        Dim oStyle As SheetMetalStyle
        oStyle = oSheetCompDef.SheetMetalStyles.Item(1)

        oStyle.Thickness = dist * 10
        oStyle.BendRadius = "Stärke"
        oStyle.BendReliefDepth = "Stärke * 0.5"
        oStyle.BendReliefShape = BendReliefShapeEnum.kRoundBendReliefShape
        oStyle.BendReliefWidth = "Stärke"
        oStyle.BendTransition = BendTransitionEnum.kArcBendTransition
        oStyle.BendTransitionArcRadius = "Stärke * 2.0"
        oStyle.CornerReliefShape = CornerReliefShapeEnum.kRoundCornerReliefShape
        oStyle.CornerReliefSize = "Stärke * 4.0"
        oStyle.MinimumRemnant = "Stärke * 2.0"
        oPartDoc.Update()

        Dim okFactor As String
        okFactor = "0.5"

        Dim okFactorUnfoldMethod As UnfoldMethod
        kFactor(okFactor)

        oPartDoc.Update()

        Dim oFaceCurved As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
        Call oSheetMetallFeatures.UnfoldFeatures.Add(oFaceCurved, , )

    End Sub

End Module

florianwenzelEJNZZ_0-1650910137570.png

Now the kFactor is without declaration.

 

 

0 Likes
Message 16 of 17

WCrihfield
Mentor
Mentor
Accepted solution

Are you just trying to change the kFactor of the currently 'active' UnfoldMethod, or are you trying to create a new UnfoldMethod, then set that as the 'active' UnfoldMethod?

If you are just trying to change the kFactor of the currently 'active' UnfoldMethod, then you should be able to use something like the following:

oSheetCompDef.UnfoldMethod.kFactor = "0.5" 'or = okFactor

But if you are trying to create a New UnfoldMethod, then set that as the 'active' one, then you should be able to use something like the following:

Dim okFactorUnfoldMethod As UnfoldMethod
okFactorUnfoldMethod = oSheetCompDef.UnfoldMethods.AddLinearUnfoldMethod("MyUnfoldMethod", "0.5")
oSheetCompDef.UnfoldMethod = okFactorUnfoldMethod

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 17 of 17

florian_wenzel
Advocate
Advocate

Yes, now i get it.

Thanks.

0 Likes