Untitled
Anonymous
python
03/02/2026 7:16 PM
16.7 KB
20
Indexable
# -*- coding: mbcs -*-
from abaqus import *
from abaqusConstants import *
import __main__
import math
def Test2():
import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
# ---- PARAMETERS ----
R = 0.68
angle_deg = 60.0
# --------------------
angle_rad = math.radians(angle_deg)
y_center = 4.0 + R
x1 = R * math.sin(angle_rad)
y1 = y_center - R * math.cos(angle_rad)
x2 = x1 + (5.0 - y1) / math.tan(angle_rad)
# --- Draw half sketch ---
s1 = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
g, v, d, c = s1.geometry, s1.vertices, s1.dimensions, s1.constraints
s1.setPrimaryObject(option=STANDALONE)
s1.ConstructionLine(point1=(0.0, -100.0), point2=(0.0, 100.0))
s1.FixedConstraint(entity=g[2])
s1.ArcByCenterEnds(
center=(0.0, y_center),
point1=(x1, y1),
point2=(0.0, 4.0),
direction=CLOCKWISE
)
s1.Line(point1=(x1, y1), point2=(x2, 5.0))
s1.Line(point1=(x2, 5.0), point2=(10.0, 5.0))
s1.HorizontalConstraint(entity=g[5], addUndoState=False)
s1.ArcByCenterEnds(center=(10.0, 85.0), point1=(37.84, 10.0), point2=(10.0,
5.0), direction=CLOCKWISE)
s1.CoincidentConstraint(entity1=v[6], entity2=g[5], addUndoState=False)
s1.Line(point1=(37.84, 10.0004099989494), point2=(37.84, 0.0))
s1.VerticalConstraint(entity=g[7], addUndoState=False)
s1.Line(point1=(37.84, 0.0), point2=(0.0, 0.0))
s1.HorizontalConstraint(entity=g[8], addUndoState=False)
s1.PerpendicularConstraint(entity1=g[7], entity2=g[8], addUndoState=False)
s1.Line(point1=(0.0, 0.0), point2=(0.0, 4.0))
s1.VerticalConstraint(entity=g[9], addUndoState=False)
s1.PerpendicularConstraint(entity1=g[8], entity2=g[9], addUndoState=False)
s1.setAsConstruction(objectList=(g[9], ))
# --- Create centerline before mirroring ---
s1.ConstructionLine(point1=(0.0, 0.0), point2=(37.84, 0.0))
s1.HorizontalConstraint(entity=g[10], addUndoState=False)
s1.CoincidentConstraint(entity1=v[9], entity2=g[10], addUndoState=False)
s1.CoincidentConstraint(entity1=v[8], entity2=g[10], addUndoState=False)
s1.sketchOptions.setValues(constructionGeometry=ON)
s1.assignCenterline(line=g[10])
# --- Mirror the sketch ---
s1.copyMirror(mirrorLine=g[2], objectList=(g[3], g[4], g[5], g[6], g[7], g[8], g[9]))
# --- Create part from revolved sketch ---
p = mdb.models['Model-1'].Part(name='Part-1', dimensionality=THREE_D,
type=DEFORMABLE_BODY)
p = mdb.models['Model-1'].parts['Part-1']
p.BaseSolidRevolve(sketch=s1, angle=360.0, flipRevolveDirection=OFF)
s1.unsetPrimaryObject()
del mdb.models['Model-1'].sketches['__profile__']
print('Created: Part-1 with R = ' + str(R))
# --- Circle partition on end face ---
f, e, d2 = p.faces, p.edges, p.datums
t = p.MakeSketchTransform(sketchPlane=f[2], sketchUpEdge=e[4],
sketchPlaneSide=SIDE1, origin=(37.84, 0.0, 0.0))
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__',
sheetSize=94.46, gridSpacing=2.36, transform=t)
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.setPrimaryObject(option=SUPERIMPOSE)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
s.CircleByCenterPerimeter(center=(0.0, 0.0), point1=(1.5, 0.0))
f = p.faces
pickedFaces = f.getSequenceFromMask(mask=('[#4 ]', ), )
e1, d1 = p.edges, p.datums
p.PartitionFaceBySketch(sketchUpEdge=e1[4], faces=pickedFaces, sketch=s)
s.unsetPrimaryObject()
del mdb.models['Model-1'].sketches['__profile__']
# --- Partition cells along circle ---
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[0], edges=(e[8], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[1], edges=(e1[10], ))
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[2], edges=(e[12], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[3], edges=(e1[14], ))
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[4], edges=(e[8], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[5], edges=(e1[8], ))
# --- Datum axis and planes ---
p.DatumAxisByPrincipalAxis(principalAxis=XAXIS)
d1 = p.datums
axis_key = d1.keys()[-1]
p.DatumPlaneByPrincipalPlane(principalPlane=YZPLANE, offset=0.0)
d2 = p.datums
yz_key = d2.keys()[-1]
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#4 ]', ), )
p.PartitionCellByDatumPlane(datumPlane=d2[yz_key], cells=pickedCells)
# --- Extrude edge partition ---
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ff ]', ), )
e, d1 = p.edges, p.datums
p.PartitionCellByExtrudeEdge(line=d1[axis_key], cells=pickedCells,
edges=(e[9], ), sense=REVERSE)
# --- XY and XZ plane partitions ---
p.DatumPlaneByPrincipalPlane(principalPlane=XYPLANE, offset=0.0)
p.DatumPlaneByPrincipalPlane(principalPlane=XZPLANE, offset=0.0)
d2 = p.datums
xy_key = d2.keys()[-2]
xz_key = d2.keys()[-1]
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ffff ]', ), )
p.PartitionCellByDatumPlane(datumPlane=d2[xy_key], cells=pickedCells)
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ffffffff ]', ), )
d1 = p.datums
p.PartitionCellByDatumPlane(datumPlane=d1[xz_key], cells=pickedCells)
session.viewports['Viewport: 1'].setValues(displayedObject=p)
print('Partitioned: Part-1')
def testtest3():
import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
# ---- PARAMETERS ----
angle_deg = 60.0
R_start = 0.4
R_stop = 0.8
n = 4
R_values = [R_start + i * (R_stop - R_start) / (n - 1) for i in range(n)]
# --------------------
angle_rad = math.radians(angle_deg)
for i, R in enumerate(R_values):
formatted = '{:.2f}'.format(R).replace('.', '_')
part_name = 'Part-R' + formatted[:-1] + '_' + formatted[-1]
y_center = 4.0 + R
x1 = R * math.sin(angle_rad)
y1 = y_center - R * math.cos(angle_rad)
x2 = x1 + (5.0 - y1) / math.tan(angle_rad)
# --- Draw half sketch ---
s1 = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
g, v, d, c = s1.geometry, s1.vertices, s1.dimensions, s1.constraints
s1.setPrimaryObject(option=STANDALONE)
s1.ConstructionLine(point1=(0.0, -100.0), point2=(0.0, 100.0))
s1.FixedConstraint(entity=g[2])
s1.ArcByCenterEnds(
center=(0.0, y_center),
point1=(x1, y1),
point2=(0.0, 4.0),
direction=CLOCKWISE
)
s1.Line(point1=(x1, y1), point2=(x2, 5.0))
s1.Line(point1=(x2, 5.0), point2=(10.0, 5.0))
s1.HorizontalConstraint(entity=g[5], addUndoState=False)
s1.ArcByCenterEnds(center=(10.0, 85.0), point1=(37.84, 10.0), point2=(10.0,
5.0), direction=CLOCKWISE)
s1.CoincidentConstraint(entity1=v[6], entity2=g[5], addUndoState=False)
s1.Line(point1=(37.84, 10.0004099989494), point2=(37.84, 0.0))
s1.VerticalConstraint(entity=g[7], addUndoState=False)
s1.Line(point1=(37.84, 0.0), point2=(0.0, 0.0))
s1.HorizontalConstraint(entity=g[8], addUndoState=False)
s1.PerpendicularConstraint(entity1=g[7], entity2=g[8], addUndoState=False)
s1.Line(point1=(0.0, 0.0), point2=(0.0, 4.0))
s1.VerticalConstraint(entity=g[9], addUndoState=False)
s1.PerpendicularConstraint(entity1=g[8], entity2=g[9], addUndoState=False)
s1.setAsConstruction(objectList=(g[9], ))
# --- Create centerline before mirroring ---
s1.ConstructionLine(point1=(0.0, 0.0), point2=(37.84, 0.0))
s1.HorizontalConstraint(entity=g[10], addUndoState=False)
s1.CoincidentConstraint(entity1=v[9], entity2=g[10], addUndoState=False)
s1.CoincidentConstraint(entity1=v[8], entity2=g[10], addUndoState=False)
s1.sketchOptions.setValues(constructionGeometry=ON)
s1.assignCenterline(line=g[10])
# --- Mirror the sketch ---
s1.copyMirror(mirrorLine=g[2], objectList=(g[3], g[4], g[5], g[6], g[7], g[8], g[9]))
# --- Create part from revolved sketch ---
p = mdb.models['Model-1'].Part(name=part_name, dimensionality=THREE_D,
type=DEFORMABLE_BODY)
p = mdb.models['Model-1'].parts[part_name]
p.BaseSolidRevolve(sketch=s1, angle=360.0, flipRevolveDirection=OFF)
s1.unsetPrimaryObject()
del mdb.models['Model-1'].sketches['__profile__']
print('Created: ' + part_name + ' with R = ' + str(R))
# --- Circle partition on end face ---
f, e, d2 = p.faces, p.edges, p.datums
t = p.MakeSketchTransform(sketchPlane=f[2], sketchUpEdge=e[4],
sketchPlaneSide=SIDE1, origin=(37.84, 0.0, 0.0))
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__',
sheetSize=94.46, gridSpacing=2.36, transform=t)
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.setPrimaryObject(option=SUPERIMPOSE)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
s.CircleByCenterPerimeter(center=(0.0, 0.0), point1=(1.5, 0.0))
f = p.faces
pickedFaces = f.getSequenceFromMask(mask=('[#4 ]', ), )
e1, d1 = p.edges, p.datums
p.PartitionFaceBySketch(sketchUpEdge=e1[4], faces=pickedFaces, sketch=s)
s.unsetPrimaryObject()
del mdb.models['Model-1'].sketches['__profile__']
# --- Partition cells along circle ---
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[0], edges=(e[8], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[1], edges=(e1[10], ))
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[2], edges=(e[12], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[3], edges=(e1[14], ))
c1 = p.cells
e = p.edges
p.PartitionCellByPatchNEdges(cell=c1[4], edges=(e[8], ))
c2 = p.cells
e1 = p.edges
p.PartitionCellByPatchNEdges(cell=c2[5], edges=(e1[8], ))
# --- Datum axis and planes ---
p.DatumAxisByPrincipalAxis(principalAxis=XAXIS)
d1 = p.datums
axis_key = d1.keys()[-1]
p.DatumPlaneByPrincipalPlane(principalPlane=YZPLANE, offset=0.0)
d2 = p.datums
yz_key = d2.keys()[-1]
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#4 ]', ), )
p.PartitionCellByDatumPlane(datumPlane=d2[yz_key], cells=pickedCells)
# --- Extrude edge partition ---
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ff ]', ), )
e, d1 = p.edges, p.datums
p.PartitionCellByExtrudeEdge(line=d1[axis_key], cells=pickedCells,
edges=(e[9], ), sense=REVERSE)
# --- XY and XZ plane partitions ---
p.DatumPlaneByPrincipalPlane(principalPlane=XYPLANE, offset=0.0)
p.DatumPlaneByPrincipalPlane(principalPlane=XZPLANE, offset=0.0)
d2 = p.datums
xy_key = d2.keys()[-2]
xz_key = d2.keys()[-1]
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ffff ]', ), )
p.PartitionCellByDatumPlane(datumPlane=d2[xy_key], cells=pickedCells)
c = p.cells
pickedCells = c.getSequenceFromMask(mask=('[#ffffffff ]', ), )
d1 = p.datums
p.PartitionCellByDatumPlane(datumPlane=d1[xz_key], cells=pickedCells)
print('Partitioned: ' + part_name)
session.viewports['Viewport: 1'].setValues(
displayedObject=mdb.models['Model-1'].parts[part_name])
Editor is loading...
Leave a Comment