Splice an array of CAE.FEElement-How to?

To all,

I have a code which define an array (I think!) of CAE.FEElement as follows
Dim arrFEElmInGroupTarget() As CAE.FEElement = GetGroupElements(caeGroup1)

The code work as intended but I now would like to add some checks. One of them is to check if each elements in that array is a 1D element if it isn't remove it from the array. I believe the 'splice' function should do the trick: https://msdn.microsoft.com/en-us/library/vstudio/72x0hey1(v=vs.100).aspx

It seems that I need the index for the splice function but I am getting an error about index not being a member of System.Array

what is it that I am not getting? (ignoring my limited vb knowledge)

Thanks
Regards
JXB

I would suggest creating a new List object to hold the elements you are interested in, loop through the group elements, if the type is 1D - add it to the list. You will be left with a list (essentially a fancy array) of only the elements that you want.

While playing around with the idea of a "final" list, I was going through the function I am using to get the CAE.FFEElement in the specified group and I think I might be able to do the test on the element type on that function. What I have at the moment is

Dim element As CAE.FEElement = CType(obj, CAE.FEElement)
If Not element Is Nothing Then
elementList.Add(element)
End If

Which I think I can modify to do the check as follows

Dim element As CAE.FEElement = CType(obj, CAE.FEElement)
If Not element Is Nothing And element.Shape= Line Then
elementList.Add(element)
End If

The only small problem is understanding the output of .Shape as the doc states ... Property Shape As ElementTypes.Shape
and list the type of Shape. A quick test with

TheLW.WriteLine("elm shape is :" & element.Shape) returns un number. 1 in case of "Line"

did a test with (which works!)

If Not element Is Nothing Then
If element.Shape = 1 'Line
elementList.Add(element)
Else
iNotKeptElm += 1
End if
End If

Is there a way of using "Line" to do the check?
This code appears to be very slow

Thanks
Regards
JXB

Thanks
Regards

Sorry for not responding to this sooner, I just stumbled across this question today.

To answer your question we'll need to talk a bit about "magic constants" and enumerations. Many times when writing programs, we must assign some arbitrary descriptor to an item. For instance, we might be writing a program that deals with a "box" object; our boxes come in three distinct sizes: small, medium, and large. We assign each size an arbitrary integer value so that the computer can distinguish between the different sizes (we use integer values because computers can quickly and efficiently manipulate them). We assign the value of 0 (zero) to "small", 1 (one) to medium, and 2 (two) to large. We could have easily used other numbers to represent the sizes, we just need something so that the computer can distinguish the sizes and manipulate the information.

Now let's say I finish writing the program and I use these values directly in my code. I may end up with code that looks something like:

If someMeaninglessVariable = 0 then
otherVariable = 1.1
End if

if someMeaninglessVariable = 1 then
otherVariable = 1.2
End if

'etc

I retire and you are hired in to maintain the code that I wrote. The code above would be confusing to you; in some parts of the code the values 0, 1, and 2 seem to have some sort of special significance. These values with special significance came to be known as "magic constants". We don't use the variable "someMeaninglessVariable" in mathematical formulas, but the value seems to indicate something else. Had I used named constants in my code, it would have saved you a lot of time tracking down what those constants meant.

The code would have been more readable (and thus maintainable) had I used named constants (and more descriptive variable names).

Const BoxSizeSmall as integer = 0
Const BoxSizeMedium as integer = 1
Const BoxSizeLarge as integer = 2

'more code

if someBoxSize = BoxSizeSmall then
handlingRate = 1.1
end if

'etc

An 'enumeration' takes the named constant strategy to the next level by grouping related constants and providing us with a few other features that we won't get into right now. But basically, an enumeration allows us to give meaningful names to integer values. This gives us the best of both worlds: humans can more easily read and understand the source code, and the compiler will replace the name with the underlying integer value in the compiled code so the computer can efficiently manipulate the information.

Public Enum BoxSize As Integer
Small = 0
Medium = 1
Large = 2
End Enum

'other code
if someBoxSize = BoxSize.Small then
handlingRate = 1.1
end if

'etc

Now back to your original question: "Is there a way of using "Line" to do the check?"
The answer is: yes. ElementTypes.Shape is an enumeration provided to us in the NXOpen API. We can use the underlying value for "line", 1 (one), as you have done in your code above, or we can make our code more readable by using the name of the value. The enumeration is defined within a certain namespace in the API, we'll need to qualify which enumeration we want to use.

Dim theElement As CAE.FEElement
If theElement.Shape = CAE.ElementTypes.Shape.Line Then
'do something
End If

Thank you very much NXJournaling for this very clear explanation. I guess it just shows my rather limited knowledge of programming and you've have definitely added another stone to my "knowledge wall". This is very much appreciated it. I have to admit that I left the code as it was ([code] if theelement.shape=1 then ... [/code]) because it works but will review it during my lunch break. I will also try to read a bit more on enumeration in my spare time. While I understand the principal I have never "use" the method i.e. define a Public Enum BoxSize As Integer for example

Thanks a lot

Regards
JXB

Thanks
Regards