I am trying to get some simple iLogic code to run and I could use some (probably very basic) help.
Essentially, I need to complete my If/Then statement to do the functions in my comment quotes below. I basically want to check for a parameter named 'PartNumber' in any existing document in which the user opens (and clicks 'Save' or updates iProperties). If it exists, I want to assign it the 'MFPN' variable value (taken from the iProperties). If it does not exist, I want to create it, then assign the 'MFPN' variable value to it.
Any help is appreciated greatly. The simpler the solution the better, as I am very novice at understanding and/or maintaining programming code.
Here's what I have...
iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False) 'without extension
MFPN = iProperties.Value("Project", "Part Number")
If My_Expression Then
'If "PartNumber" parameter exists in this file, populate it with MFPN variable
Else
'If "PartNumber" parameter does not exist, create it, then populate it with MFPN variable
End If
iLogicVb.UpdateWhenDone = True
Hey, you can't use a name with space as parameter name, hence: "Part_Number":
Dim oDoc As Document = ThisApplication.ActiveDocument Dim oParas As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oPara As UserParameter Try oPara = oParas.Item("Part_Number") Catch oPara = oParas.AddByValue("Part_Number", "", UnitsTypeEnum.kTextUnits) End Try Dim MFPN As String = ThisDoc.FileName(False) 'without extension iProperties.Value("Project", "Part Number") = MFPN oPara.Value = MFPN iLogicVb.UpdateWhenDone = True
Thank you @Owner2229. I dont have the issue of parameter regenerating. I modify your code to have an inputbox but it doesnt change the value.
Dim oDoc As Document = ThisApplication.ActiveDocument Dim oParas As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oPara As UserParameter A_BracketL = InputBox("Enter DRV_A_BracketL Value", "Left Bracket Angle", 91.23) Try oPara = oParas.Item("DRV_A_BracketL") Catch oPara = oParas.AddByValue("DRV_A_BracketL", A_BracketL, UnitsTypeEnum.kDegreeAngleUnits) 'DRV_A_BracketL/57.29577951 End Try iLogicVb.UpdateWhenDone = True
try it this way.
Dim oDoc As Document = ThisApplication.ActiveDocument Dim oParas As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oPara As UserParameter Dim A_BracketL = InputBox("Enter DRV_A_BracketL Value", "Left Bracket Angle [Deg]", 91.23) Try oPara = oParas.Item("DRV_A_BracketL") Catch oPara = oParas.AddByValue("DRV_A_BracketL", 0, UnitsTypeEnum.kDegreeAngleUnits) End Try ' create a number from the text. Dim doubleValue As Double = Double.Parse(A_BracketL) 'inventor expects radians. convert the deg to rad. 'inventor will convert it back to Deg when that value is shown to the user. doubleValue = doubleValue*(Math.PI/180) oPara.Value = doubleValue iLogicVb.UpdateWhenDone = True
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.
Blog: hjalte.nl - github.com
Can't find what you're looking for? Ask the community or share your knowledge.