×
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!

*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

How to get the centroid of all elements of a group in VB.NET

How to get the centroid of all elements of a group in VB.NET

How to get the centroid of all elements of a group in VB.NET

(OP)
Dears, I'm trying to translate my vba for excel macro in VB.NET. Hear goes a snippet of my code in VB.NET:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim App As femap.model
App = GetObject(, "femap.model")
Dim cgXYZ As Object
Dim aux(3) As Double
Dim cgTXYZ(3) As Double
Dim PosIniModelX, Conversor, Mass, MassT, x, y, z As Double
Dim olel As femap.Set
olel = App.feSet
Dim el As femap.Elem
el = App.feElem
Dim elID, grID, rc As Long

grID = ReturnNumber(ComboBox1.Text)
rc = olel.AddGroup(femap.zDataType.FT_ELEM, grID)
Conversor = 1000
PosIniModelX = 0
elID = olel.First()
MassT = 0
Do While elID > 0
rc = el.Get(elID)
rc = el.GetFaceArea(0, Mass)
rc = el.GetCentroid(cgXYZ) <-- I'm having problems hear. Apparently is an object array, but I don't know how to declarate it
x = cgXYZ(0) / Conversor + PosIniModelX
y = cgXYZ(1) / Conversor
z = cgXYZ(2) / Conversor
MassT = MassT + Mass / 10000
aux(0) = aux(0) + x * Mass / 10000
aux(1) = aux(1) + y * Mass / 10000
aux(2) = aux(2) + z * Mass / 10000
elID = olel.Next()
Loop
MassT = MassT
aux(0) = aux(0) / MassT
aux(1) = aux(1) / MassT
aux(2) = aux(2) / MassT
cgTXYZ(0) = aux(0)
cgTXYZ(1) = aux(1)
cgTXYZ(2) = aux(2)
End Sub

RE: How to get the centroid of all elements of a group in VB.NET

Try to dim it as a variant not an object.

"Dim cgXYZ as Variant"

RE: How to get the centroid of all elements of a group in VB.NET

To clarify, which way are you converting to? Are you moving the code into Excel VBA or are you createing a vb.net exe in an IDE like Visual Studio.

If it's into excel the comment above should apply.

If it's into a vb.net exe then I believe Dim cgXYZ as Object is fine. This problem might be when looping through elements it is trying to overwrite the object and crashing there. Try adding " cgXYZ = Nothing " right under the Do While elID > 0. This will clear the object first.

Do While elID > 0

cgXYZ = Nothing

rc = el.Get(elID)
rc = el.GetFaceArea(0, Mass)
rc = el.GetCentroid(cgXYZ) '< --I 'm having problems hear. Apparently is an object array, but I don't know how to declarate it
x = cgXYZ(0) / Conversor + PosIniModelX
y = cgXYZ(1) / Conversor
z = cgXYZ(2) / Conversor
MassT = MassT + Mass / 10000
aux(0) = aux(0) + x * Mass / 10000
aux(1) = aux(1) + y * Mass / 10000
aux(2) = aux(2) + z * Mass / 10000
elID = olel.Next()
Loop

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! Already a Member? Login


Resources

eBook - Functional Prototyping Using Metal 3D Printing
Functional prototypes are a key step in product development – they give engineers a chance to test new ideas and designs while also revealing how the product will stand up to real-world use. And when it comes to functional prototypes, 3D printing is rewriting the rules of what’s possible. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close