"Invalid entity" when defining a rotate move feature

"Invalid entity" when defining a rotate move feature

joe_m_ferner
Explorer Explorer
638 Views
2 Replies
Message 1 of 3

"Invalid entity" when defining a rotate move feature

joe_m_ferner
Explorer
Explorer

I'm trying to write some Python code to create a rotate move feature on a body.

 

center_axis = comp.constructionAxes[0]
mci = adsk.core.ObjectCollection.create()
mci.add(my_feature.bodies[0])
mi = comp.features.moveFeatures.createInput2(mci)
mi.defineAsRotate(center_axis, adsk.core.ValueInput.createByString("10 deg"))

When "defineAsRotate" is called I get "Runtime Error: 3 : Invalid entity"

 

If I instead call "defineAsTranslateXYZ" it does indeed translate the body. I have also manually rotated the feature using the UI selecting my body and construction axis and it works correctly.

 

I must be missing something on how I'm supposed to call "defineAsRotate"

 

Full code here: https://github.com/joeferner/YAGA/blob/master/commands/spur_gear/spur_gear.py#L566-L569  and yes I know about the built in spur gear add-in and various other add-ins, I'm trying to make my spur gear add-in completely parametric with some extra features.

0 Likes
Accepted solutions (1)
639 Views
2 Replies
Replies (2)
Message 2 of 3

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

I believe the issue is because you are using objects (axis entity and target body) from different components.

So you might need to supply the the rotation axis entity's proxy, instead of the object itself.

 

This is the code snippet I used to test it:

    comp = root.occurrences[1].component

    center_axis = root.occurrences[0].component.constructionAxes[0].createForAssemblyContext(root.occurrences[0])
    mci = adsk.core.ObjectCollection.create()
    mci.add(root.occurrences[1].bRepBodies[0])
    mi = comp.features.moveFeatures.createInput2(mci)
    mi.defineAsRotate(center_axis, adsk.core.ValueInput.createByString("10 deg"))
    comp.features.moveFeatures.add(mi)

 

Regards,

Jorge Jaramillo

Software Engineer

 

Message 3 of 3

joe_m_ferner
Explorer
Explorer

Thank you that did the trick with a little tweaking for my situation.

 

occurrence = comp.parentDesign.rootComponent.occurrencesByComponent(comp)[0]
center_axis = center_axis.createForAssemblyContext(occurrence)

 

It's weird I tried using "comp.occurrences" but that had length 0, going through the root design I was able to find it.

 

Full working example: https://github.com/joeferner/YAGA/blob/7508ae579650d30de0a052ee636684b2c1aec8a9/commands/spur_gear/s...

0 Likes