CombineFeature Error while joining multiple bReps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I want the API to combine multiple, in the script created bRepBodies. So far I take a bRepBody, take a temporary copy, transform it (rotation of 1°) several times, want to combine these bodies and repeat this with another bRepBody from another occurrence.
The transformation works, but in the "combine_bodies" function an Error occurs:
For any reason the combineFeature combines all transformed bodies from the first occurrence AND the first transformed body from the second Occurrence, but the other bodies can't get combined.
(the selected on the right are the combined 36 bodies from the first occurrence, and the red/dark bodies are the uncombined from the second occurrence)
Here's the code I used:
### code in run:
test_occ = root.occurrences.addNewComponent(adsk.core.Matrix3D.create())
# occ_path is a list of occurrences
# j_list is a list of joints
for i in range(6):
occ = occ_path[i].bRepBodies.item(0) # works
rot_axis = j_list[i].jointMotion.rotationAxisVector # works
rot_origin = j_list[i].geometryOrOriginOne.origin # works
limits = {'min':get_joint_min_value(j_list[i], True),'max':get_joint_max_value(j_list[i], True),'cur':get_joint_curr_value(j_list[i], True)} # works
create_rotation_brep(tmpmgr.copy(occ), rot_axis, rot_origin, limits,test_occ, i)
def create_rotation_brep(temp_brep, rot_axis, rot_origin, rot_limits:dict, test_occ, index):
''' rotates a brepBody in the committed borders, combines the bodys of the occurrence to one
'''
cnt_bodies = 36
app = adsk.core.Application.get()
design = adsk.fusion.Design.cast(app.activeProduct)
design.designType = adsk.fusion.DesignTypes.DirectDesignType
test_comp= test_occ.component
body_coll = adsk.core.ObjectCollection.create()
# rotate temp_brep to minimum value
if not rot_limits['cur']==rot_limits['min']:
angleDiff = rot_limits['min'] - rot_limits['cur']
transform_brep(temp_brep, rot_axis, rot_origin, angleDiff)
rot_angle = (rot_limits['max'] - rot_limits['min'])/cnt_bodies
# rotate brep
for i in range(cnt_bodies):
test_comp.bRepBodies.add(temp_brep)
transform_brep(temp_brep, rot_axis, rot_origin, rot_angle)
# # fill obj-collection with created breps in the component
for body in test_comp.bRepBodies[1:]:
body_coll.add(body)
try:
combine_bodies(test_comp.bRepBodies[index], body_coll, test_comp)
except:
print('Error at create_rotation_brep')
def transform_brep(brep_body, axis:adsk.core.Vector3D, origin:adsk.core.Point3D, angle = (math.pi/180)):
''' transforms a brep-body by an angle (default: 1°) using TemporaryBrepManager '''
try:
tmpmgr = adsk.fusion.TemporaryBRepManager.get()
mat = adsk.core.Matrix3D.create()
mat.setToRotation(angle, axis, origin) # rotation matrix
tmpmgr.transform(brep_body, mat) # command to transform the body
except:
ui.messageBox('transform_brep error:\n {}'.format(traceback.format_exc()))
def combine_bodies(target, tool_collection, test_comp):
''' combines the tool_collection with the target-brep at the test_comp'''
start_time = time.time() # start time
comb_feature = test_comp.features.combineFeatures
comb_input = comb_feature.createInput(target, tool_collection)
comb_feature.add(comb_input)
end_time = time.time() # end time
elapsed_time = time.strftime('%H:%M:%S',time.gmtime(end_time-start_time))
ui.messageBox('Elapsed Time: ' + elapsed_time)
Can anyone help me, I'm really confused of this errormessage and can't figure a solution.