[Add In Programming] Trouble with making automatic face on sketch

[Add In Programming] Trouble with making automatic face on sketch

Anonymous
Not applicable
602 Views
3 Replies
Message 1 of 4

[Add In Programming] Trouble with making automatic face on sketch

Anonymous
Not applicable

I've recently started making an addin, for making easy parts at my company.

I want the project to do a couple of things:

  • Make new part (DONE)
  • Make it a sheet metal part (DONE)
  • Make sketch in said part (DONE)
  • Draw rectangle from input (DONE)
  • Make a face on said sketch (This is where I'm having trouble)

In the future I will need it so make flanges by input (different angles, and length.)

And making DXF file of the unfolded part, and saving it to location.

 

Where I'm having trouble right now is with the face part.

error.png

 

 

 

 

 

 

The writing is in danish but translated it says

 

"The public member 'FaceFeatures' in type

'SheetMetalComponentDefinition' was not found."

 

    Public Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click

        Dim invApp As Inventor.Application
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject _
                                           ("Inventor.Application")

        Dim docs As Inventor.Documents
        docs = invApp.Documents

        Dim partDoc As Inventor.PartDocument
        partDoc = docs.Add(Inventor.DocumentTypeEnum.kPartDocumentObject)

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

        Dim partDef As Inventor.SheetMetalComponentDefinition
        partDef = partDoc.ComponentDefinition

        Dim oSheetMetalFeatures As SheetMetalFeatures
        oSheetMetalFeatures = partDef.Features

        Dim oUnit As UnitsTypeEnum
        oUnit = UnitsTypeEnum.kMillimeterLengthUnits

        partDoc.UnitsOfMeasure.LengthUnits = oUnit

        '...................................................'

        Dim xyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(3)

        Dim sketch1 As Inventor.PlanarSketch
        sketch1 = partDef.Sketches.Add(xyPlane, False)

        '...................................................'

        Dim oTransGeom As TransientGeometry
        oTransGeom = g_inventorApplication.TransientGeometry

        Dim oLength As Integer = Convert.ToInt32(tLength.Text)
        Dim oWidth As Integer = Convert.ToInt32(tWidth.Text)
        Dim oHeigth As Integer = Convert.ToInt32(tHeight.Text)


        Call sketch1.SketchLines.AddAsTwoPointRectangle(
                                oTransGeom.CreatePoint2d(0, 0),
                                oTransGeom.CreatePoint2d((oLength / 10), (oWidth / 10)))

        Dim oProfile As Profile
        oProfile = sketch1.Profiles.AddForSolid

        Dim oFaceFeatureDefinition As FaceFeatureDefinition
        oFaceFeatureDefinition = partDef.FaceFeatures.CreateFaceFeatureDefinition(oProfile)


        Dim oFaceFeature As FaceFeature
        oFaceFeature = oSheetMetalFeatures.FaceFeatures.Add(oFaceFeatureDefinition)

    End Sub

Thats my code.

I've looked up a lot of the samples on website: http://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-1A2151F4-59B8-4F3E-B704-F0F6FFFAE38E

 

And I've changed the code to work in VB.NET, but it seems like a lot of the samples are a bit outdated(might be wrong there, as it has worked with some tweaks.)

 

Anybody who've had any luck with the kind of things? That could maybe lead me into the right direction.

 

Note I'm not really a programmer by any means, I've done some programming in C#, but most of what I make right

now is done by looking up a lot of things.

0 Likes
603 Views
3 Replies
Replies (3)
Message 2 of 4

Tony_Yates
Advocate
Advocate

Hi,

 

We have something that may help you.

Below is the VBA:-

 

Public Sub New_Sheet_Metal()
New_SM.CreateSheetMetalPart
RuniLogic "Parameters"

End Sub
Private Sub CreateSheetMetalPart()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject, "C:\Vault Workspace\Resources\Templates\Sheet Metal.ipt", True)
End Sub

Public Sub RuniLogic(ByVal RuleName As String)
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
iLogicAuto.RunRule oDoc, RuleName
End Sub

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function

 

Change text in red to your template location. Add the template part there.

Add button images to your VBA project location.

Right click on the ribbon - customise user commands - choose commands from - Macros - Add New_Sheet_Metal - tick large & text.

 

Done.

0 Likes
Message 3 of 4

Tony_Yates
Advocate
Advocate

Hi,

 

Video of what it does.

 

0 Likes
Message 4 of 4

marcin_otręba
Advisor
Advisor

Hi,

 

try this:

 

  Public Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click

        Dim invApp As Inventor.Application
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject _
                                           ("Inventor.Application")

        Dim docs As Inventor.Documents
        docs = invApp.Documents

        Dim partDoc As Inventor.PartDocument
        partDoc = docs.Add(Inventor.DocumentTypeEnum.kPartDocumentObject)

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

        Dim partDef As Inventor.SheetMetalComponentDefinition
        partDef = partDoc.ComponentDefinition

        Dim oSheetMetalFeatures As SheetMetalFeatures
        oSheetMetalFeatures = partDef.Features

        Dim oUnit As UnitsTypeEnum
        oUnit = UnitsTypeEnum.kMillimeterLengthUnits

        partDoc.UnitsOfMeasure.LengthUnits = oUnit

        '...................................................'

        Dim xyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(3)

        Dim sketch1 As Inventor.PlanarSketch
        sketch1 = partDef.Sketches.Add(xyPlane, False)

        '...................................................'

        Dim oTransGeom As TransientGeometry
        oTransGeom = invApp.TransientGeometry

        Dim oLength As Integer = Convert.ToInt32(tLength.Text)
        Dim oWidth As Integer = Convert.ToInt32(tWidth.Text)
        Dim oHeigth As Integer = Convert.ToInt32(tHeight.Text)


        Call sketch1.SketchLines.AddAsTwoPointRectangle(
                                oTransGeom.CreatePoint2d(0, 0),
                                oTransGeom.CreatePoint2d((oLength / 10), (oWidth / 10)))

        Dim oProfile As Profile
        oProfile = sketch1.Profiles.AddForSolid

        Dim oFaceFeatureDefinition As FaceFeatureDefinition
        oFaceFeatureDefinition = oSheetMetalFeatures.FaceFeatures.CreateFaceFeatureDefinition(oProfile)


        Dim oFaceFeature As FaceFeature
        oFaceFeature = oSheetMetalFeatures.FaceFeatures.Add(oFaceFeatureDefinition)

    End Sub

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes