Hi!
I have form created with Ilogic. The Form contains four radio buttons.
My goal is to change a custom property when user change radio button.
I've commented out the problem in line 76.
Does someone have any ideas how to do this?
Big shout out for the main code @WCrihfield
AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Class WinForm
Inherits System.Windows.Forms.Form
'Lista med olika tillverkningsmetoder
Private wordList As List(Of String) = New List(Of String) From {"Laserskuren", "Svarvad/Fräst", "3D-printad", "Inköpsdetalj"}
'Deklarerar Dictionary för att lagra Radio Buttons
Private radioButtons As Dictionary(Of String, RadioButton) = New Dictionary(Of String, RadioButton)
'Allmäna deklarationer för att använda i Subs & Functions
Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
Public Sub New() 'creates the new instance
'Formuläret
Dim oForm As System.Windows.Forms.Form = Me
With oForm
.FormBorderStyle = FormBorderStyle.FixedToolWindow
.StartPosition = FormStartPosition.CenterScreen
.Width = 300
.Height = 300
.TopMost = True
.Font = oLargerFont
.Text = "Windows Form"
.Name = "Windows Form"
.ShowInTaskbar = False
End With
'AddHandler oForm.FormClosing, AddressOf oForm_FormClosing
'Knapp
Dim oButton1 As New Button()
With oButton1
.Text = "TEST ME"
.Top = 25
.Left = 25
.Enabled = True
.AutoSize = True
End With
oForm.Controls.Add(oButton1)
AddHandler oButton1.Click, AddressOf oButton1_Click
'Skapa radio-knappar dynamiskt baserat på ordlistan
For Each word In wordList
Dim radioButton As New RadioButton()
radioButton.Text = word
radioButton.Top = oButton1.Bottom + 25 + wordList.IndexOf(word) * 30
radioButton.Left = 25
radioButton.AutoSize = True
radioButtons.Add(word, radioButton)
oForm.Controls.Add(radioButton)
AddHandler radioButton.CheckedChanged, AddressOf RadioButton_CheckedChanged
Next
End Sub
'This is the end of the main Sub that defines the Form
Private Sub oForm_FormClosing(ByVal oSender As Object, ByVal oFormCloseEvents As FormClosingEventArgs)
'oSender is a Form
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)
MsgBox("You just clicked the [" & oSender.Text & "] button.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
End Sub
Public Sub RadioButton_CheckedChanged(sender As Object, e As EventArgs)
Dim selectedRadioButton As RadioButton = DirectCast(sender, RadioButton)
'iProperties.Value("Custom", "ManufacturingMethod") = selectedRadioButton.Text
End Sub
' Method to initialize the state of radio buttons based on ManufacturingMethod iProperty
Public Sub InitializeRadioButtons(ManufacturingMethod As String)
' Set the initial state of the radio buttons based on the ManufacturingMethod iProperty
'Dim manufacturingMethod As String = iProperties.Value("Custom", "ManufacturingMethod")
If wordList.Contains(ManufacturingMethod) Then
radioButtons(ManufacturingMethod).Checked = True
End If
End Sub
End Class
'This is the code that actually shows/runs the Form
Public Class RunMyForm
Private Sub Main()
' Create an instance of WinForm and pass iLogicVb
Dim oMyForm As New WinForm()
'this visibly launches the form
oMyForm.Show
Dim ManufacturingMethod As String = iProperties.Value("Custom", "ManufacturingMethod")
' Initialize the state of radio buttons based on ManufacturingMethod iProperty
oMyForm.InitializeRadioButtons(ManufacturingMethod)
End Sub
End Class
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @tomas_wiklund. It looks to me like you simply can not use that "iProperties.Value()" snippet within any 'other' Class, other than in the 'original' Class, because that is where the 'iProperties' variable is declared. I moved your short Class just for running the form to the top of the code, then removed the Class & End Class lined from around it, so that it would adapt the 'original' Class that iLogic created for us in the background, named "ThisRule". That change enabled your 'iProperties.Value' line to work within that block of code. Then I changed your 'New' Sub routine, within the form Class, to accept an input parameter. This could be done multiple ways, but I chose to pass a Document object into it, because you appear to want to modify the custom iProperties of that Document. Try these modifications. The modified code is attached as a text file.
Wesley Crihfield
(Not an Autodesk Employee)
Elegant and working code!
With a little help from @Anonymous I got it working with code from this: https://forums.autodesk.com/t5/inventor-programming-ilogic/adding-custom-iproperties-to-idw-ussing-the-vb-net-inventor-api/td-p/6359859
Thanks both of you!
Can't find what you're looking for? Ask the community or share your knowledge.