Property assignment
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Property assignment
Hi STKO team
I have been trying to create STKO model using Python API and managed to create all B-reps and some condition assignments (such as support conditions, loads & diaphragms) but have a couple of questions.
1. I have set up faces in the model and named "W1", "W2" etc expecting that I am able to assign certain wall property to them. I have created below code, but it will report that the face number is 0 in the terminal and does not recognize face property. Can you please provide some sample code example for this?
2. I want to know how to create selection set, please provide sample codes.
3. Also assign element & material below do not appear to work. No error messages, but it just does not work. Please assist on this.
4. Lastly please provide some codes to control mesh. For walls I want to split them in 3 layers / storey horizontally for SFI-MVLEM element(no vertical meshing).
Hope to hear from you soon.
I have been trying to create STKO model using Python API and managed to create all B-reps and some condition assignments (such as support conditions, loads & diaphragms) but have a couple of questions.
1. I have set up faces in the model and named "W1", "W2" etc expecting that I am able to assign certain wall property to them. I have created below code, but it will report that the face number is 0 in the terminal and does not recognize face property. Can you please provide some sample code example for this?
2. I want to know how to create selection set, please provide sample codes.
3. Also assign element & material below do not appear to work. No error messages, but it just does not work. Please assist on this.
4. Lastly please provide some codes to control mesh. For walls I want to split them in 3 layers / storey horizontally for SFI-MVLEM element(no vertical meshing).
Hope to hear from you soon.
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Re: Property assignment
Also, below code does not appear to work and have issues with passing quantityevectors. Can someone form STKO team please let me know what I am missing.
Code: Select all
def makeSFI_MVLEM_ADD (id, m, Thicknesses, Widths, Material_tags, CoR, c, ThickMod, tMod, Poisson, Nu, Density, Dens, name):
meta_ele = doc.metaDataElementProperty('beam_column_elements.SFI_MVLEM_3D')
xobj_ele = MpcXObject.createInstanceOf(meta_ele)
xobj_ele.getAttribute('m').integer = m
xobj_ele.getAttribute('Thicknesses').quantityVector = Thicknesses
xobj_ele.getAttribute('Widths').quantityVector = Widths
xobj_ele.getAttribute('Material_tags').indexVector = Material_tags
xobj_ele.getAttribute('-CoR').Boolean = CoR
xobj_ele.getAttribute('c').quantityScalar = c
xobj_ele.getAttribute('-ThickMod').Boolean = ThickMod
xobj_ele.getAttribute('tMod').quantityScalar = tMod
xobj_ele.getAttribute('-Poisson').Boolean = Poisson
xobj_ele.getAttribute('Nu').quantityScalar = Nu
xobj_ele.getAttribute('-Density').Boolean = Density
xobj_ele.getAttribute('Dens').quantityScalar = Dens
prop = MpcProperty()
prop.id = id
prop.name = str(name)
prop.XObject = xobj_ele
doc.addElementProperty(prop)
doc.commitChanges()
doc.dirty = True
prop.commitXObjectChanges()
TK = [0.2, 0.2, 0.2]
WID = [0.5, 0.5, 0.5]
MAT = [1, 2, 1]
makeSFI_MVLEM_ADD (151, 3, TK, WID, MAT, True, 0.02, True, 0.08, True, 0.7, True, 2.4, "MVLEM FROM API")
Re: Property assignment
Sub-geometries do not have a name, you can access them by their local index. For each type of sub-shape, the local index is continuous and zero-based.1. I have set up faces in the model and named "W1", "W2" etc expecting that I am able to assign certain wall property to them. I have created below code, but it will report that the face number is 0 in the terminal and does not recognize face property. Can you please provide some sample code example for this?
2. I want to know how to create selection set, please provide sample codes.
Code: Select all
# create a new selection set
sset_id = doc.selectionSets.getlastkey(0)+1
sset_name = 'Sample Set Whole Geometry'
sset = MpcSelectionSet(sset_id, sset_name)
# add geometries
# example 1) add the whole geometry with ID = 3
item_whole_geom_3 = MpcSelectionSetItem()
item_whole_geom_3.wholeGeometry = True
sset.geometries[3] = item_whole_geom_3
# add it to the document
doc.addSelectionSet(sset)
doc.commitChanges()
# create a new selection set
sset_id = doc.selectionSets.getlastkey(0)+1
sset_name = 'Sample Set Only 1 Face'
sset = MpcSelectionSet(sset_id, sset_name)
# add geometries
# example 2) add only first face (id = 0) of geometry with ID = 3
item_geom_3_face_0 = MpcSelectionSetItem()
item_geom_3_face_0.wholeGeometry = False
item_geom_3_face_0.faces.append(0)
# in the same way you can append to vertices,edges,solids...
# just remember that subshapes have contiguous 0-based indexing
sset.geometries[3] = item_geom_3_face_0
# add it to the document
doc.addSelectionSet(sset)
doc.commitChanges()
This should work. Note that the selection in the graphic window only works for geometries that have been regenerated (i.e. they have graphical mesh for the graphical windows). Make sure that, if you assign a property to a geometry, you called Regen after the geometry has been added to the document3. Also assign element & material below do not appear to work. No error messages, but it just does not work. Please assist on this.
4. Lastly please provide some codes to control mesh. For walls I want to split them in 3 layers / storey horizontally for SFI-MVLEM element(no vertical meshing).
Code: Select all
# setup global controls
geom_id = 3 # geometry with ID = 3
edge_id = 0 # the first edge of geometry 3
geom_controls = mc.geometryControls[3]
seed = MpcMeshEdgeSeed()
seed.type = MpcMeshEdgeSeedType.UniformByDivisions
seed.divisions = 20
geom_controls.edgeControls[edge_id].seed = seedRe: Property assignment
.quantityVector.value = ...Also, below code does not appear to work and have issues with passing quantityevectors. Can someone form STKO team please let me know what I am missing.
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Re: Property assignment
Thanks STKO team ! It is all good except below.
Could you please assist me on this ? Much appreciated.
Could you please assist me on this ? Much appreciated.
Code: Select all
def makeSFI_MVLEM_ADD (id, m, Thicknesses, Widths, Material_tags, CoR, c, ThickMod, tMod, Poisson, Nu, Density, Dens, name):
meta_ele = doc.metaDataElementProperty('beam_column_elements.SFI_MVLEM_3D')
xobj_ele = MpcXObject.createInstanceOf(meta_ele)
xobj_ele.getAttribute('m').integer = m
xobj_ele.getAttribute('Thicknesses').quantityVector.value = Thicknesses
xobj_ele.getAttribute('Widths').quantityVector.value = Widths
xobj_ele.getAttribute('Material_tags').indexVector.value = Material_tags
xobj_ele.getAttribute('-CoR').Boolean = CoR
xobj_ele.getAttribute('c').quantityScalar.value = c
xobj_ele.getAttribute('-ThickMod').Boolean = ThickMod
xobj_ele.getAttribute('tMod').quantityScalar.value = tMod
xobj_ele.getAttribute('-Poisson').Boolean = Poisson
xobj_ele.getAttribute('Nu').quantityScalar.value = Nu
xobj_ele.getAttribute('-Density').Boolean = Density
xobj_ele.getAttribute('Dens').quantityScalar.value = Dens
prop = MpcProperty()
prop.id = id
prop.name = str(name)
prop.XObject = xobj_ele
doc.addElementProperty(prop)
doc.commitChanges()
doc.dirty = True
prop.commitXObjectChanges()
TK = [0.2, 0.2, 0.2]
WID = [0.5, 0.5, 0.5]
MAT = [1, 2, 1]
makeSFI_MVLEM_ADD (151, 3, TK, WID, MAT, True, 0.02, True, 0.08, True, 0.7, True, 2.4, "MVLEM FROM API")Re: Property assignment
You declared a physical property (prop = MpcProperty())
Instead you wanted an element property (prop = MpcElementProperty())
Instead you wanted an element property (prop = MpcElementProperty())
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Re: Property assignment
worked like a charm, THANK YOU !!
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Re: Property assignment
Sorry to bother you guys once again, but below code all works fine except for material tags without any error messages.
Material tag stays "None" regardless of the fact that material ids exist in the Model or not.
If I specify managerial id which does not exit, does not spit any error messages. Based on the py library for SFI-MVLEM(bottom snip), should this raise the error message?
Can you please let me know what I am missing here. Is there any syntax issues ?
Material tag stays "None" regardless of the fact that material ids exist in the Model or not.
If I specify managerial id which does not exit, does not spit any error messages. Based on the py library for SFI-MVLEM(bottom snip), should this raise the error message?
Can you please let me know what I am missing here. Is there any syntax issues ?
Code: Select all
def makeSFI_MVLEM_ADD (id, m, Thicknesses, Widths, Material_tags, CoR, c, ThickMod, tMod, Poisson, Nu, Density, Dens, name):
meta_ele = doc.metaDataElementProperty('beam_column_elements.SFI_MVLEM_3D')
xobj_ele = MpcXObject.createInstanceOf(meta_ele)
xobj_ele.getAttribute('m').integer = m
xobj_ele.getAttribute('Thicknesses').quantityVector.value = Thicknesses
xobj_ele.getAttribute('Widths').quantityVector.value = Widths
xobj_ele.getAttribute('Material_tags').indexVector.value = Material_tags
xobj_ele.getAttribute('-CoR').Boolean = CoR
xobj_ele.getAttribute('c').quantityScalar.value = c
xobj_ele.getAttribute('-ThickMod').Boolean = ThickMod
xobj_ele.getAttribute('tMod').quantityScalar.value = tMod
xobj_ele.getAttribute('-Poisson').Boolean = Poisson
xobj_ele.getAttribute('Nu').quantityScalar.value = Nu
xobj_ele.getAttribute('-Density').Boolean = Density
xobj_ele.getAttribute('Dens').quantityScalar.value = Dens
prop = MpcElementProperty() # CAREFUL !!
prop.id = id
prop.name = str(name)
prop.XObject = xobj_ele
doc.addElementProperty(prop)
doc.commitChanges()
doc.dirty = True
prop.commitXObjectChanges()
#TK = [0.2, 0.2, 0.2]
#WID = [0.5, 0.5, 0.5]
#MAT = [1, 2, 1]
#makeSFI_MVLEM_ADD (151, 3, TK, WID, MAT, True, 0.02, True, 0.08, True, 0.7, True, 2.4, "MVLEM FROM API")- Attachments
-
- Capture2.PNG (24.73 KiB) Viewed 2541 times
-
- SNIP1.PNG (55.58 KiB) Viewed 2541 times
-
BrownTrout_NZ
- Posts: 37
- Joined: Fri Sep 13, 2024 6:23 pm
Re: Property assignment
Similarly below code will not put section from library as we do manually from drop down menu, please advise asap,
Code: Select all
def makeSECTIONS_ADD (id, Dimension, Section, Use_Uniaxial_Materials, E, G, Optional, Izz_modifier, Iyy_modifier, Y, Z, name):
meta_ele = doc.metaDataPhysicalProperty('sections.Elastic')
xobj_ele = MpcXObject.createInstanceOf(meta_ele)
xobj_ele.getAttribute('Dimension').string = str(Dimension)
xobj_ele.getAttribute('3D').Boolean = True
xobj_ele.getAttribute('2D').Boolean = False
xobj_ele.getAttribute('Section').customAttributeObject = str(Section)
xobj_ele.getAttribute('Use Uniaxial Materials').Boolean = Use_Uniaxial_Materials
xobj_ele.getAttribute('E').quantityScalar.value = E
xobj_ele.getAttribute('Em material').index = 10
xobj_ele.getAttribute('Eb material').index = 10
xobj_ele.getAttribute('G material').index = 10
xobj_ele.getAttribute('G/3D').quantityScalar.value = G
xobj_ele.getAttribute('Optional').Boolean = Optional
xobj_ele.getAttribute('Izz_modifier').real = Izz_modifier
xobj_ele.getAttribute('Iyy_modifier').real = Iyy_modifier
xobj_ele.getAttribute('Y/section_offset').quantityScalar.value = Y
xobj_ele.getAttribute('Z/section_offset').quantityScalar.value = Z
prop = MpcProperty()
prop.id = id
prop.name = str(name)
prop.XObject = xobj_ele
doc.addPhysicalProperty(prop)
doc.commitChanges()
doc.dirty = True
prop.commitXObjectChanges()
meta_ele = doc.metaDataPhysicalProperty('sections.Elastic')
xobj_ele = MpcXObject.createInstanceOf(meta_ele)
for attribute_name, attribute in xobj_ele.attributes.items():
print('"{}" ({})'.format(attribute_name, attribute.type))
makeSECTIONS_ADD (40, "3D", "HSS 6x6x0.625", False, 205000000, 80000000, False, 1.0, 1.0, 0, 0, "SHS-SECTION")Re: Property assignment
Don't use the attribute value in the indexVector:Material tag stays "None" regardless of the fact that material ids exist in the Model or not.
Code: Select all
xobj_ele.getAttribute('Material_tags').indexVector = Material_tagsan indexVector is just an array of integers.
So why does Python let you do it without rasing an error saying that the attribute .value is not present in .indexVector?
Because in python you can inject new attributes an method in classes:
try this script:
Code: Select all
class aClass:
def __init__(self, value):
self.value = value
x = aClass(3.0)
print('\nbefore method injection')
print('\n'.join(i for i in dir(x) if not i.startswith('__')))
print('\nafter method injection')
x.aNewValue = 111.0
print('\n'.join(i for i in dir(x) if not i.startswith('__')))