- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, I have two bits of code here that work by themselves but i cant seem to make them work together.
What I am hoping to create is to have the Voronoi pattern/randomised points created and then have spheres be created and moved to those points. Attached is a screen shot of the effect im looking to create.
Here are the two bits of code -
This one creates the randomised points -
import adsk.core, adsk.fusion, adsk.cam, traceback
import random
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
# Create a new sketch on the XY plane.
rootComp = design.rootComponent
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Parameters for the pattern
width = 100.0 # Width of the pattern area
height = 100.0 # Height of the pattern area
grid_spacing = 10.0 # Spacing between grid points
perturbation = 3.0 # Maximum random perturbation of points
# Generate grid points with random perturbations
points = []
num_x_points = int(width / grid_spacing) + 1
num_y_points = int(height / grid_spacing) + 1
for i in range(num_x_points):
for j in range(num_y_points):
x = i * grid_spacing + random.uniform(-perturbation, perturbation)
y = j * grid_spacing + random.uniform(-perturbation, perturbation)
points.append(adsk.core.Point3D.create(x, y, 0))
# Add points to the sketch
for point in points:
sketch.sketchPoints.add(point)
ui.messageBox('Pattern of points created successfully.')
except Exception as e:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
And this is the code that creates a sphere
import adsk.core, adsk.fusion, math, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = app.activeProduct
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the xy plane.
sketches = rootComp.sketches;
xyPlane = rootComp.xYConstructionPlane;
sketch = sketches.add(xyPlane)
# Draw a circle.
circles = sketch.sketchCurves.sketchCircles
circle = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
# Draw a line to use as the axis of revolution.
lines = sketch.sketchCurves.sketchLines
axisLine = lines.addByTwoPoints(adsk.core.Point3D.create(-3, 0, 0), adsk.core.Point3D.create(3, 0, 0))
# Get the profile defined by half of the circle.
prof = sketch.profiles.item(0)
# Create an revolution input to be able to define the input needed for a revolution
# while specifying the profile and that a new component is to be created
revolves = rootComp.features.revolveFeatures
revInput = revolves.createInput(prof, axisLine, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
# Define that the extent is an angle of 2*pi to get a sphere
angle = adsk.core.ValueInput.createByReal(2*math.pi)
revInput.setAngleExtent(False, angle)
# Create the extrusion.
ext = revolves.add(revInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I cant figure this out so any help would be so amazing.
Thanks so much 🙂
Solved! Go to Solution.