Conversion from string "" to type 'Double' is not valid. (I am Not fully understanding I logic yet)

Conversion from string "" to type 'Double' is not valid. (I am Not fully understanding I logic yet)

corey_danielson
Advocate Advocate
1,135 Views
9 Replies
Message 1 of 10

Conversion from string "" to type 'Double' is not valid. (I am Not fully understanding I logic yet)

corey_danielson
Advocate
Advocate
If Parameter("DESCRIPTION1") = DESCRIPTION1 Then 
	iProperties.Value("Project", "Description") = DESCRIPTION1
	iProperties.Value("Project", "Part Number") = PART_NUMBER1
End If

trigger = iTrigger0

'===================================================================

oLength = BHHDS_LENGTH
	If oLength.Contains("/") Then 
		sArray = Split(BHHDS_LENGTH, " ") 
		Dim Int As Integer = sArray(0) 
		Dim Fraction As String = sArray(1) 
		sFractionArray = Split(Fraction, "/") 
		Dim Dbl As Double = sFractionArray(0) / sFractionArray(1)
		oLength = Int + Dbl
	End If

'===================================================================

If SCREW_DIA = .25 Then
	HEAD_DIA = .4375
	HEAD_HEIGHT = .132
    HEX_WIDTH = .15625
	HEX_DEPTH = .125
	FLAT_TOP = .188
	FLAT_EDGE = .015625
	LENGTH = BHHDS_LENGTH
End If

'=======================================================================

If SCREW_DIA = .375 Then
    SCREW_DIA = .375
	HEAD_DIA = .656
	HEAD_HEIGHT = .199
    HEX_WIDTH = .21875
	HEX_DEPTH = .125
	FLAT_TOP = .25
	FLAT_EDGE = .015625
	LENGTH = BHHDS_LENGTH
End If

'===============================================================

If SCREW_DIA = .5 Then
	HEAD_DIA = .875
	HEAD_HEIGHT = .265
    HEX_WIDTH = .3125
	HEX_DEPTH = .125
	FLAT_TOP = .375
	FLAT_EDGE = .0625
	LENGTH = BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/4-20" Then
	SCREW_DIA = .25
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/4-20 UNC"
	PART_NUMBER1 = "DESCRIPTION1 & "" & BHHDS_LENGTH"
End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/4-28" Then
	SCREW_DIA = .25
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/4-28 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 3/8-16" Then
	SCREW_DIA = .375
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "3/8-16 UNC"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 3/8-24" Then
	SCREW_DIA = .375
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "3/8-24 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-13" Then
	SCREW_DIA = .5
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/2-13 UNC"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-13" Then
	If BHHDS_LENGTH < .5 Then
	MessageBox.Show("BH HEX DRIVE SCREW 1/2-13 length must be .5 or greater. Changing to .5", "Paramter Police")
	BHHDS_LENGTH = .5
End If
End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-20" Then
	SCREW_DIA = .5
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/2-20 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-20" Then
	If BHHDS_LENGTH < .5 Then
	MessageBox.Show("BH HEX DRIVE SCREW 1/2-13 length must be .5 or greater. Changing to .5", "Paramter Police")
	BHHDS_LENGTH = .5
End If
End If

'====================================================================

iLogicVb.UpdateWhenDone = True

InventorVb.DocumentUpdate()
0 Likes
Accepted solutions (4)
1,136 Views
9 Replies
Replies (9)
Message 2 of 10

corey_danielson
Advocate
Advocate

I was trying to set the length restrictions. 1/2 was going to be a minimum length of 1/2" long.  I get the same message if I comment out those lines.

 

If Parameter("DESCRIPTION1") = DESCRIPTION1 Then 
	iProperties.Value("Project", "Description") = DESCRIPTION1
	iProperties.Value("Project", "Part Number") = PART_NUMBER1
End If

'trigger = iTrigger0

'===================================================================

'oLength = BHHDS_LENGTH
'	If oLength.Contains("/") Then 
'		sArray = Split(BHHDS_LENGTH, " ") 
'		Dim Int As Integer = sArray(0) 
'		Dim Fraction As String = sArray(1) 
'		sFractionArray = Split(Fraction, "/") 
'		Dim Dbl As Double = sFractionArray(0) / sFractionArray(1)
'		oLength = Int + Dbl
'	End If

'===================================================================

If SCREW_DIA = .25 Then
	HEAD_DIA = .4375
	HEAD_HEIGHT = .132
    HEX_WIDTH = .15625
	HEX_DEPTH = .125
	FLAT_TOP = .188
	FLAT_EDGE = .015625
	LENGTH = BHHDS_LENGTH
End If

'=======================================================================

If SCREW_DIA = .375 Then
    SCREW_DIA = .375
	HEAD_DIA = .656
	HEAD_HEIGHT = .199
    HEX_WIDTH = .21875
	HEX_DEPTH = .125
	FLAT_TOP = .25
	FLAT_EDGE = .015625
	LENGTH = BHHDS_LENGTH
