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: 

Convert string to variable

2 REPLIES 2
Reply
Message 1 of 3
gert-leonvanlier
466 Views, 2 Replies

Convert string to variable

I created the following constant in iLogic to later pass values on to Excel:

Const COLUMN_InstanceID As String = "A"
Const COLUMN_InstanceName As String = "B"
Const COLUMN_ProductType As String = "C"
Const COLUMN_Description As String = "D"
Const COLUMN_DesignType As String = "E"
Const COLUMN_GroupNumber As String = "F"
Const COLUMN_SerialNumber As String = "G"
Const COLUMN_Area As String = "H"
Const COLUMN_Zone As String = "I"
Const COLUMN_SequenceID As String = "J"
Const COLUMN_CustomerID As String = "K"
Const COLUMN_Phase As String = "L"
Const COLUMN_UsableWidth As String = "M"

 

Now I have the following code to lookup a parameter value that then has to be put in a specific cell in the Excel file:

i = 0
	For Each oString In NumericList
		For Each oPartUserParam As UserParameter In oPartUserParams
			If oPartUserParam.Name = NumericList.Item(i)	
				'parameter found
				FeedValue = oPartUserParam.Value
				If oPartUserParam.Units = "degree" Then
					FeedValue = Round(UnitConversion(FeedValue, oPartUserParam), 2)
				Else
					FeedValue = Round(UnitConversion(FeedValue, oPartUserParam), 0)
				End If
				GoTo FoundNumeric
			End If
		Next
	FoundNumeric :
		SetValueInExcel("COLUMN_" + NumericList.Item(i), Row.ToString, FeedValue)
		
		'reset FeedValue
		FeedValue = "N/A"

	i = i + 1			
	Next

 

The problem I am having is that

"COLUMN_" + NumericList.Item(i)

results in (for example) COLUMN_UsableWidth2 instead of just "M". In short: I need the constant and not the entire string. Is there a way to convert a string to a variable?

 

2 REPLIES 2
Message 2 of 3

Here is few quick exemple on how I manage parameters value.

Maybe this helps you out?

 

oAsmCompDefSub1.Parameters.Item("length").Expression = vertical_baffle_length

 

oOccDefinition = oOccurrence.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition
oValue = oOccDefinition.Parameters.Item("cover_joint").Expression

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 3

There were a lot of undefined variables I had to attempt to 'fill in the blanks' for, so I could attempt to understand your code and build a working rule to test with.  Basically, I created a new Function that accepts a String as Input (the column title) and returns a String (the column letter).  It contains a Select Case block of code that cross-references which column names go with which column letters.  Of course, since I filled in so many blanks from my own imagination, rather than working with a complete code, I could be way off here.

Here's the code I put together:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPartUserParams As UserParameters = oPDef.Parameters.UserParameters

	Dim NumericList As New List(Of String)
	NumericList.Add("InstanceID") 'A
	NumericList.Add("InstanceName") 'B
	NumericList.Add("ProductType") 'C
	NumericList.Add("Description") 'D
	NumericList.Add("DesignType") 'E
	NumericList.Add("GroupNumber") 'F
	NumericList.Add("SerialNumber") 'G
	NumericList.Add("Area") 'H
	NumericList.Add("Zone") 'I
	NumericList.Add("SequenceID") 'J
	NumericList.Add("CustomerID") 'K
	NumericList.Add("Phase") 'L
	NumericList.Add("UsableWidth") 'M

	Dim FeedValue As Double
	Dim Row As Integer

	Dim i As Integer = 1
	For Each oString In NumericList
		For Each oPartUserParam As UserParameter In oPartUserParams
			If oPartUserParam.Name = NumericList.Item(i)	
				'parameter found
				FeedValue = oPartUserParam.Value
				If oPartUserParam.Units = "degree" Then
					FeedValue = Round(UnitConversion(FeedValue, oPartUserParam), 2)
				Else
					FeedValue = Round(UnitConversion(FeedValue, oPartUserParam), 0)
				End If
				GoTo FoundNumeric
			End If
		Next
	FoundNumeric :
		SetValueInExcel("COLUMN_" + GetCol(NumericList.Item(i)), Row.ToString, FeedValue)
		'reset FeedValue
		FeedValue = "N/A"
		i = i + 1			
	Next
End Sub

Function UnitConversion(FVal As Double, UParam As UserParameter) As Double
	Return ThisApplication.UnitsOfMeasure.ConvertUnits(FVal,UnitsTypeEnum.kDatabaseLengthUnits,UnitsTypeEnum.kInchLengthUnits)
End Function

Sub SetValueInExcel(Str As String,Rw As String, fVal As Double)
	'do something here
End Sub

Function GetCol(Name As String) As String
	Select Case Name
	Case "InstanceID"
		Return "A"
	Case "InstanceName"
		Return "B"
	Case "ProductType"
		Return "C"
	Case "Description"
		Return "D"
	Case "DesignType"
		Return "E"
	Case "GroupNumber"
		Return "F"
	Case "SerialNumber"
		Return "G"
	Case "Area"
		Return "H"
	Case "Zone"
		Return "I"
	Case "SequenceID"
		Return "J"
	Case "CustomerID"
		Return "K"
	Case "Phase"
		Return "L"
	Case "UsableWidth"
		Return "M"
	End Select
End Function

On a totally other train of thought about this situation though, I'm thinking that instead of using a series of individually defined Constants, you could create a Dictionary(Of String, String), where the first String is the 'Key', and the second String is considered the 'Value' of the pair.  Then each pair (KeyValuePair) contains both the key and the value.  Have you ever worked with these types of container objects in vb.net before?

 

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report