Journaling - Changing the Value of multiple Expressions
Journaling - Changing the Value of multiple Expressions
(OP)
Cowski and others have helped me in the past to create a journal that would locate and edit the names of multiple expressions in a given part. I would like to do something similar with expression values. Basically I want the journal to locate all expressions with a specified value, then change all said expressions to a different specified value.
The two highlighted lines are where I am having trouble. I want to look for the value of each expression and am unsure of the syntax. Any help would be appreciated.
CODE -->
'This section looks for the "NAME' Expression and changes it to
'"NAME_REMIX[i]" with i being the counter established above
' The following pattern is set to look for the phrase "NAME'" in the expressions list,
' followed by a single apostrophe ('),
' followed by 1 or more digits (\d+),
' followed by 0 or more characters (\.*)
Dim DNExChange as New RegEx("NAME'\d+\.*")
' sets up a for loop that will check all the expressions in "myExpressionsDNExChange
For Each myExpChange as Expression in myExpressionsDNEx
' if the expression in question matches the "NAME'" pattern set above, then
if DNExChange.IsMatch(myExpChange.Name) then
' defines a new expression "NAME_REMIX[#]" to replace the NAME'[#] expression,
' but with a number we can account for
Dim expression1 As Expression = CType(workPart.Expressions.FindObject(myExpChange.Name), Expression)
workPart.Expressions.Rename(expression1, "DPF_NAME_REMIX" & i)
end if
Next The two highlighted lines are where I am having trouble. I want to look for the value of each expression and am unsure of the syntax. Any help would be appreciated.





RE: Journaling - Changing the Value of multiple Expressions
What you will need to do is build a new RegEx to match the expression values you are looking for. I can't help with that unless you explain the values you want to filter for.
To try and build a RegEx yourself, do some Googling on the matter and have a go using these sites:
regexr
txt2re
regexpal
regexlib
I've found each of these provide slightly different approaches to building RegExs and each one has its merits and pitfalls
Once you have Regular Expression you need to apply it to the expression value instead of the name. So you need to change the second highlighted line to something like:
CODE -->
if DNExChange.IsMatch(myExpChange.RightHandSide) thenThen finally, instead of renaming the expression, set its value instead:
CODE -->
Graham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com
RE: Journaling - Changing the Value of multiple Expressions
The value of the expression will always be an integer, 0.05 or something similar.
RE: Journaling - Changing the Value of multiple Expressions
RE: Journaling - Changing the Value of multiple Expressions
CODE -->
Dim AA as New RegEx("^\d")to look only for the RightHandSide values that begin with a number only. Unfortunately, some of the expressions I am looking to change actually start with a decimal point (instead of 0.05, their value is .05). I'm not sure how to account for that in the Regular Expression defining line. Anyone know how to do that?
RE: Journaling - Changing the Value of multiple Expressions
If you are looking for a specific value, I'd suggest using the integer.TryParse or double.TryParse methods to convert the string value returned from the expression.Value to a numeric value that you can use in comparisons. You could also use these methods on the .RightHandSide property to see if you are dealing with a formula or simple value.
Then again, regex may be what you need, it all depends on what exactly you are looking for...
www.nxjournaling.com
RE: Journaling - Changing the Value of multiple Expressions
Did you get what you needed to solve this one? If not, post back with any questions/problems.
www.nxjournaling.com
RE: Journaling - Changing the Value of multiple Expressions