Assigning Conditions + Access Section Properties

Post Reply
wcfrobert
Posts: 2
Joined: Tue Jun 21, 2022 5:30 pm

Assigning Conditions + Access Section Properties

Post by wcfrobert » Wed Jun 22, 2022 10:07 pm

Hello,

First Question:

I am trying to use the Python API to parametrically assign mass, fixity, and other conditions. After some digging around in the documentation, I managed to get something to work (see code snippet below)

Image

The part that isn't working is commented out in green. I don't know if it is being assigned to the nodes in the model or not... The work tree shows them as black. But If I go to the conditions tab, none of the nodes are highlighted.

Image


Second Question:

I want to parametrically assign physical section properties (e.g. A, Iy, Iz, Ay, Az, J) through Python; however, I cannot get the properties within "Section" attribute to change. Things like "E", "G", "Dimension", "Izz_modifier" works fine.... Do I have the right syntax here?

Image



Third Question:
In the future, I plan to group objects by section set first, and then use them for property assignment. It seems like official documentation is still being developed. Is there any example snippet for how to go about doing this? I suspect this will be a very often-repeated operation for me.


Thank you so much for your help!
Robert

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

Re: Assigning Conditions + Access Section Properties

Post by STKO Team » Fri Jun 24, 2022 10:26 am

This answers questions 2 and 3:

Code: Select all

from PyMpc import *

SELECTION_SET_ID = 1
PROPERTY_ID = 1

App.clearTerminal()
doc = App.caeDocument()

# get the property
phys_prop = doc.getPhysicalProperty(PROPERTY_ID)
xobj = phys_prop.XObject

# if you don't know all the attributes... you can look at them here
for attribute_name, attribute in xobj.attributes.items():
	print('"{}" ({})'.format(attribute_name, attribute.type))

# this is how you make it 2D
xobj.getAttribute('Dimension').string = '2D'
xobj.getAttribute('2D').boolean = True
xobj.getAttribute('3D').boolean = False

# this is how you make it 3D
xobj.getAttribute('Dimension').string = '3D'
xobj.getAttribute('3D').boolean = True
xobj.getAttribute('2D').boolean = False

# this is how you change E and G
# pay attantion to the G name:
#    we use the forward-slash in a name when we 
#    don't want to show the string after the forward-slash.
#    As in this case, we need to distinguish between 2 attributes 
#    which should appear to the user with the same name...
xobj.getAttribute('E').quantityScalar.value = 1000.0
xobj.getAttribute('G/2D').quantityScalar.value = 800.0
xobj.getAttribute('G/3D').quantityScalar.value = 800.0

# stiffness modifiers
xobj.getAttribute('Iyy_modifier').real = 0.8
xobj.getAttribute('Izz_modifier').real = 0.7

# section offset
xobj.getAttribute('Y/section_offset').quantityScalar.value = 0.1
xobj.getAttribute('Z/section_offset').quantityScalar.value = 0.2

# section
section = MpcBeamSection(
	MpcBeamSectionShapeType.Custom,
	'section_Custom', 'user', 'mm',
	#  A,  Iyy,  Izz,    J,  alphaY, alphaZ
	[1000.0,  0.2,  0.3,  0.4,     0.5,    0.6]
	)
xobj.getAttribute('Section').customObject = section

# when you are done with the XOBject changes
phys_prop.commitXObjectChanges()

# this is how you assign this property to a selection set
# clear current selection
doc.scene.unselectAll()
# run the command to select the geometries in a selection set
App.runCommand('SelectionSetSelect', str(SELECTION_SET_ID))
# run the command to assign a property to the current selection
App.runCommand('AssignPhysicalProperty', str(PROPERTY_ID))

# done.
App.updateActiveView()
Regarding question 1):
It looks like you are using the "tag" variable as both the geometry ID and their vertex index. Are you sure you want to do this?
Anyway, to assign a condition to a geometry you can use the same approach I used in the code above to assign the physical property.

wcfrobert
Posts: 2
Joined: Tue Jun 21, 2022 5:30 pm

Re: Assigning Conditions + Access Section Properties

Post by wcfrobert » Fri Jun 24, 2022 4:32 pm

Perfect, This is exactly what I needed!

Just a couple of follow-up questions:
MpcBeamSection(
MpcBeamSectionShapeType.Custom,
'section_Custom', 'user', 'mm',
# A, Iyy, Izz, J, alphaY, alphaZ
[1000.0, 0.2, 0.3, 0.4, 0.5, 0.6]
)
I am using US imperial units. Do I need to change the "mm" to anything else? I thought OpenSees if agnostic when it comes to units. Does this parameter change anything in the backend?
Regarding question 1):
It looks like you are using the "tag" variable as both the geometry ID and their vertex index. Are you sure you want to do this?
For a single node, what is the different between its geometry and its vertex?

I assigned all the nodes in my model in the following form: [index]"node{index}". Same with my mass definition: [index]"nodalMass{index}".

Since the index restarts at 1 for definition, they have a 1-to-1 match (i.e. node index = mass definition index = tag). Is this a problematic approach?

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

Re: Assigning Conditions + Access Section Properties

Post by STKO Team » Mon Jun 27, 2022 10:27 am

