Property assignment

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

Re: Property assignment

Post by BrownTrout_NZ » Tue Nov 19, 2024 4:42 am

Hi STKO team

Thanks, it is all working now except controlling the meshing for SFI-MVLEM elements and a couple more. I managed to split the panels into 2 or 3 horizontally, but cannot get rid of the diagonal meshing from python code below(this is default ??).
I manually meshed (second snip) a while back but forgot how I did it even manually. This is what I want.

Code: Select all

from PyMpc import *

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

# ***********************************************
# EDGES 0 & 2 ARE TOP AND BOTTOM
# EDGES 1 & 3 ARE THE SIDES OF THE WALL
# THIS PYTHON CODE IS TO MESH THE WALL IN 3 MESHES HORIZONTALLY AND NO MESH VERTICALLY
# AS PER SFI-MVLEM MODELLING
# ***********************************************

def Control_Mesh_Wall(div_horizontally):
    sides = [1, 3]  # List of edge indices to apply the seed to
    top_and_bot = [0, 2]
    # Setup global controls
    mc = doc.meshControls  # Access mesh controls only once
    
    for geom_id, geom in doc.geometries.items():
        shape = geom.shape
        num_vertices = shape.getNumberOfSubshapes(MpcSubshapeType.Vertex)
        if num_vertices == 4:# 4 means wall alls
            print("Geometry ID =", geom_id)
            print("Number of vertices =", num_vertices)
            for edge_id in sides:
                # Create and apply edge seed
                geom_controls = mc.geometryControls[geom_id]
                seed = MpcMeshEdgeSeed()
                seed.type = MpcMeshEdgeSeedType.UniformByDivisions
                seed.divisions = div_horizontally # element will be divided into this number, not the seed number
                geom_controls.edgeControls[edge_id].seed = seed
            for edge_id in top_and_bot:
                # Create and apply edge seed
                geom_controls = mc.geometryControls[geom_id]
                seed = MpcMeshEdgeSeed()
                seed.type = MpcMeshEdgeSeedType.UniformByDivisions
                seed.divisions = 1
                geom_controls.edgeControls[edge_id].seed = seed
 

def Control_Mesh_Column(col_list):
    mc = doc.meshControls  # Access mesh controls only once
    for geom_id, geom in doc.geometries.items():
        shape = geom.shape
        num_vertices = shape.getNumberOfSubshapes(MpcSubshapeType.Vertex)
        if geom_id in col_list:
            if num_vertices == 2 :
                geom_controls = mc.geometryControls[geom_id]
                seed = MpcMeshEdgeSeed()
                seed.type = MpcMeshEdgeSeedType.UniformByDivisions
                seed.divisions = 1 # element will be divided into this number, not the seed number
                geom_controls.edgeControls[0].seed = seed # NOTE EDGE ID 0 FOR ALL COLUMN


#Control_Mesh_Wall(1)

doc.commitChanges()
doc.dirty = True
App.runCommand("Regenerate")
App.processEvents()
DIAGONAL MESH.PNG
DIAGONAL MESH.PNG (98.93 KiB) Viewed 3659 times
NO DIAGONAL.PNG
NO DIAGONAL.PNG (95.06 KiB) Viewed 3659 times

Can you Plasse provide some tips for below as well ? Much appreciated.

1. How to assign master slave interaction into conditions - constraints.mp.rigid diaphragms from python api. Master - slave interaction is already defined through python.

2. How to merge walls and columns.

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

Re: Property assignment

Post by STKO Team » Wed Nov 20, 2024 3:02 pm

Thanks, it is all working now except controlling the meshing for SFI-MVLEM elements and a couple more. I managed to split the panels into 2 or 3 horizontally, but cannot get rid of the diagonal meshing from python code below(this is default ??).
I manually meshed (second snip) a while back but forgot how I did it even manually. This is what I want.
This is to enforce a structured quad/hexa mesh

Code: Select all

geom_id = 1 # geometry with ID = 1
face_id = 0 # the first face of geometry 1
geom_controls = doc.meshControls.geometryControls[geom_id]
face_control = geom_controls.faceControls[face_id]
face_control.topology = MpcMeshAlgoTopology.QuadHexa
face_control.algorithm = MpcMeshAlgo.Structured
2. How to merge walls and columns.
First select what you want, then run the Merge command (the option 0, is to suppress the modal dialog that typically pops up when running this command from the GUI)

Code: Select all

doc.scene.select(doc.getGeometry(1))
doc.scene.select(doc.getGeometry(2))
App.runCommand('Merge', '0')
In the above example I'm selecting the whole geometry.
If instead you want to select only some sub-geometry, for example edge 0 of geometry 1:

