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: 

Use iLogic to check for user parameter, create it, populate it

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1714 Views, 4 Replies

Use iLogic to check for user parameter, create it, populate it

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

4 REPLIES 4
Message 2 of 5
Owner2229
in reply to: Anonymous

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

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 5
Anonymous
in reply to: Owner2229

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

 

 

Message 4 of 5
JelteDeJong
in reply to: Anonymous

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.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 5
Anonymous
in reply to: JelteDeJong

Works perfectly @JelteDeJong . Thank you very much.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report