Message 1 of 4

Not applicable
10-08-2017
11:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having some issues with using the API to get as-built joint. Specifically:
1. Occurrence.asBuiltJoints seems to not be returning a joint that is present.
2. Component.allAsBuiltJoints seems to be returning joints whose .occurrenceOne and .occurrenceTwo have incorrect .assemblyContexts. (Even though the immediate joint.assemblyContext is correct).
3. While trying to demonstrate 2. in the following script, I'm getting an InternalValidationError that I don't think I should be getting.
import adsk.core, adsk.fusion def add_thingy(component, off=0): sketches = component.sketches xyPlane = component.xYConstructionPlane sketch = sketches.add(xyPlane) sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,off,0), 5.0) extInput = component.features.extrudeFeatures.createInput(sketch.profiles.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation) distance = adsk.core.ValueInput.createByReal(10.0) extInput.setDistanceExtent(False, distance) ext = component.features.extrudeFeatures.add(extInput) def make_test_doc(): # New document app = adsk.core.Application.get() doc = adsk.fusion.FusionDocument.cast(app.documents.add(0)) rootOccs = doc.design.rootComponent.occurrences # With a repeated component matrix = adsk.core.Matrix3D.create() newOcc = rootOccs.addNewComponent(matrix) newComp = newOcc.component for i in range(3): t = matrix.translation t.x += 10 matrix.translation = t rootOccs.addExistingComponent(newComp, matrix) # Put some stuff in that component matrix = adsk.core.Matrix3D.create() subOcc1 = newComp.occurrences.addNewComponent(matrix) subOcc2 = newComp.occurrences.addNewComponent(matrix) add_thingy(subOcc1.component, 0) add_thingy(subOcc2.component, 10) # And make an as-built joint between that stuff. abji = newComp.asBuiltJoints.createInput(subOcc1, subOcc2, None) abji.setAsRigidJointMotion() newComp.asBuiltJoints.add(abji) return doc from time import sleep def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface doc = make_test_doc() root = doc.design.rootComponent some_occ = root.occurrences[2] ui.messageBox("%d == %d. Those should be the same, right?" % ( some_occ.asBuiltJoints.count, # I'm getting 0 here, which misses the existing joint. some_occ.component.asBuiltJoints.count # I get 1 here, which is what I expect. )) # This next thing is causing some InternalValidationError here, which # seems like a seprate issue (unless I'm doing something wrong?) # The issue I was trying to demonstrate is it printing out # "joint.occ ctx: Component1:1" 4 times in a row, instead of # "Component1:1", "Component1:2", "Component1:3", "Component1:4" for joint in root.allAsBuiltJoints: ui.messageBox(""" joint context: %s ^ This seems correct, and steps through each relevant occurrences. joint.occ ctx: %s ^ This should be the same, but instead it's stuck on the same occurence. """ % ( joint.assemblyContext.name, joint.occurrenceOne.assemblyContext.name )) except: if ui: from traceback import format_exc ui.messageBox(format_exc(), "Exception", adsk.core.MessageBoxButtonTypes.OKButtonType, adsk.core.MessageBoxIconTypes.CriticalIconType)
Am I doing something wrong here, or have I encountered a bug?
If it helps: I'm using OS X, Fusion version 2.0.3410
Solved! Go to Solution.