Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I have a specific question.
I have a .step file of an assembly. I convert all the bodies to components. What happens is that the origin of each component is in the center of the assembly. What I want to do is move the bodies in such a way that the origin is in the middle of the component. After moving the body, I place the component back in its original position.
-->
-->
This works with the code I have, but I want to do this for each component, and this is where it goes wrong.
After I do the first one, where it succeeds, I move on to the second one, which also works, but at that moment, the first one moves back to the origin of the assembly.
elif action == 'repairDuplicates':
occs = rootComp.allOccurrences
# get the first occ out od data and find it by name
item = data[0]
data.pop(0)
occ_base = occs.itemByName(item)
# get the matrix from the occ
matrix3d_base = occ_base.transform2
position = matrix3d_base.translation
ref_coord = np.array(position.asArray()) # this is its original position
# get the boundingbox points of the body inside the occurence
occ_base_body = occ_base.bRepBodies.item(0)
body_bb = np.array([
[occ_base_body.boundingBox.minPoint.x, occ_base_body.boundingBox.minPoint.y, occ_base_body.boundingBox.minPoint.z],
[occ_base_body.boundingBox.maxPoint.x, occ_base_body.boundingBox.maxPoint.y, occ_base_body.boundingBox.maxPoint.z]
])
# calculate the midpoint of the body and the displacement that is needed
midpoint_1 = (body_bb[0] + body_bb[1]) / 2
displacement = ref_coord - midpoint_1
# now I add the body to a collection so we can do the move later.
bodies = adsk.core.ObjectCollection.create()
bodies.add(occ_base_body)
# Define a matrix that will move the body.
vector_body_move_to_origin = adsk.core.Vector3D.create(displacement[0], displacement[1], displacement[2])
transform_body = adsk.core.Matrix3D.create()
transform_body.translation = vector_body_move_to_origin
# Create a move feature
moveFeats = rootComp.features.moveFeatures
moveFeatureInput = moveFeats.createInput2(bodies)
moveFeatureInput.defineAsFreeMove(transform_body)
moveFeats.add(moveFeatureInput)
# Define a matrix that will move the occurrence to its original position
vector = adsk.core.Vector3D.create(midpoint_1[0], midpoint_1[1], midpoint_1[2])
mat: adsk.core.Matrix3D = matrix3d_base
mat.translation = vector
occ_base.transform2 = mat
Thank you!
Regards,
Nick
Solved! Go to Solution.