<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Run Code in the background without exiting a form in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11324370#M34926</link>
    <description>&lt;P&gt;I tried the backgroungworker but it won't work in this scenario. I'll explain more detail.&lt;BR /&gt;I want my code to change an iProperty when I click a button, I cannot change the iProperties inside the form (I tried using IiProperties but it gives errors), that is why I must change them from the main function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that I can only run code in the main function before or after running the form, but I want that iProperty to change whenever I click the button, not after the form is closed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System.Windows.Forms
Public Sub Main()
	Dim oForm As New WinForm()
	oForm.ShowDialog
'	oForm.Show(vbModeless)
	
	' I want to change this iProperty when I click the button
	iProperties.Value("Y.ipt", "Project", "Part Number") = "2"
	ThisDoc.Document.Update
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	
	Public Sub New() 
		oForm = Me
		
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 400
			.Text = "MYFORM"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "Change iProperty"
			.Top = oForm.Bottom - 80
			.Left = (oForm.Width/2) - oButton1.Width
			.Enabled = True
			.AutoSize = True
		End With
		Me.Controls.Add(oButton1)
	
		AddHandler oButton1.Click, AddressOf oButton1_Click
	End Sub
  
	Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		'When clicking the button, I want the program to run the iProperties change in the main function
	End Sub
End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;I've been trying various methods to access the main function without exiting the form, but no luck so far.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 19:56:47 GMT</pubDate>
    <dc:creator>dialunau</dc:creator>
    <dc:date>2022-07-27T19:56:47Z</dc:date>
    <item>
      <title>Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11311833#M34920</link>
      <description>&lt;P&gt;&lt;FONT&gt;Hello&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT&gt;I have a form and I want to run the code for (MsgBox) whenever I click the button in my form (so I will see 2 messages whenever I click the button).&lt;BR /&gt;The problem is that it will show only after I close the form. How can I do this?&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT&gt;My code looks like this:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Public Sub Main()
	Dim oForm As New WinForm(iLogicVb.Automation)
	oForm.ShowDialog()
	
	MsgBox("TASK 2")
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	
	Public Sub New(ByVal Iinf As IiLogicAutomation) 
		oForm = Me
		
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 400
			.Text = "MYFORM"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "CLICK ME!"
			.Top = oForm.Bottom - 80
			.Left = (oForm.Width/2) - oButton1.Width
			.Enabled = True
			.AutoSize = True
		End With
		Me.Controls.Add(oButton1)
	
		AddHandler oButton1.Click, AddressOf oButton1_Click
	End Sub
  
	Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		MsgBox("TASK 1")
	End Sub
End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 16:10:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11311833#M34920</guid>
      <dc:creator>dialunau</dc:creator>
      <dc:date>2022-07-21T16:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11312552#M34921</link>
      <description>&lt;P&gt;use oForm.Show() in stead of oForm.ShowDialog()&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;Public&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;()
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oForm&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;New&lt;/SPAN&gt; &lt;SPAN&gt;WinForm&lt;/SPAN&gt;(&lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;Automation&lt;/SPAN&gt;)
	&lt;SPAN&gt;oForm&lt;/SPAN&gt;.&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Show&lt;/FONT&gt;&lt;/STRONG&gt;()
	
	&lt;SPAN&gt;MsgBox&lt;/SPAN&gt;(&lt;SPAN&gt;"TASK 2"&lt;/SPAN&gt;)
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 21:14:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11312552#M34921</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-07-21T21:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11313118#M34922</link>
      <description>Modal vs Modeless forms!</description>
      <pubDate>Fri, 22 Jul 2022 06:26:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11313118#M34922</guid>
      <dc:creator>bradeneuropeArthur</dc:creator>
      <dc:date>2022-07-22T06:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11314274#M34923</link>
      <description>&lt;P&gt;,&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 14:33:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11314274#M34923</guid>
      <dc:creator>dlunaEVTVX</dc:creator>
      <dc:date>2022-07-22T14:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11314276#M34924</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I'm sorry I didn't explain properly. I want my code to show the 2 MsgBoxes whenever I click the button, so the form calls the main function to execute that code when the button is clicked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried with&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;oForm.Show&lt;/STRONG&gt;, but it causes the code to run before starting the form. On the other hand,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;oForm.Show(vbModeless)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;causes the second message to show after closing the form, so none of these attempts gave me the desired result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I call a portion of the main function from the "oButton_click" event inside the class?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 14:34:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11314276#M34924</guid>
      <dc:creator>dialunau</dc:creator>
      <dc:date>2022-07-22T14:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11317423#M34925</link>
      <description>&lt;P&gt;The easiest way for execution of background task is &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=netframework-4.8" target="_blank" rel="noopener"&gt;BackgroundWorker&lt;/A&gt;. There are two samples how to use them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 06:40:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11317423#M34925</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2022-07-25T06:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11324370#M34926</link>
      <description>&lt;P&gt;I tried the backgroungworker but it won't work in this scenario. I'll explain more detail.&lt;BR /&gt;I want my code to change an iProperty when I click a button, I cannot change the iProperties inside the form (I tried using IiProperties but it gives errors), that is why I must change them from the main function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that I can only run code in the main function before or after running the form, but I want that iProperty to change whenever I click the button, not after the form is closed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System.Windows.Forms
