Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Externally access the active session of inventor

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ndillner343SKL
161 Views, 2 Replies

Externally access the active session of inventor

Good afternoon,

 

I'm looking for some help with accessing the active session of inventor and running external iLogic rules from a winForm. Any assistance with this would be tremendously appreciated. I'm tired of utilized built in forms. They've become to limited for my use cases. 

 

Thank you for your time!

 

Issue (Unable to call external rules):

Public iLogicVb As Autodesk.iLogic.Interfaces.ILowLevelSupport
iLogicVb.RunExternalRule("Spec Reference List")

 

Complete Code:

AddReference "System.Drawing"
'Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Autodesk.iLogic.Interfaces

 

Public Class WinForm
	Inherits System.Windows.Forms.Form
	' Declare any thing here that you want to use/access throughout all Subs & Functions
	Public iLogicVb As Autodesk.iLogic.Interfaces.ILowLevelSupport
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	Public Sub New() ' Creates the new instance
		oForm = Me
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 500
			.Height = 750
			.TopMost = True
			.Font = oLargerFont
			.Text = "Template"
			.Name = "Template"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "Buttom 1 Test"
			.Top = 25
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click	
		
		Dim oButton2 As New Button()
		With oButton2
			.Text = "Buttom 2 Test"
			.Top = 125
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton2)
		AddHandler oButton2.Click, AddressOf oButton2_Click
		
'		Dim oTextBox1 As New TextBox()
'		With oTextBox1
'			.Text = "I am a Text Box"
'			.Top = 225
'			.Left = 75
'			.Font = oLargerFont
'			.Enabled = True
'			.Width = 250
'			.Height = 50
'		End With
'		oForm.Controls.Add(oTextBox1)
'		AddHandler oTextBox1.Leave, AddressOf oTextBox1_Leave
		
		Dim oCheckBox1 As New CheckBox()
		With oCheckBox1
			.Text = "Check Box"
			.Top = 325
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oCheckBox1)
		AddHandler oCheckBox1.CheckedChanged, AddressOf oCheckBox1_CheckedChanged
		
		Dim oComboBox1 As New ComboBox()
		With oComboBox1
	        .DataSource = {"A", "B", "C", "NA"}
			.Top = 425
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oComboBox1)
		AddHandler oComboBox1.SelectedIndexChanged, AddressOf oComboBox1_SelectedIndexChanged
		
		Dim oRadioButton1 As New RadioButton()
		With oRadioButton1
			.Text = "Radio Button 1"
			.Top = 525
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton1)
		AddHandler oRadioButton1.CheckedChanged, AddressOf oRadioButton1_CheckedChanged
		
		Dim oRadioButton2 As New RadioButton()
		With oRadioButton2
			.Text = "Radio Button 2"
			.Top = 575
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton2)
		AddHandler oRadioButton2.CheckedChanged, AddressOf oRadioButton2_CheckedChanged
	' This is the end of the main Sub that defines the Form .SelectionChangeCommitted
	End Sub

	Private Sub WinForm_FormClosing(ByVal oSender As Object, ByVal oFormCloseEvents As FormClosingEventArgs) Handles Me.FormClosing
'	    If MsgBox("Are you sure you want to close this Form?",vbYesNo+vbQuestion, "CLOSE") = vbYes Then
'	    Else
'	      oFormCloseEvents.Cancel = True
'	    End If
	 End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
'		MsgBox("You just clicked the [" & oSender.Text & "] button.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
'		ThisApplication.ActiveDocument.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject
		iLogicVb.RunExternalRule("Spec Reference List")
	End Sub
	
	Private Sub oButton2_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
'		MsgBox("You just clicked the [" & oSender.Text & "] button.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
'		iLogicVb.RunExternalRule("Spec Reference List")
	End Sub

	Private Sub oTextBox1_Leave(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Text <> oOriginalText Then 'oSender is a TextBox
			MsgBox("The contents of the TextBox have changed.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
		
	Private Sub oCheckBox1_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked = True Then 'Sender is a CheckBox
			MsgBox("You just Checked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
			MsgBox("You just UnChecked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
	
	Private Sub oComboBox1_SelectedIndexChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
'		 oSender is a ComboBox
		MsgBox("You just chose " & oSender.Text & " from the ComboBox.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
	Private Sub oRadioButton1_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked Then 'oSender is a RadioButton
			MsgBox("You just changed the Radio Button option to '" & oSender.Text & "'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
'			MsgBox("You just changed the Radio Button option to 'Choice 2'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub

	Private Sub oRadioButton2_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked Then 'oSender is a RadioButton
			MsgBox("You just changed the Radio Button option to '" & oSender.Text & "'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
'			MsgBox("You just changed the Radio Button option to 'Choice 2'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
End Class

Public Class RunMyForm
	Private Sub Main
		Dim oMyForm As New WinForm
		oMyForm.Show
	End Sub
End Class  

 

2 REPLIES 2
Message 2 of 3
WCrihfield
in reply to: ndillner343SKL

Hi @ndillner343SKL.  One important detail here is, how are you launching your Windows Form(s)?  Are they originating from an Inventor add-in, or from an iLogic rule, or other?  If originating from an iLogic rule, you can pass the iLogic object to your external resource, when you initiate it, or call it to run, one way or another.  Such as using Public Read/Write Property(s) that you can set the value to from a rule, or 'input' parameters when calling Public Methods of the Class, which are then used to set the values of Private 'internal use only' variables.  The is likely the most common way, if you are wanting to use tools/objects that are unique to the iLogic add-in within other stuff.  If it is originating from an add-in, then you may need 2 different things (get the Application object from a higher level shared variable, then use another path for incorporating iLogic stuff).

Edit:  There are also a few things you can get directly from the iLogic ApplicationAddIn object itself.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3
ndillner343SKL
in reply to: WCrihfield

Hi @WCrihfield,

 

Thank you for the reply. I'm launching it from an iLogic rule and accessing the "ApplicationAddIns" did the trick!

 

Imports System.Runtime.InteropServices
Imports Inventor
Dim ThisApplication As Inventor.Application
ThisApplication = Marshal.GetActiveObject("Inventor.Application")
addin = ThisApplication.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")
_iLogicVbAutomation = addin.Automation
_iLogicVbAutomation.RunExternalRule(ThisApplication.ActiveDocument, "Spec Reference List")

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report