Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Inventor 2022
API Visual Studio
I try to use the Sample Code to import a DWG Sketch into Inventor Sketch.
This Code works with Inventor API (with VBA), but when i want to use it in Visual Studio with VB.NET, then i got some Problem.
This is My CODE:
Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Module CommandFunctionButton_04
Public Sub CommandFunctionfweButton_04()
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 oRefComponents As ReferenceComponents = oCompDef.ReferenceComponents
Dim oImportedCompDef As ImportedComponentDefinition
oImportedCompDef = oRefComponents.ImportedComponents.CreateDefinition("C:\AutoCAD\ACADDWG.dwg")
Dim oImportedDWGDef As ImportedDWGComponentDefinition
If oImportedCompDef.Type = ObjectTypeEnum.kImportedDWGComponentDefinitionObject Then
oImportedDWGDef = oImportedCompDef
End If
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
oMatrix.SetTranslation(g_inventorApplication.oTG.CreateVector(0, 0, 1))
oImportedDWGDef.Transformation = oMatrix
Dim oImportedComponent As ImportedComponent
oImportedComponent = oRefComponents.ImportedComponents.Add(oImportedDWGDef)
Dim oImportedDWGComponent As ImportedDWGComponent
If oImportedComponent.Type = ObjectTypeEnum.kImportedDWGComponentObject Then
oImportedDWGComponent = oImportedComponent
Dim oSk As PlanarSketch
oSk = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))
Dim oDWGModelSpaceDef As DWGBlockDefinition
oDWGModelSpaceDef = oImportedDWGComponent.ModelSpaceDefinition
Dim oDWGEntity As DWGEntity
For Each oDWGEntity In oDWGModelSpaceDef.Entities
Call oSk.AddByProjectingEntity(oDWGEntity)
Next
End If
End Sub
End Module
I got a Problem with :
oImportedDWGDef.Transformation = oMatrix
Error:
Using Variable, befor give any Value, Value null
Other Problem:
The Public Member oTG for type Aplication was not Found.
I dont know, where is the Problme.
Thanks for any Sugestion
Solved! Go to Solution.