Property assignment

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Property assignment

Post by BrownTrout_NZ » Wed Nov 06, 2024 2:54 am

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?
snip face.PNG
snip face.PNG (59.39 KiB) Viewed 2674 times
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.
Capture.PNG
Capture.PNG (39.71 KiB) Viewed 2674 times
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).
CREATE_STKO_MODEL_TW1_MANUAL.zip
(7.75 KiB) Downloaded 82 times
Hope to hear from you soon.

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Re: Property assignment

Post by BrownTrout_NZ » Tue Nov 12, 2024 3:06 am

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")

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

Re: Property assignment

Post by STKO Team » Wed Nov 13, 2024 10:45 am

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?
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.

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()
3. Also assign element & material below do not appear to work. No error messages, but it just does not work. Please assist on this.
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 document

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 = seed

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

Re: Property assignment

Post by STKO Team » Wed Nov 13, 2024 10:45 am

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.
.quantityVector.value = ...

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Re: Property assignment

Post by BrownTrout_NZ » Thu Nov 14, 2024 5:16 am

Thanks STKO team ! It is all good except below.
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")
snip12112024.PNG
snip12112024.PNG (37.69 KiB) Viewed 2572 times

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

Re: Property assignment

Post by STKO Team » Thu Nov 14, 2024 9:13 am

You declared a physical property (prop = MpcProperty())
Instead you wanted an element property (prop = MpcElementProperty())

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Re: Property assignment

Post by BrownTrout_NZ » Thu Nov 14, 2024 5:05 pm

worked like a charm, THANK YOU !!

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Re: Property assignment

Post by BrownTrout_NZ » Fri Nov 15, 2024 7:50 pm

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 ?

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
Capture2.PNG (24.73 KiB) Viewed 2544 times
SNIP1.PNG
SNIP1.PNG (55.58 KiB) Viewed 2544 times

BrownTrout_NZ
Posts: 37
Joined: Fri Sep 13, 2024 6:23 pm

Re: Property assignment

Post by BrownTrout_NZ » Mon Nov 18, 2024 2:36 am

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")
Capture.PNG
Capture.PNG (19.02 KiB) Viewed 2508 times

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

Re: Property assignment

Post by STKO Team » Mon Nov 18, 2024 9:56 am

Material tag stays "None" regardless of the fact that material ids exist in the Model or not.
Don't use the attribute value in the indexVector:

Code: Select all

xobj_ele.getAttribute('Material_tags').indexVector = Material_tags
Note that a quantityVector is something that support a value and unit system, that's why you have a .value attribute.
an 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('__')))

Post Reply