Standalone Application Inventor

Standalone Application Inventor

nicolas_couallier
Explorer Explorer
465 Views
2 Replies
Message 1 of 3

Standalone Application Inventor

nicolas_couallier
Explorer
Explorer

Good Morning,

i am trying to create an executable that launches Inventor, draws a few lines on a sketch and then save the part it created.

I wrote the following code in VBA using  Visual Studio 2019.

The code compile but when launched i have the following Exception: System.InvalidOperationException

The error is the public member 'TransientGeomtry' of 'PartDocument' type can be founded: 

(in french below)

nicolascouallier_0-1624526694769.png

The code i wrote is the following:

Public Sub Triangle()
Dim oTG As TransientGeometry
Dim oDoc As PartDocument

oDoc = _invApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _invApp.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))

Dim oSketch As PlanarSketch
oSketch = oDoc.ComponentDefinition.Sketches.Add(oDoc.ComponentDefinition.WorkPlanes.Item(3))


oTG = oDoc.TransientGeometry

Dim ocord(0 To 3) As Point2d

ocord(1) = oTG.CreatePoint2d(0, 0)
ocord(2) = oTG.CreatePoint2d(1, 0)
ocord(3) = oTG.CreatePoint2d(1, 1)

Dim oLines(0 To 4) As SketchLine
oLines(1) = oSketch.SketchLines.AddByTwoPoints(ocord(1), ocord(2))
oLines(2) = oSketch.SketchLines.AddByTwoPoints(ocord(2), ocord(3))
oLines(3) = oSketch.SketchLines.AddByTwoPoints(oLines(2).EndSketchPoint, oLines(1).StartSketchPoint)

 

I made the following Import:

Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor

 

Does anyone know where the problem comes from ?

Thank you for your answers.

0 Likes
Accepted solutions (1)
466 Views
2 Replies
Replies (2)
Message 2 of 3

FINET_Laurent
Advisor
Advisor
Accepted solution

Salut !

 

It is in the application and not in the document that you have to look for the geometries.

 

C'est dans l'appication et non dans le document que tu dois aller chercher les géométries.

oTg = ThisApplication.TransientGeometry

et non oTg = oDoc.TransientGeometry

 

Bàt,

 

FINET L.

 

Mod note: English translation added

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 3

nicolas_couallier
Explorer
Explorer

It works perfectly.

Thank you very much.