Creating temporary User Parameters in a drawing for a multi-selection iLogic form

Creating temporary User Parameters in a drawing for a multi-selection iLogic form

rhenstenburg
Advocate Advocate
1,093 Views
4 Replies
Message 1 of 5

Creating temporary User Parameters in a drawing for a multi-selection iLogic form

rhenstenburg
Advocate
Advocate

I am trying to build a drawing note based on user selected options in iLogic.  I am using Inventor Pro 2020 (moving to 2022 soon).

 

Instead of asking a series of Yes/No questions (whether to include something in the note or not), I would like the put up a dialog with checkboxes so the user can go down the list in ONE dialog and select the items to include.

 

To achieve this, I thought that I would create temporary “storage” by using either iProperties or Parameters in the drawing, one Boolean for each option that I want to include in my note (iLogic form entities must be based on either a Parameter, Rule or iProperty, nothing else allowed that I can see).  By using Boolean iProperties or Parameters, I was looking to create an iLogic form with checkboxes to easily tick off what notes that are wanted.  Afterward, I append the desired notes together based on the responses and then clean up my mess by deleting the temporary things I created. 

 

I am successful at creating and deleting both User Parameters and Custom iProps in either a drawing or model file using iLogic. 

 

First issue:  I found that iLogic forms do NOT allow me to display Boolean Custom iProps with checkboxes on the form (only dropdown boxes – less convenient for my purposes because 2 clicks are required for a selection rather than just 1).  Therefore, I eliminated using iProps as my vehicle.

 

This quickly brings me to my second issue:  I can’t add Boolean User parameters in a drawing file to an iLogic form (they simply do not appear on the list).

 

As a workaround, I created an IPT with the User Parameter names I wanted and then created a Global iLogic form from the IPT.  When running my routine on a drawing, I get the form to display but when I click a checkbox I get an warning dialog box (attached) every time I click something.  Despite the error, I get the parameters to change as desired.  I have included an image of my form and a Message confirming what I selected.

 

As a test, I commented out my deletion of the parameters at the end of my routine so they are left defined.  I then brought up the Parameters dialog for the drawing interactively.  When I change the state of my iLogic created parameters, I get the same error as when running my routine.  Thus, it appears that my problem may be with my UserParameters declaration where I define “oUP” in my code).

 

I am attaching my testing routine.  Anyone know what I'm doing wrong?

Const Ext As Integer = 5

Dim oUP As UserParameters
'Following works for model files
'oUP = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters

'Following seems to work for drawings but throws an error when I change the User Parameter
oUP = ThisApplication.ActiveDocument.Parameters.UserParameters

Dim oTest As Parameter
Dim ErrFlg As Boolean = False
Dim i As Integer

'Test for the pre-existance of the user parameters and create if missing
For i = 0 To Ext
	On Error Resume Next
	oTest = oUP.Item("Question" & i)
	If Err.Number <> 0 Then
		'create parameter
		oUP.AddByValue("Question" & i, False, kBooleanUnits)
	Else
		ErrFlg = True
		Exit For
	End If
Next i

On Error GoTo 0

If ErrFlg Then
	MessageBox.Show("Pre-existing User Parameter Conflict", "ERROR",MessageBoxButtons.OK,MessageBoxIcon.Stop)
	Exit Sub
End If

iLogicForm.ShowGlobal("Select Notes", FormMode.Modal)

'Display my responses
Dim q(0 To Ext) As String
Dim mess As String = "Results:"

For i = 0 To Ext
	If oUP.Item("Question" & i).Value Then
		q(i) = "Yes"
	Else
		q(i) = "No"
	End If
	mess = mess & vbCrLf & "Question" & i & ": " & q(i)
Next i

MessageBox.Show(mess, "Responses")

' Cleanup
For i = 0 To Ext
	oUP.Item("Question" & i).Delete
Next i

 

Inventor Pro / Vault Basic
0 Likes
1,094 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @rhenstenburg 

 

I'm not sure I followed all of the issues, but something like this might work for you.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main
	Const Ext As Integer = 5

	Dim oUP As UserParameters
	oUP = ThisApplication.ActiveDocument.Parameters.UserParameters

	'Test for the pre-existance of the user parameters and create if missing
	For i = 1 To Ext
		Try 'try to get parameter
			oTest = oUP.Item("Question" & i)
		Catch
			'create parameter when not found
			oUP.AddByValue("Question" & i, False, kBooleanUnits)
		End Try
	Next

	'Display my responses
	For i = 1 To Ext
		If oUP.Item("Question" & i).Value = True Then
			oNoteText = NoteFunction(i)
			If oMsg = "" Then
				oMsg = oNoteText
			Else
				oMsg = oMsg & vbCrLf & oNoteText
			End If
		End If

	Next i

	If Not oMsg Is Nothing Then
		MessageBox.Show(oMsg, "Responses")
		Call CreateNote(oMsg)
	End If
