VB.net cant call Sub in event (Inventor API)

VB.net cant call Sub in event (Inventor API)

j.romo
Advocate Advocate
335 Views
4 Replies
Message 1 of 5

VB.net cant call Sub in event (Inventor API)

j.romo
Advocate
Advocate

Hello, I have been trying to call a Sub on a Button Event and no luck

Public Class frmFLOR


    Sub Main()
        Dim invApp As Inventor.Application = GetObject(, "Inventor.Application")
        AddSketch(invApp)
    End Sub

    Private Sub btnSketch1_Click(sender As Object, e As EventArgs) Handles btnSketch1.Click
' here is how I call the sub, But it doesnt Work
        AddSketch()
       


    End Sub
    Public Sub AddSketch(ThisApplication As Inventor.Application)
       
        Dim oCompDef As PartComponentDefinition
        oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

        
        Dim oSketch As PlanarSketch
        oSketch = oCompDef.Sketches.Add("XY Plane", True)
        oSketch.Name = "Master Sketch"

    End Sub

End Class

 

Any help would be apreciated

 

0 Likes
Accepted solutions (1)
336 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @j.romo.  It looks to me like you may just be missing a line to declare the 'btnSketch1' variable as having Events you want to be able to access.  A like something like the following, I believe:

 

Private WithEvents btnSketch1 As ????

...I assume that 'btnSketch1' represents a System.Windows.Forms.Button, but I was not 100% sure.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

j.romo
Advocate
Advocate

Yes the  'btnSketch1' is a button of a Form in Visual Studio, right now I can Open the form but cant call the Sub  AddSketch().

I want to ru the Sub once I click on the Button

0 Likes
Message 4 of 5

j.romo
Advocate
Advocate

I get this error in the debug 

jromo_0-1665593370759.png

You didnt Specify an argument for the parameter 'ThisApplication' of 'Public Sub AddSketch(ThisApplication As Application)

0 Likes
Message 5 of 5

j.romo
Advocate
Advocate
Accepted solution

Ok I found the problem,

it seems that to call a function we need to add (g_inventorApplication)

code looks like this:

Public Class frmFLOR


    Sub Main()
        Dim invApp As Inventor.Application = GetObject(, "Inventor.Application")
        AddSketch(invApp)
    End Sub

    Private Sub btnSketch1_Click(sender As Object, e As EventArgs) Handles btnSketch1.Click

        AddSketch(g_inventorApplication)
        


    End Sub



    Public Sub AddSketch(ThisApplication As Inventor.Application)
 
        Dim oCompDef As PartComponentDefinition
        oCompDef = ThisApplication.ActiveDocument.ComponentDefinition



        Dim xyPlane As Inventor.WorkPlane = oCompDef.WorkPlanes.Item(3)
        Dim oSketch As PlanarSketch
        oSketch = oCompDef.Sketches.Add(xyPlane, False)
        oSketch.Name = "Master Sketch"

    End Sub
0 Likes