End If

'===============================================================

If SCREW_DIA = .5 Then
	HEAD_DIA = .875
	HEAD_HEIGHT = .265
    HEX_WIDTH = .3125
	HEX_DEPTH = .125
	FLAT_TOP = .375
	FLAT_EDGE = .0625
	LENGTH = BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/4-20" Then
	SCREW_DIA = .25
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/4-20 UNC"
	PART_NUMBER1 = "DESCRIPTION1 & "" & BHHDS_LENGTH"
End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/4-28" Then
	SCREW_DIA = .25
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/4-28 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 3/8-16" Then
	SCREW_DIA = .375
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "3/8-16 UNC"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 3/8-24" Then
	SCREW_DIA = .375
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "3/8-24 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'===============================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-13" Then
	SCREW_DIA = .5
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/2-13 UNC"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-13" Then
'	If BHHDS_LENGTH < 1/2 Then
'	MessageBox.Show("BH HEX DRIVE SCREW 1/2-13 length must be 1/2 or greater. Changing to 1/2", "Paramter Police")
'	BHHDS_LENGTH = 1/2
'End If
'End If

'=====================================================================

If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-20" Then
	SCREW_DIA = .5
    Feature.IsActive("Thread1") = True
    Feature.ThreadDesignation("Thread1") = "1/2-20 UNF"
	PART_NUMBER1 = DESCRIPTION1 & "" & BHHDS_LENGTH
End If

'If DESCRIPTION1 = "BH HEX DRIVE SCREW 1/2-20" Then
'	If BHHDS_LENGTH < 1/2 Then
'	MessageBox.Show("BH HEX DRIVE SCREW 1/2-13 length must be 1/2 or greater. Changing to 1/2", "Paramter Police")
'	BHHDS_LENGTH = 1/2
'End If
'End If

'====================================================================

iLogicVb.UpdateWhenDone = True

InventorVb.DocumentUpdate()
0 Likes
Message 3 of 10

WCrihfield
Mentor
Mentor
Accepted solution

What type of units does the 'BHHDS_LENGTH' parameter use (Numeric, like Integer or Double, or Text units like String).  Also, what type of units does the 'LENGTH' parameter use?  Since you are setting the value of one to the value of the other, their units must be the same type (both numerical, or both text, or both Boolean).  When you want to include the value of a parameter within a String type value, but that parameter is numerical, you should usually include the .ToString function at the end of that parameter's name, to convert the Integer or Double to String, so it can be concatenated together with other String values into one larger String value.  It is not always required in iLogic rules, because they tend to make some things 'easier' for inexperienced programmers, but it is usually a good idea.  Especially if the Double type value is the first element being combined (concatenated) with other String type values.

 

In the following line of code: (which I know you have commented out)

 

sArray = Split(BHHDS_LENGTH, " ") 

 

...that 'Split' function is expecting a String as input, not an unquoted, blue parameter name that represents a Double type value.   It will not be able to convert that Double data type to the String data type that it is expecting.  You might be able to change it like this:

 

sArray = Split(BHHDS_LENGTH.ToString, " ") 

 

...but I am not really sure what you are trying to do there.

 

Also, are the parameters named 'DESCRIPTION1' and 'PART_NUMBER1' both set to text type units, or is one/both set to numerical units.  If either is not set to text units, that may be causing problems.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 10

corey_danielson
Advocate
Advocate

The length parameter is in fractions, that is a multi-line parameter.  Then I just created a user parameter called BHHDS_LENGTH. (Button Head Hex Drive Screw) I was wanting to set BHHDS_LENGTH equal to LENGTH. I was trying to follow another example I had seen. I might have it working now, I did use your suggestion. When I changed it to - ToString, it seems to work. Thank you very much.  I do have one more question, I have created my form, When I Select  1/2-13 and select length of 1, then hit apply, the threads update but the head is too small. If I select 1/2-20, hit apply, it updates completely. then if i select 1/2-13 again, hit apply, it just changes the treads to coarse, but still looks right. (Same thing with the 1/4 and 3/8) 

0 Likes
Message 5 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Fractions is not the type of units of a parameter.  When you open your Parameters dialog box, there is a column labeled "Unit/Type", and within that column is where the true units of the parameters is set.  If that parameter is set to "in", then that means it is Inches, which will result in that parameter having a numerical type value.  If the units column has "Text" as the units, then the value of that parameter will be a String, instead of a numerical type, even if the String contains numbers.  You normally can not combine numerical pieces of data (such as an Integer or a Double) together with a String type piece of data, to create a new, single value of either data Type, even if the String contains numbers, because those individual pieces of data are different types, and would need to be converted before being combined.  Different numerical types will usually mix together just fine.

WCrihfield_0-1728930723805.png

