Message 1 of 5
variables to parameters of an assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am new to inventor and I would like to pass my text type variables to parameters of an assembly, but when I execute it, it does not pass the variables to the inventor.
If someone could help me or pass a tutorial to give me a reference, it would be very helpful.
I attach my code and my form next to where I want it to be displayed in inventor.
Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor
Public Class Form1
Dim _invApp As Inventor.Application 'Variable que hace referencia a inventor la cual se utilizará para proporcionar un acceso rápido al objeto de aplicación de Inventor
Dim _started As Boolean = False
Dim Panel_PanelRef As String
Dim Panel_PanelWidth As String
Dim Panel_PanelHeight As String
Dim Panel_PanelThickness As String
Dim oPartDoc As PartDocument
Public Sub New()
' Esta llamada es requerida por el diseñador.
InitializeComponent()
'Añadir cualquier inicialización después de la llamada InitializeComponent()
Try
_invApp = Marshal.GetActiveObject("Inventor.Application") 'Esta variable contiene un objeto de tipo inventor
Catch ex As Exception
Try
Dim invAppType As Type =
GetTypeFromProgID("Inventor.Application")
_invApp = CreateInstance(invAppType)
_invApp.Visible = True
_started = True
Catch ex2 As Exception
MsgBox(ex2.ToString())
MsgBox("Unable to get or start Inventor")
End Try
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Panel_PanelRef = TextBox1.Text
Panel_PanelWidth = TextBox2.Text
APanel_PanelHeight = TextBox3.Text
Panel_PanelThickness = TextBox4.Text
Try
_invApp = Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
MessageBox.Show("Cannot connect to Inventor")
End Try
oPartDoc = _invApp.ActiveDocument
oPartDoc.ComponentDefinition.Parameters.Item("API_Panel_PanelRef").Expression = Panel_PanelRef
oPartDoc.ComponentDefinition.Parameters.Item("API_Panel_PanelWidth").Expression = Panel_PanelWidth
oPartDoc.ComponentDefinition.Parameters.Item("API_APanel_PanelHeight").Expression = APanel_PanelHeight
oPartDoc.ComponentDefinition.Parameters.Item("API_Panel_PanelThickness").Expression = Panel_PanelThickness
oPartDoc.Update()
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
' Esto cerrará la sesión de Inventor iniciada cuando se inició el formulario
If _started Then
_invApp.Quit()
End If
_invApp = Nothing
'Aquí se sale de la sesión de Inventor si _started está establecido en True (es decir, fue el código el que inició la sesión, ya que uno aún no se estaba ejecutando).
End Sub
End Class