Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journaling - Changing the Value of multiple Expressions

Status
Not open for further replies.

kfraysur

Bioengineer
Feb 4, 2010
42
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.


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 (\.*)
[b][highlight #FCE94F]Dim DNExChange as New RegEx("NAME'\d+\.*")[/highlight][/b]



' 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
	[highlight #FCE94F][b]if DNExChange.IsMatch(myExpChange.Name) then[/b][/highlight]

		' 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.
 
Replies continue below

Recommended for you

The first highlighted line defines a Regular Expression (RegEx) to match the required expression name.
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 [wink]

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.[highlight #EDD400]RightHandSide[/highlight]) then

Then finally, instead of renaming the expression, set its value instead:
Code:
myExpChange.SetRightHandSide([i][sub]the new expression value[/sub][/i])

Graham Inchley, Systems Developer.
NX6, NX8.5(testing)
 
Thanks for the help.

The value of the expression will always be an integer, 0.05 or something similar.
 
I think the Regular Expression is probably overkill for the current application. I am only looking to change expressions with a single integer value.
 
Looking into this further, I thought I had solved the problem by using the line

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?
 
I think a regex may be overkill for this particular problem.

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
 
I did. Thanks cowski and everyone else for the help, it's really appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor