Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everybody,
First, this is my first code and I'm absolutely not familiar with this. I'm trying to do a Patch feature with multiple curves & lines but I don't understand why the feature doesn't work. When I do it manually in the software it works so it's not about unconnected edges.
I'm using a ObjectCollection and putting everythink inside, may someone know what I'm doing wrong ?
Thank you !
import traceback
import adsk.core
import adsk.fusion
import math
app = adsk.core.Application.get()
ui = app.userInterface
def run(_context: str):
try:
#OUTILS#
design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
sketches = rootComp.sketches
planes = rootComp.constructionPlanes
origin = adsk.core.Point3D.create(0,0,0)
patches = rootComp.features.patchFeatures
#1# Création des UP + importation
diam = str("Diametre")
mmUnit = str("mm")
diamExpression = ui.inputBox("Saisir le diamètre (en " + mmUnit + "):",diam,"200")
diamExpressionReal = adsk.core.ValueInput.createByReal(float(diamExpression[0])/10)
design.userParameters.add(diam,diamExpressionReal,mmUnit,"Diamètre exterieur")
diametre = design.userParameters.itemByName("Diametre")
radius = float(diamExpression[0])/10/2
#2# Création des cercles de jonction
planeInput = planes.createInput()
XY = rootComp.xYConstructionPlane
YZ = rootComp.yZConstructionPlane
XZ = rootComp.xZConstructionPlane
plane =[XY,YZ,XZ]
#Plans
offset_rail_plane =[]
offset_values = [-diametre.value,diametre.value,diametre.value]
for i in range (3):
planeInput.setByOffset(plane[i],adsk.core.ValueInput.createByReal(offset_values[i]))
offset_rail_plane.append(planes.add(planeInput));
#Cercles
cercles = [offset_rail_plane[0],offset_rail_plane[1],offset_rail_plane[2]]
patchAvant = adsk.core.ObjectCollection.create()
for i in range(3) :
sketch = sketches.add(cercles[i])
sketch.sketchCurves.sketchArcs.addByCenterStartEnd(origin,adsk.core.Point3D.create(radius,0,0),adsk.core.Point3D.create(0,radius,0))
patchAvant.add(sketch.sketchCurves.item(0))
#3# Création des rails
for i in range(3):
#rails petits
sketch = sketches.add(plane[i])
cos45_small = -(math.sqrt(2)/2)*(diametre.value/4)
small_rail_O = adsk.core.Point3D.create(diametre.value*0.75,diametre.value,0)
small_rail_A = adsk.core.Point3D.create(diametre.value*0.5,diametre.value,0)
small_rail_B = adsk.core.Point3D.create(diametre.value*0.75+cos45_small,diametre.value+cos45_small,0)
small_rail_OO = adsk.core.Point3D.create(diametre.value,diametre.value*.75,0)
small_rail_C = adsk.core.Point3D.create(diametre.value+cos45_small,diametre.value*0.75+cos45_small,0)
small_rail_D = adsk.core.Point3D.create(diametre.value,diametre.value*.5,0)
sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_O,small_rail_A,small_rail_B)
sketch.sketchCurves.sketchLines.addByTwoPoints(small_rail_B,small_rail_C)
sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_OO,small_rail_C,small_rail_D)
patchAvant.add(sketch.sketchCurves.item(0))
patchAvant.add(sketch.sketchCurves.item(1))
patchAvant.add(sketch.sketchCurves.item(2))
#Patch avant
patchInput = patches.createInput(patchAvant,adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
patches.add(patchInput);
ui.messageBox(f'"{app.activeDocument.name}" is the active Document.')
except: #pylint:disable=bare-except
# Write the error message to the TEXT COMMANDS window.
app.log(f'Failed:\n{traceback.format_exc()}')
Solved! Go to Solution.