A2plus - Trying to rotate constrained assembly using python script

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
vic_0311
Posts: 1
Joined: Thu Apr 06, 2023 4:44 pm

A2plus - Trying to rotate constrained assembly using python script

Post by vic_0311 »

New FreeCAD / A2plus user here.

I am trying to learn the A2plus workbench, and as a starting project I have created a simple assembly consisting of a base with a hole, and a crank which will rotate within said hole. Everything went well, I imported the individual parts into the assembly, and constrained them using a simple circularEdge constraint, I have attached the file for reference.

Now I am trying to create a simple animation by running a python script which will rotate the crank, following the example from the A2plus workbench: https://wiki.freecad.org/A2plus_Workben ... pt_Example. The script is made for the A2p_animated-example.FCStd which can be found on the page, which is a moving star wheel assembly.

I downloaded the script and modified line 14, to crank = document.getObject("Crank_001"), in order to reference the crank found in my assembly, and line 26, to crank.Placement.Rotation.Angle = math.radians(angle). However, when I attempt to run the script, I get the following error in line 26: <class 'AttributeError'>: 'NoneType' object has no attribute 'Placement'.

After doing some research, it seems that this error occurs when python is not able to find the referenced object required to execute the code. I tried renaming the object in my assembly, removing the "_", etc... however I always get the same error. It seems that the script will only work for the assembly attached in the wiki, is there anything I am missing, that I need to modify in order for the code to work with my assembly?

I have attached both my assembly and script I'm trying to use, any help would be greatly appreciated :D
Attachments
Moving Assembly.FCStd
(7.52 KiB) Downloaded 36 times
A2p_animation for moving assembly.py
(1.4 KiB) Downloaded 38 times
Post Reply