End Sub

Sub CreateNote(oMsg As String)
	
	Dim oDoc As DrawingDocument
	oDoc = ThisApplication.ActiveDocument

	Dim oActiveSheet As Sheet
	oActiveSheet = oDoc.ActiveSheet

	Dim oGeneralNotes As GeneralNotes
	oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes
	
	oHeader = "General Notes:"
	Dim oGeneralNote As GeneralNote
	For Each oGeneralNote In oGeneralNotes
		If oGeneralNote.FormattedText.Contains(oHeader) Then
			oGeneralNote.Delete
		End If
	Next
	
	oGeneralNote = oGeneralNotes.AddFitted _
		(ThisApplication.TransientGeometry.CreatePoint2d(3, 8), oHeader & vbLf & oMsg)
End Sub

Function NoteFunction(i As Integer)

	Select Case i
		Case 1
			oText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
		Case 2
			oText = "Duis aute irure dolor In reprehenderit fugiat nulla pariatur."
		Case 3
			oText = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem"
		Case 4
			oText = "Nemo enim ipsam voluptatem quia voluptas sit aspernatur"
		Case 5
			oText = "Ut enim ad minima veniam, quis nostrum exercitationem"
	End Select

	Return oText
End Function

 

 

 

EESignature

Message 3 of 5

JelteDeJong
Mentor
Mentor

There is another solution that does not involve creating any parameter or iProperty and is far more flexible. But it's a bit more difficult. You can create your own custom form with iLogic. The example below shows you a rule that will create a form with checkboxes. When you click on "Ok" it will show dialogues with the results.

At the top of the rule, you can add questions. At the bottom, in the function oButton1_Click() you can your code that handles the output.

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Class WinForm
	Inherits System.Windows.Forms.Form

	Private _questions As List(Of String)
	Private _checkBoxes As List(Of CheckBox)	
	Public Sub New()
		_checkBoxes = New List(Of CheckBox)
		_questions = New List(Of String)
		' Add your questions here
		_questions.Add("Question 1")
		_questions.Add("Question 2")
		
		With Me
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = _questions.Count * 20 + 100
			.TopMost = True
			.Font = New Font("Arial",10)
			.Text = "Question Form"
			.ShowInTaskbar = False
		End With
		Dim i = 0
		For Each question As String In _questions
			AddCheckbox(question, i * 20)
			i = i + 1
		Next
		Dim oButton1 As New Button()
		With oButton1			
			.Text = "Ok"
			.Top = Me.Height - 75
			.Left = Me.Width - 130
			.Width = 100
			.Height = 25
			.Enabled = True
			.AutoSize = False
		End With
		Me.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click		
	End Sub
	
	Private Sub AddCheckbox(text, i)
		Dim oCheckBox As New CheckBox()
		With oCheckBox
			.Text = text
			.Top =  10 + i
			.Left = 10
			.AutoSize = True			
		End With
		Me.Controls.Add(oCheckBox)	
		_checkBoxes.Add(oCheckBox)
	End Sub	
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
	
		For Each checkBox As CheckBox In _checkBoxes
			MsgBox(CheckBox.Text & " = " & CheckBox.checked)
		Next
		
		' Your code for can go here....		
		
		Me.Close()
	End Sub
End Class


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

More information about creating a form with iLogic can be found on this page

 

 

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 4 of 5

rhenstenburg
Advocate
Advocate

Thanks @Curtis_Waguespack, I like your usage of Try and Catch but I have the actual note generation and placing on the drawing already figured out.  For testing, I boiled my routine down so I could examine just the creation of the parameters, displaying the iLogic Form then deleting the parameters to clean things up (not required but nice).  This is what I shared.

 

The hitch came when trying to change the drawing UserParameters through the form or even from Manage>Parameters.  This problem was the same for my routine and for yours (I adding  a call to your routine to display my global form). 

 

BOTTOM LINE: I tested on a fresh drawing and both yours and my routines worked flawlessly.  My error was that I was testing on the same drawing over and over and I must have bollixed something up during testing.

 

My apologies for wasting your time @Curtis_Waguespack (but I will use the Try and Catch you illustrated in the future).

Inventor Pro / Vault Basic
Message 5 of 5

rhenstenburg
Advocate
Advocate

Saw @JelteDeJong solution which came as I was testing and creating my response above.  Very elegant but well out of my league.  I will save this for when I become more proficient. 

 

I appreciate and "Liked" the solutions from @Curtis_Waguespack and @JelteDeJong but it was my own clumsiness that led to my issue.

Inventor Pro / Vault Basic