Code: Select all

doc.scene.select(doc.getGeometry(1), 0, MpcSubshapeType.Edge)

1. How to assign master slave interaction into conditions - constraints.mp.rigid diaphragms from python api. Master - slave interaction is already defined through python.
Similar to what I did above. Try it by yourself. Select and run the command. Tip: the optional argument for the Assignment command is the str(index) of the property/condition/etc you want to assign

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

Re: Property assignment

Post by BrownTrout_NZ » Fri Nov 22, 2024 7:07 pm

Thanks Team

All good. I could not find AssignCondition ?? I used EditCondition instead and it is kind of working with a pop up comes up & I need to chose the interaction manually, but nice to be able to automate to it.

Not sure doc.getInteraction(1) is working...

Any suggestions ?

Code: Select all

def Assign_MS_to_Condition ():
	meta_cond = doc.metaDataCondition('Constraints.mp.rigidDiaphragm')
	xobj_cond = MpcXObject.createInstanceOf(meta_cond)
	xobj_cond.getAttribute('perpDirn').integer = 3
	prop_load = MpcCondition()
	#prop_load.id = doc.conditions.getlastkey(0) + 1
	prop_load.id = 250
	prop_load.name = 'RIGID-DIAPHRAGMS'
	prop_load.XObject = xobj_cond
	doc.addCondition(prop_load)
	doc.commitChanges()
	doc.dirty = True
	prop_load.commitXObjectChanges()
	
	doc.scene.select(doc.getInteraction(1)) # get interaction as opposed to doc.getgeometry
	App.runCommand('EditCondition', '250')

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

Re: Property assignment

Post by BrownTrout_NZ » Sat Nov 23, 2024 12:24 am

Index vector is not working under sp & mp constraints. Montor is ok.
Can you please advise what I am missing ?

Code: Select all


def Adust_AnalysisSteps_Parameters():
	# CHCEK ID IN ANLAYSIS STEPS
	const = doc.getAnalysisStep(30)
	sp1 = [14,1]
	mp1 = [250,23]
	const.XObject.getAttribute('sp').IndexVector = sp1
	const.XObject.getAttribute('mp').IndexVector = mp1
	const.commitXObjectChanges()
	
	gravitypattern = doc.getAnalysisStep(31)
	gp = [27,28,29,20,31,32,33,34]
	gravitypattern.XObject.getAttribute('load').IndexVector = gp
	gravitypattern.commitXObjectChanges()

	print (f"sp1 = {sp1}")
	print (f"mp1 = {mp1}")
	print (f"gp = {gp}")

	moni = doc.getAnalysisStep(39)
	moni.XObject.getAttribute('Selection Set/X').index = 13
	moni.XObject.getAttribute('Selection Set/Y').index = 15
	moni.commitXObjectChanges()

	moni1 = doc.getAnalysisStep(41)
	moni1.XObject.getAttribute('Selection Set/Y').index = 13
	moni1.commitXObjectChanges()

	moni2 = doc.getAnalysisStep(42)
	moni2.XObject.getAttribute('Selection Set/Y').index = 13
	moni2.commitXObjectChanges()

	# document has changed
	doc.dirty = True
	doc.commitChanges()
	App.runCommand('Regenerate', '1')
	App.processEvents()

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

Re: Property assignment

Post by STKO Team » Mon Nov 25, 2024 9:32 am

I could not find AssignCondition ?? I used EditCondition instead and it is kind of working with a pop up comes up & I need to chose the interaction manually, but nice to be able to automate to it.

Code: Select all

cond = doc.getCondition(1)

# to unassign this condition from all previous assignments
cond.unassign()

# to assign this condition to an interaction
inter = doc.getInteraction(1)
cond.assignTo(inter)

# to assign this condition to a sub-shape of a geometry
geom = doc.getGeometry(1)
subset = MpcConditionIndexedSubSet()
subset.edges.append(0) # you can also use vertices,faces,solids...
cond.assignTo(geom, subset)

# done
cond.clearVisualRepresentation()
cond.changed = True
doc.commitChanges()
App.runCommand('Regenerate')
Index vector is not working under sp & mp constraints. Montor is ok.
Can you please advise what I am missing ?
it's .indexVector, not .IndexVector

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

Re: Property assignment

Post by BrownTrout_NZ » Tue Nov 26, 2024 1:43 am

Perfect ! thanks.

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

Re: Property assignment

Post by STKO Team » Tue Nov 26, 2024 9:04 am

You're welcome

Post Reply