I am using US imperial units. Do I need to change the "mm" to anything else? I thought OpenSees if agnostic when it comes to units. Does this parameter change anything in the backend?
Don't care about the units. In fact, both OpenSees and STKO are unitless. However, the databases we use for beam-cross-section have a unit for pre-defined section types. But it is just used for creating the default values.
At the end of the day, OpenSees uses the numbers you input.
For a single node, what is the different between its geometry and its vertex?
I assigned all the nodes in my model in the following form: [index]"node{index}". Same with my mass definition: [index]"nodalMass{index}".
What I mean is that you are using "tag" as both:
  • The geometry ID (here: geom = doc.geometries[tag])
  • The vertex Index (here: mass_assignment.vertices.append(tag)
However, the sub-geometry indices are different from the parent-geometry's ID. sub-geometry indices are always 0-based and continuos.
Look at this for example:
geom_tag_and_vertex_tag.png
geom_tag_and_vertex_tag.png (58.35 KiB) Viewed 1038 times
If you show me a screenshot of your model or of what you are trying to achieve, I can suggest you something

StavrosP
Posts: 6
Joined: Sat Oct 22, 2022 2:48 pm

Re: Assigning Conditions + Access Section Properties

Post by StavrosP » Mon Apr 10, 2023 4:07 pm

Hello,

I am also having some trouble assigning a condition to a specific geometric entity (vertex in my case) as the "assignCondition" command doesn't exist and I cannot get working the "editing" command.
Could you tell me what am I missing here?

Code: Select all

def beam_fixities():
    # THIS FUNCTION IS NOT ASSIGNING CORRECLTY THE CONDITIONS TO THE VERTICES.
    meta_cond = doc.metaDataCondition('Constraints.sp.fix')
    xobj_cond = MpcXObject.createInstanceOf(meta_cond)
    xobj_cond.getAttribute('Dimension').string = '3D'
    xobj_cond.getAttribute('2D').boolean = False
    xobj_cond.getAttribute('3D').boolean = True
    xobj_cond.getAttribute('ModelType').string = 'U-R (Displacement+Rotation)'
    xobj_cond.getAttribute('U-R (Displacement+Rotation)').boolean = True
    xobj_cond.getAttribute('Ux').boolean = True
    xobj_cond.getAttribute('Uy').boolean = True
    xobj_cond.getAttribute('Uz').boolean = True
    xobj_cond.getAttribute('Rx').boolean = True
    xobj_cond.getAttribute('Ry').boolean = True
    # xobj_cond.getAttribute('Rz').boolean = True # THIS IS NOT WORKING PROPERLY - SEE MY QUESTION COMMENT IN THE FORUM
    # make the fixity condition
    prop_fix = MpcCondition()
    prop_fix.id = doc.conditions.getlastkey(0) + 1
    prop_fix.name = 'Fixity'
    prop_fix.XObject = xobj_cond
    doc.addCondition(prop_fix)
    doc.commitChanges()
    doc.dirty = True
    prop_fix.commitXObjectChanges()
    # edit the condition
    App.runCommand('EditCondition', str(prop_fix.id))
    # assign it to the vertices
    doc.scene.unselectAll()
    beam_geometry = doc.getGeometry(doc.geometries.getlastkey(0))
    shape = beam_geometry.shape
    for vertex_id in range(shape.getNumberOfSubshapes(MpcSubshapeType.Vertex)):
        doc.scene.select(beam_geometry, vertex_id, MpcSubshapeType.Vertex)
    doc.commitChanges()
    doc.dirty = True
    App.runCommand("Regenerate")
    App.processEvents()    
I would like also to ask about some additional points which are related to this question:
  • in the commands above I cannot set "Rz" equal to "True" as it gives an error of "'NoneType' Object has no attribute 'boolean'". Why is that? The rest of the attributes work fine.
  • where can I find what are the differences between the following commands: "commitChanges", "commitXObjectChanges" and "processEvents"?
  • I am using the command App.runCommand('NewPreDocument') to create a clean doc, but how can I bypass the popup dialogue each time (for example, answering "No" to save the project)?
  • Is there a complete example that shows a simple model generation (e.g. beam, truss) from beginning to end, including, the analysis steps, setting up the recorder etc.? I couldn't find this in the documentation or the scripts provided in the beg./adv. courses.
I also attach my code just in case it's helpful to answer the above. Thank you very much!

Stavros
Attachments
create_1d_models.zip
(2.93 KiB) Downloaded 4 times

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

Re: Assigning Conditions + Access Section Properties

Post by STKO Team » Tue Apr 11, 2023 9:53 am

Is there a complete example that shows a simple model generation (e.g. beam, truss) from beginning to end, including, the analysis steps, setting up the recorder etc.? I couldn't find this in the documentation or the scripts provided in the beg./adv. courses.
Not yet. We are creating the documentation and it will be ready in few months from now. In the meantime you can ask questions here and we will guide you.


First issue. You don't have to add the 2 vertices to the document, since they are used to build the edge, which will in turn contain them as sub-geometries.
So, in the function "beam_geometry" I deleted these 2 lines:

Code: Select all

add_geom(MpcGeometry(get_geom_id(), "V1", v1))
add_geom(MpcGeometry(get_geom_id(), "V2", v2))
in the commands above I cannot set "Rz" equal to "True" as it gives an error of "'NoneType' Object has no attribute 'boolean'". Why is that? The rest of the attributes work fine.
It's because The Rz attribute does not exist. Instead you have Rz/2D and Rx/3D (because the Rz attribute can be used for either 2D or 3D case)
If you are not sure, you can see what are all the attribute names in a XOBject with this function:

Code: Select all

print('\n'.join(xobj_cond.attributes.keys()))
Since you are working in 3D, this is what you need:

Code: Select all

xobj_cond.getAttribute('Rz/3D').boolean = True
I am using the command App.runCommand('NewPreDocument') to create a clean doc, but how can I bypass the popup dialogue each time (for example, answering "No" to save the project)?
You cannot do it now, But in the next version you will have a way to do it.

I am also having some trouble assigning a condition to a specific geometric entity (vertex in my case) as the "assignCondition" command doesn't exist and I cannot get working the "editing" command.
The assignment of conditions is different from the assignment of properties.
See this modified example:
create_1d_models.zip
(3.13 KiB) Downloaded 3 times

Post Reply