Allowed characters in parameter name ?

Allowed characters in parameter name ?

Martin-Winkler-Consulting
Advisor Advisor
2,239 Views
5 Replies
Message 1 of 6

Allowed characters in parameter name ?

Martin-Winkler-Consulting
Advisor
Advisor

Hi,

i recognized in some parts and assemblies an unallowed character Hex 0x1F at the end of the prameter name.

In the fxManager it could not be seen ,but it is there. I have no idea in which context the character was added to the name. Perhaps by using copy/paste with notepad++. Because of this character iLogic rules do not work any more and other issues. It is not depending on wether the parameter name in the rule is used or not.

 

iLogic_Error.jpg

 

My idea is writing a tool that checks all parameter names for unallowed characters and deletes them.

 

For this reason i have some questions:

Is there an existing inventor api method that checks parameter names so that i can use it?

Which characters are allowed in parameter names?

Why is it possible that inventor do not detect this unallowed sign before? 

Martin Winkler
CAD Developer
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

0 Likes
2,240 Views
5 Replies
Replies (5)
Message 2 of 6

b_sharanraj
Advocate
Advocate

Hi @Martin-Winkler-Consulting

 

No Special Characters are allowed in Parameter Name.

 

Any Parameter Units also cannot be used as a Parameter Name.

 

Most Probably i use the combination of Alphabets & Underscore as Parameter name very rarely i use numbers (Parameter Name should not start with a Number).

 

Before adding a Parameter Name we can only check and remove the unallowed characters by below code

 

'Before Adding the Parameter from Notepad++
Param_Name = AlphaNumericOnly(Param_Name)

Function AlphaNumericOnly(strSource As String) As String
    Dim i As Integer
    Dim strResult As String

    For i = 1 To Len(strSource)
        Select Case Asc(Mid(strSource, i, 1))
            Case 95, 65 To 90:
                strResult = strResult & Mid(strSource, i, 1)
        End Select
    Next
    AlphaNumericOnly = strResult
End Function

Regards

B.Sharan Raj

Message 3 of 6

Martin-Winkler-Consulting
Advisor
Advisor

Hi B.Sharan Raj

 

i expected that inventor checks by itself wether a character in a parameter name is allowed or not. But it seems to be that it is possible to put unallowed characters in it. So a function like you posted should be part of inventor even when a parameter is created. For example when you try to use the sign "/" in a  parameter name there is an error message because it is the sign for dividing but if you use ":" inventor produce no error message.

I get the files from one of my clients who uses "normal" Inventor setup. In addition i have no idea how to add a tool into inventor that checks every time wether the user makes a right or wrong input in paramter names.

 

In this case it was however the charcter ascii 31 , unit seperator.

I wrote this evening a tool that eliminates this sign from all parameters. And if you are right that only Alphanummeric signs could or should be used i would optinally enlarge the tool to all other unallowed characters for future use.

 

Perhaps better improvment of the user entries is a case for the ideas section.

I am excited to hear about this from the Autodesk staff 😉

Martin Winkler
CAD Developer
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

0 Likes
Message 4 of 6

I'll come back to my post here. I am currently writing a tool in which user parameters are used and I would like to prevent the user from using an invalid parameter name. If I enter a user parameter into the parameters table in Inventor the validity is checked and if the name is not valid an error message appears. Is there a way to use this function from the API that checks the name in a VB.net programming?
If so, where can I find this function?

Martin Winkler
CAD Developer
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

0 Likes
Message 5 of 6

DRoam
Mentor
Mentor

Hi Martin, I don't think there's a built-in API method for checking parameter name validity. However, I wrote a couple of functions that will check if a parameter name is valid, or try to convert it to a valid name. See functions at the bottom of the post.

 

Here's a usage example of a program that uses the functions to test if input names are valid or can be made valid:

 

Sub Main()
Dim oRuleTitle As String = "Parameter Name Checker"
Dim oParamName As String = ""
Dim oInput As String = ""

Do
	oInput = InputBox("Parameter Name:", oRuleTitle, oInput)
	
	If oInput = "" Then
		'User hit "Cancel"
		Exit Do
	Else If ParamNameIsValid(oInput) = False Then
		Dim oConvertedName As String = MakeParamNameValid(oInput)
		
		If oConvertedName = "" Then
			MessageBox.Show("Could not convert name to a valid one. It may be a unit string or contain all invalid characters. Please try again.",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
		Else
			MessageBox.Show("Converted to valid name: """ & oConvertedName & """",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Information)
			oParamName = oConvertedName
		End If
	Else
		MessageBox.Show("Name is valid.",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Information)
		oParamName = oInput
	End If
Loop

End Sub

It works by trying to create parameters with the inputted names. However, it wraps this in a transaction and aborts, it, so the document isn't actually modified.

 

Hope this works for you.

 

 

Functions:

 

Function ParamNameIsValid(oName As String) As Boolean
	Dim oThisDoc As Inventor.PartDocument = ThisDoc.Document
	Dim oCompDef As Inventor.PartComponentDefinition = oThisDoc.ComponentDefinition
	
	Dim oTransaction As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oThisDoc,"Create dummy parameter")
	
	Try
		Dim oParam As Inventor.Parameter
		Try
			oParam = oCompDef.Parameters.Item(oName)
			'Parameter already exists, so name is valid.
			Return True
		Catch
			oParam = oCompDef.Parameters.UserParameters.AddByValue(oName,0,"ul")
			'Parameter created, so name is valid.
			oParam.Delete
			Return True
		End Try
	Catch
		'Parameter could not be created, so name is invalid.
		Return False
	Finally
		oTransaction.Abort
	End Try
End Function

Function MakeParamNameValid(oName As String) As String
	Dim oThisDoc As Inventor.PartDocument = ThisDoc.Document
	Dim oCompDef As Inventor.PartComponentDefinition = oThisDoc.ComponentDefinition
	
	Dim oTransaction As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oThisDoc,"Create dummy parameter")
	oParam = oCompDef.Parameters.UserParameters.AddByValue("dummyparam",0,"ul")
	
	Dim oNewName As String
	
	Dim i As Integer = 0
	For Each oChar As Char In oName
		i += 1
		Try
			Try
				Dim oParam2 As Inventor.Parameter = oCompDef.Parameters.Item(oChar)
				'Parameter named character exists, so character is valid.
				oNewName = oNewName & oChar
			Catch
				If i = 1 Then
					oParam.Name = oChar & oParam.Name
				Else
					oParam.Name = oParam.Name & oChar
				End If
				'Parameter renamed, so character is valid in current position.
				oNewName = oNewName & oChar
			End Try
		Catch
			'Character could not be used, so character is invalid. Replace with underscore, unless is first character.
			If i = 1 Then
				'Skip character and reset counter to zero.
				i = 0
			Else
				oNewName = oNewName & "_"
			End If
		End Try
	Next
	
	oTransaction.Abort
	
	If ParamNameIsValid(oNewName) Then
		Return oNewName
	Else
		Return ""
	End If
End Function
0 Likes
Message 6 of 6

Martin-Winkler-Consulting
Advisor
Advisor

@DRoam 

Thanks al lot, I will test it tomorrow.

Best Regards Martin

Martin Winkler
CAD Developer
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

0 Likes