Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Invalid entity" when defining a rotate move feature

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
joe_m_ferner
109 Views, 2 Replies

"Invalid entity" when defining a rotate move feature

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.

2 REPLIES 2
Message 2 of 3

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
in reply to: joe_m_ferner

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...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report