To all
I have a small function which returns a user selection for a CAE group as a CAE.Caegroup variable and I defined it as follows
[Code]
Dim caeGroup1 As CAE.CaeGroup = CType(ChooseOneItem("Select Group containing 1D elements", workSimPart.CaeGroups.ToArray()), CAE.CaeGroup)
[/Code]
the function works just fine but I am playing around with the idea of a GUI (using the NX block Styler). The test on a simple GUI seems to work just fine but I'd like to re-use as much of my original function(s) as possible.
One of the user selection is for CAE group(s) to be processed so the GUI display a list of (valid) CAE groups name in a list box and I can retrieve the user choice.
I'd like to know if it' s possible to (convert)/allocate a group name defined as a string to a variable defined as CAE.CaeGroup? Is it the case of using the Ctype() approach
for example (which is not going to work)
[Code]
Dim caeGroup1 As CAE.CaeGroup = CType(theGroupNameasString,CAE.CaeGroup)
[/Code]
Part of the code I have to retrieve the user selection of CAE groups is
[Code]
Public Function apply_cb() As Integer
Dim saSelecteGroup() As String
'pick up user selection in list box "group Name"
saSelecteGroup = LBoxGroupName.GetSelectedItemStrings
[/Code]
Thanks
Regards
JXB
re: list box
I don't currently have a blockstyler license, so I cannot explain how they work or give any example code for them. However, for a windows form listbox, I'd suggest you attack the problem from the other direction. With a windows form listbox, you can have a collection of objects and tell the listbox to display a particular property of the object (something that returns a string value). When the user makes a selection, it returns the "index" of the item; using the index you can quickly get the correct object from the collection. In the case of CAEGroups, you could maintain a collection of the actual group objects and display the value returned by the .GetName method in the listbox to identify individual groups.
Perhaps the blockstyler listbox has similar capabilities.
re: list box
Thanks. I currently loop through all the CAE group (As CAE.CAEgroup) , check if group is valid for the program (no geo allowed), if it is get the name of this group, add it to a list to be displayed in the listbox
Thinking about your idea of "index" I may append the group ID to the name, for example "12-thegroupname", to be displayed in the list box. Once the program loops through all the user selection, I should be able to extract this ID (bys splitting the name) and "search" for the group (As a CAEgroup) using teh index in the CAE group manager
Thanks
Regards
list box example
Below is a quick example of a winforms listbox. It gathers up all the extrude features into a list and opens a form. The form adds the features in the list to the list box for user selection. The list box uses the .Timestamp property of the feature for display in the list box. When an item is chosen, it is passed back to the module for further processing. The actual feature objects are used at all times; I don't have to create a list of string values representing the features then search through the features later to match up a string value chosen to an actual feature.
Again, I don't know if the block styler list boxes work in the same way. Whether they do or not, perhaps this code will give you some ideas.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Public extrudeList As New List(Of Features.Extrude)
Public chosenExtrude As Features.Extrude
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'gather up the "extrude" features for the listbox
For Each tempFeat As Features.Feature In workPart.Features
If tempFeat.FeatureType = "EXTRUDE" Then
extrudeList.Add(tempFeat)
End If
Next
Dim theForm As New Form1
theForm.ShowDialog()
'user is interacting with form
'user closed the form
If theForm.canceled Then
lw.WriteLine("form cancelled")
Return
End If
If IsNothing(chosenExtrude) Then
lw.WriteLine("no extrude chosen from listbox")
Return
End If
'if we get here, one of the extrude features was chosen
lw.WriteLine("chosen extrude: " & chosenExtrude.GetFeatureName)
Dim extBuilder As Features.ExtrudeBuilder = workPart.Features.CreateExtrudeBuilder(chosenExtrude)
lw.WriteLine("boolean operation: " & extBuilder.BooleanOperation.Type.ToString)
lw.WriteLine("body type: " & extBuilder.FeatureOptions.BodyType.ToString)
lw.WriteLine("start limits: " & extBuilder.Limits.StartExtend.TrimType.ToString)
lw.WriteLine("end limits: " & extBuilder.Limits.EndExtend.TrimType.ToString)
extBuilder.Destroy()
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
''''''''''''''''''''''''''''''''''''''''''''
Public Class Form1
Public canceled As Boolean = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.AddRange(Module1.extrudeList.ToArray)
ListBox1.DisplayMember = "Timestamp"
End Sub
Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
canceled = True
Me.Close()
End Sub
Private Sub btnOk_Click(sender As System.Object, e As System.EventArgs) Handles btnOk.Click
Module1.chosenExtrude = ListBox1.SelectedItem
Me.Close()
End Sub
End Class
''''''''''''''''''''''''''''''''''''''''''''
'generated by the VB.net express IDE, you can ignore the stuff below this line
_
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
_
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.btnOk = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.Location = New System.Drawing.Point(88, 38)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(184, 199)
Me.ListBox1.TabIndex = 0
'
'btnOk
'
Me.btnOk.Location = New System.Drawing.Point(12, 262)
Me.btnOk.Name = "btnOk"
Me.btnOk.Size = New System.Drawing.Size(95, 37)
Me.btnOk.TabIndex = 1
Me.btnOk.Text = "OK"
Me.btnOk.UseVisualStyleBackColor = True
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(177, 262)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(95, 37)
Me.btnCancel.TabIndex = 2
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(29, 38)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(53, 13)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Extrude #"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(29, 9)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(219, 13)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Choose an extrude feature from the list below"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 311)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOk)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents btnOk As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
End Class
RE: list box example
Thanks for the suggestion. I am playing around with different way of defining List
Looking at the provided example it look like the NX GUI with blockstyler is not to different to the Windows Form.
A top level work flow is
1. Initialise GUI listbox
a. Display group name
2. User select groups on list box. ’Apply’
3. The selected group name(s) is returned as a string array
4. The main program at some point requires the variable to be a CAEgroup (as it needs to extract the FEelements in that group)
to load the (valid) group names in the list box
[Code]
Dim ListGroupNames As New List(Of String)(GetCAEGroupName("*"))
LBoxGroupName.SetListItems(ListGroupNames.ToArray)
[/Code]
and the list of (valid) group name is established as follows
[Code]
Function GetCAEGroupName(sFilter1 As String) As List(Of String)
Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
Dim aTheCAEGroups() As CAE.CaeGroup
Dim sTheGroupName As String
Dim iFEElemFound As Integer = 0
Dim pos As Integer = 0
GetCAEGroupName = New List(Of String)
aTheCAEGroups=workSimPart.CaeGroups.ToArray()
For each theCAEGroup As CAE.CaeGroup In aTheCAEGroups
'Check if group contains FE Element. if "yes" then add to List
'break loop as soon as 1 FE element is found
For Each obj As TaggedObject In theCAEGroup.GetEntities()
Try
Dim element As CAE.FEElement = CType(obj, CAE.FEElement)
If Not element Is Nothing Then
iFEElemFound +=1
If iFEElemFound > 1 Then Exit For
End if
Catch
End Try
Next obj
If iFEElemFound <> 0 Then
sTheGroupName = theCAEGroup.GetName()
If sFilter1 <> "*" Then 'sFilter1 is forced to "*" if nothing is given by the user on the GUI i.e it's blank
pos = InStr(sTheGroupName,sFilter1)
If pos <> 0 Then GetCAEGroupName.Add(sTheGroupName)
Else
GetCAEGroupName.Add(sTheGroupName)
End if
End If
Next theCAEGroup
End Function
[/Code]
and when the user presses apply then a (array) of string containing the selection (of group name is created)
[Code]
Dim saSelectGroup() As String
saSelectGroup = LBoxGroupName.GetSelectedItemStrings
[/Code]
if all input is OK, the main program is called as follows
[Code]
If errorCode = 0 Then ProcessData(saSelecRespSimSolEvent,saSelectGroup)
[/Code]
As a test I have created a small function which take the group name as a string and return a CAE.CAEgroup
Dim caeGroup1 As CAE.CaeGroup = GetCAEGroupFromName(CAEGroupSelected)
Thanks
Regards