Change iProperties using form

Change iProperties using form

dialunau
Advocate Advocate
551 Views
5 Replies
Message 1 of 6

Change iProperties using form

dialunau
Advocate
Advocate

Hello,

I'm trying to change the iProperties of some parts inside a textbox in a form. I'm using a class to define my form, but it seems I cannot use the iProperties.Value function inside the event handler for clicking a button. I'm getting the following error: 
Reference to a non-shared member requires an object reference.

 

My code looks like this:

 

 

Public Sub Main()
	Dim oDrawDoc As DrawingDocument = ThisDoc.Document
	Dim oName As String = "MyPart.ipt"
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm(iLogicVb.Automation, oDrawDoc)
	oForm.Show
	oDrawDoc.Update
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public Property oDrawDocint As DrawingDocument
	Public Property oTextBox As New System.Windows.Forms.TextBox
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New(ByVal Iinf As IiLogicAutomation,oDrawDoc As DrawingDocument) 
		oForm = Me
		myIinf = Iinf
		oDrawDocint = oDrawDoc
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 250
			.Height = 300
			.Font = oLargerFont
		End With
		
		'//////// CREATES THE BUTTON ////////
		Dim oButton1 As New Button()
		With oButton1
			.Text = "ACTION"
			.Top = ((oForm.Bottom - oForm.Top)/2) - (oButton1.Bottom - oButton1.Top)
			.Left = (oForm.Width/2) - oButton1.Width +20
			.Enabled = True
			.AutoSize = True
		End With
		
		Dim oLbl As New Label
		With oLbl
			.Text = "MyPart"
		    .Top = 20
		    .Left = 20
		    .Height = 40
		End With
		
		With oTextBox
			.Text = "Part No."
			.Top = 20
			.Left = 120
			.Width = 100
			.Height = 25
		End With
		
		oLbl = oForm.Controls.Add(oLbl)
		oForm.Controls.Add(oTextBox)
		oForm.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)
		iProperties.Value(oName, "Project", "Part Number") = oTextBox.Text
	End Sub
End Class

 

 


Any suggestions of how to modify the iProperties when I click the button?

0 Likes
Accepted solutions (1)
552 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @dialunau.  It looks like this is a similar case to this one.  I believe you can simply add an extra Public declaration line near the start of your WinForm Class block, which will introduce that 'iProperties' term/interface object.

Try adding this line:

Public iProperties As Autodesk.iLogic.Interfaces.IiProperties

...right after your 'Inherits' line, just inside of your 'WinForm' Class block.  That should allow your iProperties.Value() function below to recognize that starter term.  That term is usually defined under the default 'ThisRule' Class, so it just needs to be recreated within this class.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

dialunau
Advocate
Advocate

Thanks for the help, I was able to execute the iProperties.Value command by adding that line, but now I'm getting another error that doesn't allow me to change the iProperty value:

dialunau_0-1658259006106.png


In the line 

iProperties.Value(oName, "Project", "Part Number") = oTextBox.Text

the variable oName has the part name "MyPart.ipt"

Does this have something to do with the fact that I'm running this rule from a DWG file?

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

There is another approach. You can get the information from the Form and use it in your "Main" function. something like this:

Public Sub Main()
	Dim oDrawDoc As DrawingDocument = ThisDoc.Document
	Dim oName As String = "MyPart.ipt"
	
	'//////// RUN THE FORM ////////
	Dim oForm As New WinForm(iLogicVb.Automation, oDrawDoc)
	oForm.ShowDialog()
	
	iProperties.Value(oName, "Project", "Part Number") = oForm.NewPartNumber
	
	oDrawDoc.Update
End Sub

Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public Property oDrawDocint As DrawingDocument
	Public Property oTextBox As New System.Windows.Forms.TextBox
	
	'//////// CREATE NEW INSTANCE ////////
	Public Sub New(ByVal Iinf As IiLogicAutomation,oDrawDoc As DrawingDocument) 
		oForm = Me
		myIinf = Iinf
		oDrawDocint = oDrawDoc
		
		'//////// PARAMETERS FOR THE FORM ////////
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			'.StartPosition = FormStartPosition.CenterScreen
			.Width = 250
			.Height = 300
			.Font = oLargerFont
		End With
		
		'//////// CREATES THE BUTTON ////////
		Dim oButton1 As New System.Windows.Forms.Button()
		With oButton1
			.Text = "ACTION"
			.Top = ((oForm.Bottom - oForm.Top)/2) - (oButton1.Bottom - oButton1.Top)
			.Left = (oForm.Width/2) - oButton1.Width +20
			.Enabled = True
			.AutoSize = True
		End With
		
		Dim oLbl As New System.Windows.Forms.Label
		With oLbl
			.Text = "MyPart"
		    .Top = 20
		    .Left = 20
		    .Height = 40
		End With
		
		With oTextBox
			.Text = "Part No."
			.Top = 20
			.Left = 120
			.Width = 100
			.Height = 25
		End With
		
		oLbl = oForm.Controls.Add(oLbl)
		oForm.Controls.Add(oTextBox)
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click
	End Sub
  
  	Public Property NewPartNumber As String
	  
	Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		NewPartNumber = oTextBox.Text
		Me.Close()
		' iProperties.Value(oName, "Project", "Part Number") = oTextBox.Text
	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 5 of 6

WCrihfield
Mentor
Mentor

Hi @dialunau.  I am not sure if it would have anything to do with you working with a DWG file type or not, because I personally do not work with DWG files with Inventor.  But I do know that when using the iProperties.Value() iLogic snippet, it is limited to only being able to access the documents within the 'AllReferencedDocuments' scope of the 'active' document.  It can not access another 'parallel' document that is not being referenced by the active document.  And yes, when specifying a document name for it to access, it generally wants that document's file name, with file extension, but without file path, as you seem to have it already.  But in the code that you posted, you defined the oName variable up in your Sub Main block of code, outside of the 'WinForm' Class block of code, but then you have your iProperties.Value() line down within a Sub routine block, within your 'WinForm' Class, so it likely did not recognize what that oName variable was at that point.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

dialunau
Advocate
Advocate

I don't know why this line and trying to rewrite the iProperties inside the class was not working

Public iProperties As Autodesk.iLogic.Interfaces.IiProperties

 

But reading the class property from the Main function solved the problem. Now I can change those iProperties.

Thank you so much.

0 Likes