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!

Expressions in VB

Status
Not open for further replies.

Passzed

Computer
Sep 11, 2010
17
Hi,

Can anyone give me any advice of how to check if a specific (named) expression variable has been set from the user using Block styler with VB?

Any help appreciated,
Thank you,
P.
 
Replies continue below

Recommended for you

Is your specific question about accessing the expression with VB or using the block styler?
 
Thank you for your reply,

I want to use expressions or get directly the drawn dimensions of objects through the block styler (interface) saved in VB code.
 
I am not certail that the attached simple vb code gives you an insight to what you are looking for. The code lets you select a feature and lists the feature expression descripion and expression equation. I asume that you can then place the correct expression values in the Block Styler for users to edit.

Is this what you are looking for?

Frank Swinkels
 
 http://files.engineering.com/getfile.aspx?folder=fea0abe1-753a-4854-85f5-3d8b148aecfe&file=FeatureExpressions.vb
I have seen this code. Trying to simplify it.
So far I got the named expressions displayed and now im trying, according what their values are, output messages in a multiline_string box (as defined from the blockstyler).

The thing that causes me headache is the way you output messages in this box (multiline_string); I have tried

Dim ExpressionString As String = expression1.Value.ToString
Dim multiline_string0 As PropertyList = multiline_string0.SetStrings("Expression", ExpressionString)

Also

multiline_string0.Text = expression1.Value.ToString
or
multiline_string0.SetStrings ...
or
multiline_string0.Show ...

Nothing work. Any ideas?

 
Ok if you want the expression values below is a portion of the relevant code

Dim expValues(-1) As String

response = select_feature(feat)

ufs.Modl.AskExpDescOfFeat(feat.Tag, noExps, expdescstrings, _ exptags)

For i As Integer = 0 To noExps - 1
exp = NXObjectManager.Get(exptags(i))
ReDim Preserve expValues(i)
expValues(i) = exp.RightHandSide
Next
Dim multiline_string0Props As PropertyList = _ multiline_string0.GetProperties
multiline_string0Props.SetStrings("Value", expValues)

The differences from the code you had are:

1) For the expression values you need to ask for the RightHandSide
i.e. expValues(i) = exp.RightHandSide

2) Since features may have different number of expressions therefore we need to read the expression values into a string array. The relevant code is:

Dim expValues(-1) As String
For i As Integer = 0 To noExps - 1
exp = NXObjectManager.Get(exptags(i))
ReDim Preserve expValues(i)
expValues(i) = exp.RightHandSide
Next

3) You need to create a PropertyList and set the multi line string using:

Dim multiline_string0Props As PropertyList = _ multiline_string0.GetProperties
multiline_string0Props.SetStrings("Value", expValues)

Hope this helps.

Frank Swinkels

 
So for the late reply; Thank you very much for your help :)
 
I was wondering if there is a specific command for comparing expressions through the VB.net code..

Expressions are already converted to strings.. is it difficult to search and compared for a example a named expression from the user i.e p1?

 
One more question..

This code:

Dim expValues(-1) As String
For i As Integer = 0 To noExps - 1
exp = NXObjectManager.Get(exptags(i))
ReDim Preserve expValues(i)
expValues(i) = exp.RightHandSide
Next
Dim list_box0Properties As PropertyList = list_box0.GetProperties()
list_box0Properties.SetStrings("Value", stringArray:=expValues)

Causes the error: Invalid name property for the block. Whereas if I change the "Value" to "ListItems" shows nothing.

What's is going on?
 
Since you changed from from a multiline string box to a list box you need to use
list_box0Properties.SetStrings("ListItems", expValues)

It is also probable that you need to change a line in the initialize_cb() sub. This should read

list_box0 = CType(theDialog.TopBlock.FindBlock("list_box0"), NXOpen.BlockStyler.ListBox)

I think yours probably still has ("multiline_string0") in it.

Frank Swinkels
 
Still, nothing appears in the list box list_box0Properties.SetStrings("ListItems", expValues)
or
in the version that there is a multiline_string0
multiline_string0Props.SetStrings("Value", expValues)

The initialize_cb() is correct.

I have tried few things nothing worked.
 
If the list box or multi line string box do not show any entries nor throw any errors than we must assume that no expressions have been found. The only reason I can think of is that you might be selecting a body and not a feature. Using either method I get entries in the display when I select a feature. I would need to see more code (especially for selecting a feature) to be able to comment further.

Frank Swinkels
fsw13678@bigpond.net.au
 
To be honest with you I thought I would be able to load all the expressions values of all the objects/features displayed without selecting a specific one. The moment the app lances it will load all the available expressions in string format inside this multiline or list box. I suppose, that’s not possible?

 
OK to get all expression in the current work part the following code snippet will do it. In looking back at the initial question I think what you are asking for is not the expression values but rather the expression name. Please remember that there are many ways to program any specific requirement and that one needs to be very specific regarding one's request for help.

Dim expTitle(-1) As String
Dim workPart As Part = s.Parts.Work
Dim count As Integer = 0
For Each eachexp As Expression In workPart.Expressions
ReDim Preserve expTitle(count)
expTitle(count) = eachexp.Name
count += 1
Next
Dim list_box0Props As PropertyList = list_box0.GetProperties()
list_box0Props.SetStrings("ListItems", expTitle)

Hope this helps

Frank Swinkels
 
Thank you very much for all your help. I should be more specific for future requests for help.

What I was actually wanted to achieve is to display both value and name of expressions in a textbox and then compare / validate them through another piece of code. To do that i thought I needed to convert the expresssions into strings and then compare them against a set of rules.

Thank you,
P.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor