Surface Area ( Python API command )

Hello.
I start building a small python script in order to generate some formulas. The current py script is:

import math
assert mw.version() == 13
id = mw.input("ID:") # get the element ID as string
id = int(id) # convert string into integer

density = mw.mass(id)/mw.volume(id) # calculate density of the element
mw.message("Density of element no. " + str(id) + " is: " + str(math.ceil(density)) + " kg/m3")

surf = mw.surface_area(id, 5) # get surface area based on element ID and face_number
mw.message("Surface area is " + str(surf) + "m2")


What I want to get is the thickness of the shell for any quad4, quad 8...etc using the existing API commands. Currently I am stuck at 'mw.surface_area(face_id)' command. I can get the ID of any element as an input data and it works in order to get the mass and volume of any finite element based on its element number, but I get an error for the 'FaceID'.

Based on Victor's API Reference, the FaceID is 'The area of the element face'. Also, FaceID is defined as command: FaceId(element_id, face_number), having the element ID and the face_number. Based on the attached file, the Face ID for all elements is: faceid="5".

Still, I get an error : "surface_area() takes exactly 1 argument (2given)". What is the correct formula for mw.surface_area ?

Also, how can I get the FaceID of an element from inside Mecway and not opening the LIML file as a text file?

Thank you.

Comments

  • edited May 2020
    There isn't a function for thickness yet, sorry. That should come later as part of material properties.

    Here's an example for surface area of element 1:

    mw.surface_area(FaceId(1,5))

    You could get FaceId using mw.selected_faces() if you've already selected it manually before running the script.

    Face numbers are the circled numbers shown in the attached picture as well as 6 for the opposite face of shells.

    'The area of the element face' refers to the value returned by the function, not the FaceId parameter.
  • Victor,

    Thank you for the Element Shape pictures, that makes it easier to understand how it works.

    I am afraid the function is still not working.

    Even if I run only your command for element no. 1 : mw.surface_area(FaceID(1, 5)) I still get the error "Error from IronPython: name 'FaceID' is not defined." Even if I manually select the element 1 before running the script ( even if this is not the intent ), is still not working.

    Thx!
  • Lower case "d" in FaceId following Python's class naming convention.
  • Of course, is name sensitive... :)
    Is working, thank you!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!