Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SDETERS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sap API question, Are the parameter dimensions in SapModel.File.NewSolidBlock (3,3,1) capped at inches?

GJoeRMK

Structural
Aug 19, 2024
15
Hello, I have the following code:
import comtypes.client as cc
import os
def crear_losa_con_viguetas_sap2000():
"""
Crea un nuevo modelo en SAP2000 y genera:
- Losa de 3x6m, espesor 5cm (elementos sólidos).
- Viguetas de 15cm de peralte adicionales, separadas cada 0.40m.
"""
try:
SapObject = cc.GetActiveObject("CSI.SAP2000.API.SapObject")
attach_to_instance = True
print("Conectado a instancia existente de SAP2000.")
except:
SapObject = cc.CreateObject("CSI.SAP2000.API.SapObject")
attach_to_instance = False
print("No hay instancia de SAP2000 abierta. Creando una nueva...")
SapObject.ApplicationStart()
SapModel = SapObject.SapModel
SapModel.InitializeNewModel()
ret = SapModel.File.NewBlank()
if ret != 0:
print(f"Error al crear un nuevo modelo en blanco. Código de error: {ret}")
return
SapModel.SetPresentUnits(6)
nombre_material = "Concrete210"
# Primero, define el material. Si ya existe, se modificará. Si no, se creará.
ret = SapModel.PropMaterial.SetMaterial(nombre_material, 2) # 2 para concreto
print(f"Estado de creación/modificación del material: {ret}")
if ret != 0:
print("Error al crear/modificar el material")
return
E_concreto = 2.1e10
nu_concreto = 0.2
peso_volumetrico = 23500.0
coeficiente_termico = 5.5e-6 # Agregado coeficiente térmico. Valor de ejemplo.
ret = SapModel.PropMaterial.SetMPIsotropic(nombre_material, E_concreto, nu_concreto, coeficiente_termico)
if ret != 0:
print("Error al asignar propiedades isotrópicas del material")
return
nombre_prop_solido = "SolidoConcreto210"
ret = SapModel.PropSolid.SetProp(nombre_prop_solido, nombre_material, 0.0, 0.0, 0.0, True)
print(f"Estado de creación de la propiedad de sólido: {ret}")
if ret != 0:
print("Error al crear propiedad de sólido")
return
print("Material y propiedades definidas correctamente.")
# 6) Parámetros geométricos
largo_x = 3.0 # m
largo_y = 6.0 # m
espesor_losa = 0.05 # 5 cm
peralte_vigueta = 0.15 # 15 cm
separacion_viguetas = 0.40 # 40 cm
ancho_vigueta = 0.10 # 10 cm (ajústalo si necesitas otro ancho)
# 7) Definimos subdivisiones de la losa (para un mallado más refinado)
nx = 6 # subdivisiones en X
ny = 12 # subdivisiones en Y
dx = largo_x / nx
dy = largo_y / ny
# 7.1) Creamos bloques sólidos para la LOSA (3 x 6 x 0.05)
contador_solidos = 0
for ix in range(nx):
for iy in range(ny):
x1 = ix * dx
x2 = (ix + 1) * dx
y1 = iy * dy
y2 = (iy + 1) * dy
# z top = 0, z bottom = -espesor_losa
z_top = 0.0
z_bot = -espesor_losa
# Ocho puntos del paralelepípedo
X = [x1, x2, x2, x1, x1, x2, x2, x1]
Y = [y1, y1, y2, y2, y1, y1, y2, y2]
Z = [z_top, z_top, z_top, z_top, z_bot, z_bot, z_bot, z_bot]

# Crea el sólido en SAP2000
ret = SapModel.SolidObj.AddByCoord(X, Y, Z, "" , nombre_prop_solido)
print(f"Estado de la losa : {ret}" )
if ret[4] != 0:
print(f"Error al crear sólido de losa. Código de error: {ret}")
return

contador_solidos += 1
SapModel.SetPresentUnits(6)
# Linea de prueba
ret = SapModel.File.NewSolidBlock(8, 8, 4,"" ,nombre_prop_solido, 4, 4, 2)
print(ret)
ret = SapModel.SolidObj.Count()
print(f"Número total de sólidos en el modelo: {ret}")

