Strange joint behavior with parameterization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to script a parameterized assembly of several components.
All works well with the initial parameter settings, but when I change the parameter values some of the joints do not seem to follow the adjusted component geometry.
I've attached a distilled demo showing the problem. The simple demo creates two occurrences of single component, and joins them with a rigid joint located on one of the component vertices. After changing the User Parameter, I would expect the occurrences to still be joined by the corner, but this is not what happens.
Creating the same (at least I think it's the same) joint through the GUI results in expected behavior.
I would really appreciate some guidance on what I am doing wrong here, as it has be baffled 🙂
Thanks
import adsk.core, adsk.fusion, adsk.cam, traceback, math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
# Simple parameter to control the depth
value = adsk.core.ValueInput.createByString("600mm")
design.userParameters.add("Depth", value, design.unitsManager.defaultLengthUnits, "")
# Get the root component of the active design.
rootComp = design.rootComponent
transform = adsk.core.Matrix3D.create()
occ1: adsk.fusion.Occurrence = rootComp.occurrences.addNewComponent(transform)
comp = occ1.component
comp.name = "Comp"
# Create a new sketch on the xy plane.
sketches = comp.sketches
xyPlane = comp.xYConstructionPlane
sketch = sketches.add(xyPlane)
lines = sketch.sketchCurves.sketchLines
recLines = lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0),
adsk.core.Point3D.create(2, 90, 0))
# Get the profile
prof = sketch.profiles.item(0)
# Create an extrusion input
extrudes1 = comp.features.extrudeFeatures
extInput1 = extrudes1.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Set the distance extent
distance1 = adsk.core.ValueInput.createByString("Depth")
extInput1.setDistanceExtent(False, distance1)
# Create the extrusion
ext1 = adsk.fusion.ExtrudeFeature.cast(extrudes1.add(extInput1))
ext1.extentOne.distance.expression = "Depth"
# New occurance of same component
occ2 = rootComp.occurrences.addExistingComponent(comp, transform)
compJointFace: adsk.fusion.BRepFace = ext1.sideFaces.item(0)
compJointEdge: adsk.fusion.BRepEdge = compJointFace.edges.item(0)
face1 = compJointFace.createForAssemblyContext(occ1)
edge1 = compJointEdge.createForAssemblyContext(occ1)
face2 = compJointFace.createForAssemblyContext(occ2)
edge2 = compJointEdge.createForAssemblyContext(occ2)
geo0 = adsk.fusion.JointGeometry.createByPlanarFace(face1, edge1, adsk.fusion.JointKeyPointTypes.StartKeyPoint)
geo1 = adsk.fusion.JointGeometry.createByPlanarFace(face2, edge2, adsk.fusion.JointKeyPointTypes.StartKeyPoint)
jointInput: adsk.fusion.JointInput = rootComp.joints.createInput(geo1, geo0)
jointInput.setAsRigidJointMotion()
jointInput.angle = adsk.core.ValueInput.createByReal(math.pi/2)
joint: adsk.fusion.Joint = rootComp.joints.add(jointInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))