API for geometry?

kolozvari
Posts: 227
Joined: Tue Oct 05, 2021 9:22 pm

API for geometry?

Post by kolozvari » Mon Feb 19, 2024 3:45 am

Hello,

I have data about nodes, element connectivities and element properties in tabulated format and I was wondering if there is an API tool (or similar) that can be used to import this into STKO. All elements are beam-column elements.

Please let me know.

Thanks

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: API for geometry?

Post by STKO Team » Mon Feb 19, 2024 9:19 am

The documentation will be online soon.

in the meantime try this for creating geometries. When you will be done with this, we can give you instruction about how to assign properties and conditions

Code: Select all

from PyMpc import *
doc = App.caeDocument()

# how to create vertices from coordinates
v1 = FxOccBuilder.makeVertex(0.0, 0.0, 0.0)
v2 = FxOccBuilder.makeVertex(0.0, 0.0, 3.0)
v3 = FxOccBuilder.makeVertex(3.0, 0.0, 3.0)

# how to create straight edges from 2 vertices
e1 = FxOccBuilder.makeEdge(v1, v2)
e2 = FxOccBuilder.makeEdge(v2, v3)

# how to make a wire from multiple edges
edges = [e1,e2]
w1 = FxOccBuilder.makeWire(edges)

# how to get the next id:
# get the last ID (or default = 0) + 1
next_id = doc.geometries.getlastkey(0) + 1

# how to add a geometry to the document
# using the wire w1 as shape
geom = MpcGeometry(next_id, "The Geometry name", w1)

# add it to the document
doc.addGeometry(geom)

# regenerate (str(1) default, or str(2) to also do a fitall)
App.runCommand('Regenerate', str(2))

kolozvari
Posts: 227
Joined: Tue Oct 05, 2021 9:22 pm

Re: API for geometry?

Post by kolozvari » Mon Feb 19, 2024 4:20 pm

Thank you. I'll try to make a loop since I have hundreds of nodes and elements. A few questions.

Is it necessary to make a wire?

What is the difference between an egde and a wire?

How do you write/debug this? Can you run this in regular python interpreter or you can run this only via STKO?

Thanks

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: API for geometry?

Post by STKO Team » Mon Feb 19, 2024 5:28 pm

Is it necessary to make a wire?
What is the difference between an egde and a wire?
A wire is a set of connected edges. similar to a "Merge" for generic geometries. A wire is specific for edges only.
An edge is a line, a circle, a spline, i.e. any curve with 2 boundary vertices.
How do you write/debug this? Can you run this in regular python interpreter or you can run this only via STKO?
Some function can be used in regular python. The only thing you need to do is to make sure python can locate the PyMpc.pyd shared library which is inside the STKO installation dir.
However, other functions (Like the runCommand for the regen) need the STKO's gui.
The simplest way to debug it is to view the results in STKO.

It's not a complex code that may need a real debugger

kolozvari
Posts: 227
Joined: Tue Oct 05, 2021 9:22 pm

Re: API for geometry?

Post by kolozvari » Mon Feb 19, 2024 5:33 pm

OK, thank you. I managed to import the geometry. Now I want to assign the properties and elements. Can you please send me the API codes for that?

Thanks

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: API for geometry?

Post by STKO Team » Tue Feb 20, 2024 11:35 am

Ok, a question now.
a) Properties are already defined and you only have to assign them? or
b) You also need to define properties at runtime?

kolozvari
Posts: 227
Joined: Tue Oct 05, 2021 9:22 pm

Re: API for geometry?

Post by kolozvari » Tue Feb 20, 2024 10:09 pm

I can define properties by hand in STKO and then I would just need to assign them using API.

Thank you

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: API for geometry?

Post by STKO Team » Fri Feb 23, 2024 11:41 am

start with this snippet:

Code: Select all

from PyMpc import *
doc = App.caeDocument()

# here you select the whole geometry with ID = 1
doc.scene.select(doc.getGeometry(1))

# here you select only the sub-edge with localID = 0 (cotinuous and 0-based)
# of geometry with ID = 2
doc.scene.select(doc.getGeometry(2), 0, MpcSubshapeType.Edge)

# now that you have a selection you can assign a property
prop_id = 1
App.runCommand('AssignPhysicalProperty', str(prop_id))

kolozvari
Posts: 227
Joined: Tue Oct 05, 2021 9:22 pm

Re: API for geometry?

Post by kolozvari » Mon Feb 26, 2024 11:24 pm

Thank you for sharing this. I have used your code to implement a loop to load my entire model. Loading geometry works fine, but assigning properties doesn't seem to work. I attached a reduced version of the input with only a few elements, and I was wondering if you could give me a hint of what is wrong. In the attached folder is also the STKO model with all the pre-defined section properties that I would like to assign. By the way, it would be great if the definition of section properties could be automated at some point...

Looking forward to hearing from you.

Thanks,
Attachments
LoadModelPy.zip
(148.67 KiB) Downloaded 245 times

STKO Team
Posts: 3066
Joined: Tue Oct 29, 2019 8:45 am

Re: API for geometry?

Post by STKO Team » Tue Feb 27, 2024 9:42 am

Here it is:
LoadModelInfo.zip
(1.38 KiB) Downloaded 252 times
The main issue was that you were adding geometries and trying to select them. Selection from doc.scene works only if a geometry has a visual representation (i.e. after a Regen).
So what I did was to do it in 2 loops. The first one adds the geometries and map them to their property id.
After this first loop I do a regen, and then a new loop to select and assign

Few minor changes:
  • os.system('cls') changed to App.clearTerminal(). The former has no effect on STKO.
  • I re-formatted your for loops using the for key,value in dict.items(). It is more efficient than iterating through keys and then doing multiple lookups into the dict to get the value

Post Reply