Public Sub Main()
	Dim oForm As New WinForm()
	oForm.ShowDialog
'	oForm.Show(vbModeless)
	
	' I want to change this iProperty when I click the button
	iProperties.Value("Y.ipt", "Project", "Part Number") = "2"
	ThisDoc.Document.Update
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	
	Public Sub New() 
		oForm = Me
		
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 400
			.Text = "MYFORM"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "Change iProperty"
			.Top = oForm.Bottom - 80
			.Left = (oForm.Width/2) - oButton1.Width
			.Enabled = True
			.AutoSize = True
		End With
		Me.Controls.Add(oButton1)
	
		AddHandler oButton1.Click, AddressOf oButton1_Click
	End Sub
  
	Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		'When clicking the button, I want the program to run the iProperties change in the main function
	End Sub
End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;I've been trying various methods to access the main function without exiting the form, but no luck so far.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 19:56:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11324370#M34926</guid>
      <dc:creator>dialunau</dc:creator>
      <dc:date>2022-07-27T19:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11324431#M34927</link>
      <description>&lt;P&gt;you can change iProperies from the form. The only thing is that you cant use the iLogic API. You need to use the Inventor API. Try this:&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Imports System.Windows.Forms
Public Sub Main()

	Dim partDocument As PartDocument = ThisDoc.Document

	Dim oForm As New WinForm(partDocument)
	oForm.ShowDialog()



End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form

	Private _doc As PartDocument

	Public Sub New(doc As PartDocument)

		_doc = doc

		Dim oForm = Me
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 400
			.Text = "MYFORM"
			.ShowInTaskbar = False
		End With

		Dim oButton1 As New Button()
		With oButton1
			.Text = "CLICK ME!"
			.Top = oForm.Bottom - 80
			.Left = (oForm.Width / 2) - oButton1.Width
			.Enabled = True
			.AutoSize = True
		End With
		Me.Controls.Add(oButton1)

		AddHandler oButton1.Click, AddressOf oButton1_Click
	End Sub

	Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' for more info check https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html
		Dim propertySet As PropertySet = _doc.PropertySets.Item("Design Tracking Properties")
		Dim myProperty As [Property] = propertySet.Item("Description")
		myProperty.Value = "I have been updated from the form!"
		
		msgbox("Description property has been updated!")
	End Sub
End Class&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Jul 2022 20:30:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11324431#M34927</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-07-27T20:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Run Code in the background without exiting a form</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11342344#M34928</link>
      <description>&lt;P&gt;That worked perfectly.&lt;BR /&gt;modifying the property sets instead of using the &lt;STRONG&gt;iproperties.value&lt;/STRONG&gt; method helped me modify them without exiting the class.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 14:25:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-code-in-the-background-without-exiting-a-form/m-p/11342344#M34928</guid>
      <dc:creator>dialunau</dc:creator>
      <dc:date>2022-08-05T14:25:05Z</dc:date>
    </item>
  </channel>
</rss>