# Refrescar vista
ret = SapModel.View.RefreshView(0, False)
# 7.2) Creamos bloques sólidos para las VIGUETAS
# Desde z = -espesor_losa hasta z = -(espesor_losa + peralte_vigueta)
# en posiciones separadas cada 0.40 m en X
z_inicial_vigueta = -espesor_losa
z_final_vigueta = -(espesor_losa + peralte_vigueta)
x_actual = 0.0
while x_actual < largo_x:
x1_v = x_actual
x2_v = x_actual + ancho_vigueta
# Verificamos que la vigueta no rebase la losa
if x2_v > largo_x:
break
# subdivisión en Y
for iy in range(ny):
y1 = iy * dy
y2 = (iy + 1) * dy
X = [x1_v, x2_v, x2_v, x1_v, x1_v, x2_v, x2_v, x1_v]
Y = [y1, y1, y2, y2, y1, y1, y2, y2]
Z = [
z_inicial_vigueta, z_inicial_vigueta, z_inicial_vigueta, z_inicial_vigueta,
z_final_vigueta, z_final_vigueta, z_final_vigueta, z_final_vigueta
]
ret = SapModel.SolidObj.AddByCoord(X, Y, Z, "Vigueta_Default", nombre_prop_solido)
print(f"Estado de las viguestas : {ret}" )
if ret[4] != 0:
print(f"Error al crear sólido de vigueta. Código de error: {ret}")
return
contador_solidos += 1
# Pasamos a la siguiente vigueta
x_actual += separacion_viguetas
print(f"Se han creado {contador_solidos} sólidos en total (losa + viguetas).")
# Refrescar vista
ret = SapModel.View.RefreshView(0, False)

ruta_guardado = os.path.join(os.path.dirname(__file__), "ModeloLosaViguetas.sdb")
ret = SapModel.File.Save(ruta_guardado)
if ret != 0:
print(f"Error al guardar el archivo. Código de error: {ret}")
return
print("Modelo guardado correctamente.")
if __name__ == "__main__":
crear_losa_con_viguetas_sap2000()
That exact sections where I have questions is here:
ret = SapModel.File.NewSolidBlock(8, 8, 4,"" ,nombre_prop_solido, 4, 4, 2)

If I set the units to inches:
SapModel.SetPresentUnits(1)

Everything is normal and work as expected, but if I use anything but inches (meters)
SapModel.SetPresentUnits(6)

The dimensions of the solid block doesn't correspond with the values I expected.

What would SAP API work like this? I dont wanna hard code units
 
Replies continue below

Recommended for you

This code is working for me:


Python:
import comtypes.client
import math
import matplotlib.pyplot as plt

#boiler plate code to attach to the SAP model
SapObject=comtypes.client.GetActiveObject("CSI.SAP2000.API.SapObject")
SapModel = SapObject.SapModel

#units = 1 #this is for lbs, inch,
units = 6 #this is for kN, m,


x = SapModel.InitializeNewModel(units)
nombre_prop_solido = "SolidoConcreto210"
size = 8;
ret = SapModel.File.NewSolidBlock(size, size, size,"" ,nombre_prop_solido, size, size, size)

inches.png


Switching between 1 and 6 for "units" correctly updates the solid block
 
Thank you so much, I realize SapModel.File.NewSolidBlock() creates a new file , I was expecting to add solid objects to an existing file, that explains many questions I had.

The documentation says:
1743482788207.png
Which made me think it creates a solid object and everything should be good, but looking at similiar cousin calls (just for curiosity), it clearly states that it only should be use for creating a new model and every other "NewBeam" "NewWall" say the same, and so I realize "NewSolid" probably is going in the same patter and Eureka! Everything starting with "New..." is related at least with a creation of a new file
1743482850578.png

Oh my, I invest some hours but finally I got my answer. Hopefully this post helps somebody else. Cheers
 

Part and Inventory Search

Sponsor