stepalibre
Senior Member

Stay tuned.

Introducing GPTs
You can now create custom versions of ChatGPT that combine instructions, extra knowledge, and any combination of skills.
openai.com
from AlibreScript import *
def create_base_plate_with_holes():
# Initialize a part session
part = CurrentPart()
# Define dimensions for the base plate and holes
plate_length = 100.0 # Length of the base plate
plate_width = 50.0 # Width of the base plate
plate_thickness = 5.0 # Thickness of the base plate
hole_diameter = 5.0 # Diameter of the holes
hole_offset = 10.0 # Offset of the holes from the edges
# Create a base plate
base_sketch = part.AddSketch('BasePlateSketch', part.XYPlane)
base_sketch.AddRectangle(-plate_width / 2, -plate_length / 2, plate_width / 2, plate_length / 2, False)
part.AddExtrudeBoss('BasePlate', base_sketch, plate_thickness, False, part.EndCondition.ToDepth, None, 0, part.DirectionType.Normal, None, 0, False)
# Create holes
for x in [-plate_width / 2 + hole_offset, plate_width / 2 - hole_offset]:
for y in [-plate_length / 2 + hole_offset, plate_length / 2 - hole_offset]:
hole_sketch = part.AddSketch('HoleSketch', part.XYPlane)
hole_sketch.AddCircle(x, y, hole_diameter / 2, False)
part.AddExtrudeCut('ThroughHole', hole_sketch, 0, False, part.EndCondition.ThroughAll, None, 0, part.DirectionType.Normal, None, 0, False)
# Save the part
#part.Save()
# Run the function to create a simple base plate with four holes
create_base_plate_with_holes()
import math
from AlibreScript import *
# Initialize the part session
part = CurrentPart()
# Assuming you have a part with an edge to chamfer.
# The edge can be obtained in various ways, depending on the context.
# Here's a generic way to get an edge, replace this with your specific method.
edges = part.GetEdges()
edge_to_chamfer = edges[0] # Assuming you want to chamfer the first edge in the list
# Define chamfer parameters
distance1 = 1 # The first chamfer distance
distance2 = 1 # The second chamfer distance (for unequal chamfer, otherwise set same as distance1)
# Add chamfer to the selected edge
part.AddChamfer("ChamferName", edge_to_chamfer, distance1, distance2, False)
# Regenerate the part to update the view
part.Regenerate()
import math
from AlibreScript import *
# Initialize the part session
part = CurrentPart()
# Define the dimensions of the bolt
hex_head_diameter = 10 # Diameter of the hex head
hex_head_height = 5 # Height of the hex head
shaft_diameter = 5 # Diameter of the shaft
shaft_length = 20 # Length of the shaft
# Create a hexagon sketch for the bolt head
hex_sketch = part.AddSketch("HexHeadSketch", part.XYPlane)
for i in range(6):
angle1 = math.radians(60 * i)
angle2 = math.radians(60 * (i + 1))
x1 = hex_head_diameter / 2 * math.cos(angle1)
y1 = hex_head_diameter / 2 * math.sin(angle1)
x2 = hex_head_diameter / 2 * math.cos(angle2)
y2 = hex_head_diameter / 2 * math.sin(angle2)
hex_sketch.AddLine([x1, y1], [x2, y2], False)
# Extrude the hex head
hex_head = part.AddExtrudeBoss("HexHead", hex_sketch, hex_head_height, False)
# Create a circle sketch for the shaft
shaft_sketch = part.AddSketch("ShaftSketch", part.XYPlane)
shaft_sketch.AddCircle(0, 0, shaft_diameter / 2, False)
# Extrude the shaft
shaft = part.AddExtrudeBoss("Shaft", shaft_sketch, shaft_length, False)
# Regenerate the part to update the view
part.Regenerate()
import math
from AlibreScript import *
# Initialize the part session
part = CurrentPart()
# Fetch the standard planes
xy_plane = part.GetPlane("XY-Plane")
zx_plane = part.GetPlane("ZX-Plane")
# Create a profile sketch on the XY plane
profile_sketch = part.AddSketch("ProfileSketch", xy_plane)
# Add a circle to the profile sketch as the sweep profile
profile_sketch.AddCircle(0, 0, 2, False) # Center at (0,0), Radius = 2
# Create a path sketch on the ZX plane
path_sketch = part.AddSketch("PathSketch", zx_plane)
# Add a line to the path sketch as the sweep path
path_sketch.AddLine([0, 0], [10, 10], False) # Line from (0,0) to (10,10)
# Define parameters for the sweep boss
is_rigid = False
end_condition = part.EndCondition.EntirePath # Using EntirePath as the end condition
end_plane = None
end_offset = 0
draft_angle = 0 # No draft angle
outward_draft = False # No outward draft
# Add the sweep boss feature
part.AddSweepBoss("SweepBossFeature", profile_sketch, path_sketch, is_rigid, end_condition, end_plane, end_offset, draft_angle, outward_draft)
# Regenerate the part to update the view
part.Regenerate()
import math
from AlibreScript import *
# Initialize the part session
part = CurrentPart()
# Flange dimensions (in mm)
flangeDiameter = 565 # Flange outer diameter
flangeThickness = 30 # Flange thickness
pipeDiameter = 254 # 10 inches converted to mm for pipe
boltHoleDiameter = 40 # Bolt hole diameter
boltCircleDiameter = 175 # Bolt circle diameter
numberOfBoltHoles = 12
# Create main flange disc
flangeSketch = part.AddSketch('FlangeBase', part.XYPlane)
flangeSketch.StartEditing()
flangeSketch.AddCircle(0, 0, flangeDiameter / 2, False) # Center at (0,0)
flangeSketch.StopEditing()
flange = part.AddExtrudeBoss('FlangeDisc', flangeSketch, flangeThickness, False)
# Create bolt holes
for i in range(numberOfBoltHoles):
angle = 2 * math.pi * i / numberOfBoltHoles
x = boltCircleDiameter / 2 * math.cos(angle)
y = boltCircleDiameter / 2 * math.sin(angle)
boltHoleSketch = part.AddSketch('BoltHole', part.XYPlane)
boltHoleSketch.StartEditing()
boltHoleSketch.AddCircle(x, y, boltHoleDiameter / 2, False)
boltHoleSketch.StopEditing()
part.AddExtrudeCut('BoltHoleCut', boltHoleSketch, flangeThickness, False)
# Create center pipe hole
centerHoleSketch = part.AddSketch('CenterPipeHole', part.XYPlane)
centerHoleSketch.StartEditing()
centerHoleSketch.AddCircle(0, 0, pipeDiameter / 2, False)
centerHoleSketch.StopEditing()
part.AddExtrudeCut('CenterHoleCut', centerHoleSketch, flangeThickness, False)
print("10-inch pipe flange model created.")
import math
from AlibreScript import *
# Initialize the part session
part = CurrentPart()
# Nut dimensions (in mm)
threadDiameter = 10 # M10 thread
pitch = 1.5 # Typical pitch for M10
acrossFlats = 17 # Width across flats for M10
thickness = 8 # Nut thickness for M10
cornerRadius = 1 # Corner radius
# Number of sides for the hexagon
numSides = 6
# Create the base hexagonal profile
hexSketch = part.AddSketch('HexBase', part.XYPlane)
hexSketch.StartEditing()
# Calculate vertices for the hexagon
vertices = []
for i in range(numSides + 1): # +1 to close the hexagon
angle = 2 * math.pi * i / numSides
x = acrossFlats / (2 * math.cos(math.pi / numSides)) * math.cos(angle)
y = acrossFlats / (2 * math.cos(math.pi / numSides)) * math.sin(angle)
vertices.append([x, y])
# Add lines to create the hexagon
for i in range(numSides):
startX, startY = vertices[i]
endX, endY = vertices[i + 1]
hexSketch.AddLine(startX, startY, endX, endY, False) # Adding line using coordinates
hexSketch.StopEditing()
# Extrude the hexagon to form the nut body
nutBody = part.AddExtrudeBoss('NutBody', hexSketch, thickness, False)
# Create internal thread hole
threadHoleSketch = part.AddSketch('ThreadHole', part.XYPlane)
threadHoleSketch.StartEditing()
threadHoleSketch.AddCircle(0, 0, threadDiameter / 2, False)
threadHoleSketch.StopEditing()
part.AddExtrudeCut('ThreadHoleCut', threadHoleSketch, thickness, False)
print("M10 hex nut model created.")
from __future__ import division
to fix integer division in ironpython 2.7 or for example 5/2 will equal 2 instead of 2.5hole_sketch.AddCircle(x, y, hole_diameter / 2, False)
should be hole_sketch.AddCircle(x, y, hole_diameter, False)
as the AddCircle expects a diameter not a radius.Units.Current = UnitTypes.Millimeters
Units.Current = UnitTypes.Centimeters
Units.Current = UnitTypes.Inches