From CAD to FEM/CAE

Hello all!
I am currently trying to get acquainted with the NX Open scripting.
Currently, I just want to create a FEM file for the present part (CAD) file.
I am assuming a simple cuboid as solid. I want to create the corresponding FEM file on top of it, apply a simple meshing and that's all.
Unfortunately I am already stuck at the CAD->FEM part. I was able to record that, but recording seems to be an unclean and only temporary solution. All current steps (generating sketch, extruding etc.) have been scripted in a clean and preferable way. Now I want to keep to this cleanliness and avoid adding recorded code.
I already tried my best on google, but somehow most of the tutorials are only discussing CAD steps.
(BTW: I am using c#)

Could you please help me here?

Regards
Benny

I would suggest cleaning up and generalizing the recorded code before adding it to your existing code base. I like to clean up the recorded code and turn it into a subroutine, function, or class before using it. My general strategy is as follows:

  • Look for builder objects that do not pertain to the task at hand, comment them out and test the code.
  • Look for variables that are declared and later deleted or never used again in the code. Comment them out and test the code.
  • Look for references to objects that only exist in the current work file (usually in the calls to .FindObject), rework these to use the object you want
  • Look for any hard coded values (I run into this most often when working with fonts) and replace them with an appropriate variable reference.
  • Collect the desired "reusable" code into a subroutine, function, or class.
  • Test the code, add it to your existing code, then test some more.