Message 1 of 4
Importing STEP files and moving to certain position, Invalid Entity?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I'm trying to automate importing STEP files and trying to move them to certain coordinates. I am able to get the .step files imported and get to the BRepBody instances that come in. I move them over to the root composition's bodies.
Here's the code where problems start occurring.
def reposition_pixel(self, coords, body):
app.log(f"{body.isValid=}, {body.objectType=}, {(body.parentComponent == root_comp)=}")
# Create a Move feature to move the body
object_collection = adsk.core.ObjectCollection.create()
app.log(f"{object_collection.isValid=}, {object_collection.count=}")
object_collection.add(body)
app.log(f"{object_collection.isValid=}, {object_collection.count=}")
origin_point = body.boundingBox.minPoint
destination_coord = [c * POS_MULT for c in coords]
# y came first, then x, because of how they were accessed
destination_point = adsk.core.Point3D.create(
destination_coord[1] * POS_MULT,
destination_coord[0] * POS_MULT * -1,
0,
)
move_input = root_comp.features.moveFeatures.createInput2(object_collection)
app.log(f"{move_input.isValid=}")
app.log(f"{origin_point.objectType=} {origin_point.isValid=}")
app.log(f"{destination_point.objectType=} {destination_point.isValid=}")
move_input.defineAsPointToPoint( # this is where the problem occurs
origin_point, destination_point,
)
root_comp.features.moveFeatures.add(move_input)
I get various log messages (something about my debugger is not working right now, so I'm using good ol' print debugging), and then I get a traceback.
body.isValid=True, body.objectType='adsk::fusion::BRepBody', (body.parentComponent == root_comp)=True
object_collection.isValid=False, object_collection.count=0
object_collection.isValid=False, object_collection.count=1
coord=(0, 6)
move_input.isValid=True
origin_point.objectType='adsk::core::Point3D' origin_point.isValid=True
destination_point.objectType='adsk::core::Point3D' destination_point.isValid=True
Failed:
Traceback (most recent call last):
File "/Users/username/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/Thing Creator/Thing Creator.py", line 40, in run
builder.build_thing_from_json_data()
File "/Users/username/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/Thing Creator/Thing Creator.py", line 79, in build_thing_from_json_data
self.reposition_pixel(pixel_info, pixel)
File "/Users/username/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/Thing Creator/Thing Creator.py", line 134, in reposition_pixel
move_input.defineAsPointToPoint(
File "/Users/username/Library/Application Support/Autodesk/webdeploy/production/bd07983cd9e69cddc8d92b9be6507c3dbbec9409/Autodesk Fusion.app/Contents/Api/Python/packages/adsk/fusion.py", line 36928, in defineAsPointToPoint
return _fusion.MoveFeatureInput_defineAsPointToPoint(self, originPoint, targetPoint)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 3 : Invalid entity
I can see that everything but the object collection is valid, and I have NO idea why not.
Is there a simpler way to just move a body from one defined point to another?