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: 

Problem setting part name to form

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dialunau
344 Views, 2 Replies

Problem setting part name to form

dialunau
Advocate
Advocate

Hello everyone,

I'm trying to set the name of a selected part occurrence into a radiobutton of a form.

I'm using a shared variable to get the name from another rule. Everything works well, but in the end the name of the occurrence is missing in the form.

 

dialunau_1-1640119352837.png

Does anyone know how to get the string I want into the form?

 

My code looks like this:

 

 

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Public Sub Main()
	'//////// GET THE OCCURRENCE NAME ////////
	Dim oOcc As String = SharedVariable("Occurrence")
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm
	oForm.Show
End Sub
Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New
		oForm = Me
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 700
			.TopMost = True
			.Font = oLargerFont
			.Text = "Component Select"
			.Name = "Components"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "MODIFY"
			.Top = 25
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click
		
		Dim oOptions As New List(Of String)
		oOptions.AddRange({"Option 1","Option 2","Option 3"})

		Dim oGroupBox As GroupBox = New GroupBox()
		oGroupBox.Left = 25
		oGroupBox.Width = 150
		oGroupBox.Top = oButton1.Bottom + 20
		oGroupBox.Height = 100
		oGroupBox.Text = "Choose"
		oForm.Controls.Add(oGroupBox)
		
		'//////// RADIOBUTTON PARAMETERS ////////
		Dim oRadioButton1 As New RadioButton()
		oGroupBox.Controls.Add(oRadioButton1)
		oRadioButton1.Text = oOcc.Name
		oRadioButton1.Top = 20
		oRadioButton1.Left = 35
		oRadioButton1.AutoSize = True
	End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		MsgBox("Action triggered",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
End Class

 

 

0 Likes

Problem setting part name to form

Hello everyone,

I'm trying to set the name of a selected part occurrence into a radiobutton of a form.

I'm using a shared variable to get the name from another rule. Everything works well, but in the end the name of the occurrence is missing in the form.

 

dialunau_1-1640119352837.png

Does anyone know how to get the string I want into the form?

 

My code looks like this:

 

 

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Public Sub Main()
	'//////// GET THE OCCURRENCE NAME ////////
	Dim oOcc As String = SharedVariable("Occurrence")
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm
	oForm.Show
End Sub
Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New
		oForm = Me
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 700
			.TopMost = True
			.Font = oLargerFont
			.Text = "Component Select"
			.Name = "Components"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "MODIFY"
			.Top = 25
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click
		
		Dim oOptions As New List(Of String)
		oOptions.AddRange({"Option 1","Option 2","Option 3"})

		Dim oGroupBox As GroupBox = New GroupBox()
		oGroupBox.Left = 25
		oGroupBox.Width = 150
		oGroupBox.Top = oButton1.Bottom + 20
		oGroupBox.Height = 100
		oGroupBox.Text = "Choose"
		oForm.Controls.Add(oGroupBox)
		
		'//////// RADIOBUTTON PARAMETERS ////////
		Dim oRadioButton1 As New RadioButton()
		oGroupBox.Controls.Add(oRadioButton1)
		oRadioButton1.Text = oOcc.Name
		oRadioButton1.Top = 20
		oRadioButton1.Left = 35
		oRadioButton1.AutoSize = True
	End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		MsgBox("Action triggered",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
End Class

 

 

Labels (5)
2 REPLIES 2
Message 2 of 3
JelteDeJong
in reply to: dialunau

JelteDeJong
Mentor
Mentor
Accepted solution

try it this way:

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Sub Main()
	'//////// GET THE OCCURRENCE NAME ////////
	Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(
			SelectionFilterEnum.kAssemblyOccurrenceFilter, 
			"Select occurrence")
	Dim occName As String = occ.Name
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm(occName)
	oForm.Show
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New(occName As String)
		oForm = Me
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 700
			.TopMost = True
			.Font = oLargerFont
			.Text = "Component Select"
			.Name = "Components"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "MODIFY"
			.Top = 25
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click
		
		Dim oOptions As New List(Of String)
		oOptions.AddRange({"Option 1","Option 2","Option 3"})

		Dim oGroupBox As GroupBox = New GroupBox()
		oGroupBox.Left = 25
		oGroupBox.Width = 150
		oGroupBox.Top = oButton1.Bottom + 20
		oGroupBox.Height = 100
		oGroupBox.Text = "Choose"
		oForm.Controls.Add(oGroupBox)
		
		'//////// RADIOBUTTON PARAMETERS ////////
		Dim oRadioButton1 As New RadioButton()
		oGroupBox.Controls.Add(oRadioButton1)
		oRadioButton1.Text = occName
		oRadioButton1.Top = 20
		oRadioButton1.Left = 35
		oRadioButton1.AutoSize = True
	End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		MsgBox("Action triggered",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

try it this way:

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Sub Main()
	'//////// GET THE OCCURRENCE NAME ////////
	Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(
			SelectionFilterEnum.kAssemblyOccurrenceFilter, 
			"Select occurrence")
	Dim occName As String = occ.Name
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm(occName)
	oForm.Show
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New(occName As String)
		oForm = Me
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 700
			.TopMost = True
			.Font = oLargerFont
			.Text = "Component Select"
			.Name = "Components"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "MODIFY"
			.Top = 25
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click
		
		Dim oOptions As New List(Of String)
		oOptions.AddRange({"Option 1","Option 2","Option 3"})

		Dim oGroupBox As GroupBox = New GroupBox()
		oGroupBox.Left = 25
		oGroupBox.Width = 150
		oGroupBox.Top = oButton1.Bottom + 20
		oGroupBox.Height = 100
		oGroupBox.Text = "Choose"
		oForm.Controls.Add(oGroupBox)
		
		'//////// RADIOBUTTON PARAMETERS ////////
		Dim oRadioButton1 As New RadioButton()
		oGroupBox.Controls.Add(oRadioButton1)
		oRadioButton1.Text = occName
		oRadioButton1.Top = 20
		oRadioButton1.Left = 35
		oRadioButton1.AutoSize = True
	End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		MsgBox("Action triggered",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3
dialunau
in reply to: JelteDeJong

dialunau
Advocate
Advocate

That is exactly what I needed to work with the variable inside the class.

Thank you.

0 Likes

That is exactly what I needed to work with the variable inside the class.

Thank you.

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

Post to forums  

Autodesk Design & Make Report