So, in your last reply, when you said "The length parameter is in fractions", I still do not know if it is numerical or text units.  There is no such thing as a multi-line parameter, so you must mean that it us a multi-value parameter.  Those still only have one current value, but they just have a list of other possible values readily available that we can choose one from, to make changing its actual value easier.  We can have parameters with either text units or numerical units, that are multi-value, so that does not really indicate units either.  If the length parameter is set to inches units, which will result in the parameter having a numeric value type, but the other parameter has text type units, which will result in a String type value, then those two value types will not be compatible with each other.  So one or the other will need to be converted before combining them together, depending on the Type of value you need the result to be.  Both the 'Part Number' and the 'Description' iProperties have a String type value.  So, if combining multiple pieces of different types of data together to create its new value, you will want to make sure the resulting new, single value is a String, not an Integer or Double.  It can be complicated to know which type of value an iProperty is supposed to have, because the Property.Value just indicates 'Variant' or 'Object' type, instead of something more specific.  Both the 'Variant' and the 'Object' are both sort of like wildcard types, or similar to saying it has no specific type, or any type.

 

Usually a fraction is represented by text (or a String), instead of a true numerical value, unless it is being used in a mathematical equation.  When looking in the Parameters dialog, the Equation column can contain mathematical equations, &/or the names of other existing parameters in that model.  If you want to see the true, current value of a parameter, look in the 'Nominal Value' column, or the 'Model Value' column.  If the parameter is set to numerical units, then both columns will contain values, but they will not contain values if the parameter is set to text type units or Boolean type units (True/False ; Yes/No).

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 10

corey_danielson
Advocate
Advocate

Sorry, I said that wrong. It is a multi-value list. I do not get any error messages anymore, but when I pick coarse thread from the form. only part of it updates, until I pick the fine thread, then apply, it all updates. I included the part if you don't mind taking a look.

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Hi @corey_danielson.  I know you said that you are no longer getting errors, but I do see more lines of code that are likely problematic, and would likely be causing the same type of error.

The following line of code appears to work, only because iLogic is allowing it to work:

BHHDS_LENGTH = LENGTH

The 'BHHDS_LENGTH' parameter has text units (String).

The 'LENGTH' parameter has inches units (numerical).

In this situation, the iLogic add-in is automatically converting the Double value type of the 'LENGTH' parameter to String data type, so it can be set as the value of the 'BHHDS_LENGTH' parameter.

 

However, this reversed line of code (which appears several times in your rule) will not work, and will throw that original error.

LENGTH = BHHDS_LENGTH

Because the item on the left side of an equals sign is always 'receiving' the value from the item on the right side of an equals sign.  And in this case, a parameter with inches units (numerical) will not always be able to receive a value that is a String.  If the String contains only a pure number, without any text or special characters, then it might work.  But if the String contains the fraction character ("/"), the inches character ("), units abbreviation letters ("in"), or anything like that, it can not directly convert that String into a Double, and will throw an error like that.

 

You need to understand the difference between the 'Value' of a Parameter, and the 'Expression' of a Parameter.

The Expression is always a String, no matter what type of units the parameter is set to, and is where we put mathematical equations, and things like fractions, or names of other parameters.  The Value of a parameter is the result of evaluating the mathematical Expression, while interpreting any numerical values within the equation as representing the parameter's units, unless specified otherwise within the equation.  The parameter's Value may look very different from what we see in the Expression, because it is pretty much always in natural decimal form.

 

Sometimes these seemingly simpler ways of accessing parameters will allow us to directly specify an 'Expression' instead of a regular 'Value', but if so, it must be in proper format.

 

It is difficult to explain it all here, because it seems like I would have to type up a whole book in my response, but there are several ways to access parameters by code, and each way functions differently in multiple ways.  Using these blue, unquoted parameter names within an 'internal' iLogic rule (a rule that is saved within an Inventor document, not an external rule), is only one of those ways, and is often considered the simplest way, due to it requiring the least code.  That technique (like all others) has its pros and cons though.  One of its cons is this limitation mentioned above, where it is throwing errors because it can not convert some String values directly into Double type values.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10

corey_danielson
Advocate
Advocate

Thank you very much for your explanations. I appreciate it. I am going to look at my code one more time after reading your notes. Thanks again for taking time to explain.

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor
Accepted solution

One more thing you should probably add near the end of your code, but before the document update line of code, is the following line of code:

RuleParametersOutput()

Again, a little difficult to explain, but this line of code runs a 'hidden' Sub routine that makes sure the values of those blue, unquoted parameter names in your rule, get written back into the model document, after any changes have been made to them.  This line if code is pretty much only useful within 'internal' rules (not in external rules), where you are changing the values of those blue, unquoted parameter names.  There is a whole bunch of code behind the scenes supporting the recognition of those names, turning them blue, and making them work the way they appear to be working, to make it easier for us to automate Inventor.  When using other ways of accessing parameters, there are other similar lines of code specifically for updating the model after changes to parameters within the code.  Without that extra little line of code in there, it can sometimes seem like you may need to run a rule twice to see the intended results you expected from a single run of the rule.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 10

corey_danielson
Advocate
Advocate

Everything works just like it should now, Form is set up and working. Thank you very much for the help

0 Likes