×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journaling - Changing the Value of multiple Expressions

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.


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

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.RightHandSide) then 

Then finally, instead of renaming the expression, set its value instead:

CODE -->

myExpChange.SetRightHandSide(the new expression value) 

Graham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com

RE: Journaling - Changing the Value of multiple Expressions

(OP)
Thanks for the help.

The value of the expression will always be an integer, 0.05 or something similar.

RE: Journaling - Changing the Value of multiple Expressions

(OP)
I think the Regular Expression is probably overkill for the current application. I am only looking to change expressions with a single integer value.

RE: Journaling - Changing the Value of multiple Expressions

(OP)
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?

RE: Journaling - Changing the Value of multiple Expressions

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

RE: Journaling - Changing the Value of multiple Expressions

kfraysur,
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

(OP)
I did. Thanks cowski and everyone else for the help, it's really appreciate it.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources