API for geometry?
API for geometry?
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
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
Re: API for geometry?
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
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))
Re: API for geometry?
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
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
Re: API for geometry?
A wire is a set of connected edges. similar to a "Merge" for generic geometries. A wire is specific for edges only.Is it necessary to make a wire?
What is the difference between an egde and a wire?
An edge is a line, a circle, a spline, i.e. any curve with 2 boundary vertices.
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.How do you write/debug this? Can you run this in regular python interpreter or you can run this only via STKO?
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
Re: API for geometry?
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
Thanks
Re: API for geometry?
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?
a) Properties are already defined and you only have to assign them? or
b) You also need to define properties at runtime?
Re: API for geometry?
I can define properties by hand in STKO and then I would just need to assign them using API.
Thank you
Thank you
Re: API for geometry?
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))
Re: API for geometry?
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,
Looking forward to hearing from you.
Thanks,
- Attachments
-
- LoadModelPy.zip
- (148.67 KiB) Downloaded 245 times
Re: API for geometry?
Here it is:
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:
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