CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [Other] Spaceclaim automatic body generator (https://www.cfd-online.com/Forums/ansys-meshing/255015-spaceclaim-automatic-body-generator.html)

Sonenzon March 14, 2024 06:31

Spaceclaim automatic body generator
 
Hello,

TL;DR: I wish to write a python script which creates box bodies from their x,y,z dimensions and centroid locations - [Xdim,Ydim,Zdim] and [Xloc,Yloc,Zloc], in relation to a local origin .

I tried to use
BlockBody.Create(Point.Create(MM(0), MM(0), MM(0)), Point.Create(MM(Ydim), MM(Xdim), MM(Zdim))
but it creates the box according to translation and orientation of the global origin

Relocating the box afterwards becomes problematic because the relation, both translation and orientation, between the local and global origin must be calculated. It can be a possible solution but I neither want to do it manually nor know how to do it automatically using scripting

thank you in advance,
Sonenzon

Sonenzon March 19, 2024 05:47

[Solved]
 
In case anyone in the future might find this topic useful :)

Given the following data:
- Position of centroid [Xpos, Ypos, Zpos]
- Dimensions of a box [Xdim, Ydim, Zdim]
- local cordinate system named 'local_sys'

Code:

# Box Position
Xpos=69.3
Ypos=39.5
Zpos=float(2.94)

# Components Dimensions
Xdim=float(11.09)
Ydim=float(10.61)
Zdim=float(0.6)

#Creating rectengular sketch of the box in the local origin plane "local_sys" and tranlation to the bottom face of the box = Zpos - Zdim/2
# Set sketch plane
result = ViewHelper.SetSketchPlane(Selection.CreateByNames("local_sys"),None)
axis = HandleAxis.Z
distance = MM(Zpos - Zdim/2)
# Create surface
result = ViewHelper.TransformSectionPlaneAlongAxis(axis, distance)
point1 = Point2D.Create(MM(Xpos - Xdim/2),MM(Ypos - Ydim/2))
point2 = Point2D.Create(MM(Xpos + Xdim/2),MM(Ypos - Ydim/2))
point3 = Point2D.Create(MM(Xpos + Xdim/2),MM(Ypos + Ydim/2))
result = SketchRectangle.Create(point1, point2, point3)
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, None))

# Extruding box according to Zdim
j = GetRootPart().Bodies
#Selects the newest body added to the design, which the surface of the box that needed to be extruded
selection = FaceSelection.Create(GetRootPart().Bodies[j.Count-1].Faces[0])
options = ExtrudeFaceOptions()
options.ExtrudeType = ExtrudeType.ForceIndependent
result = ExtrudeFaces.Execute(selection, MM(Zdim), options)



All times are GMT -4. The time now is 05:52.