Dino's experience with 3D graphic:
I am an ICT teacher at a Secondary Technical School in Palermo (Sicily-Italy) – ITI VITTORIO EMANUELE III
My adventure with Fusion 360 started very recently. It started in June 2016 with a course held by Dario Passariello (aka @passariello) of Digital3D who is an Autodesk Academic Partner, Certified Instructor and Expert Elite member.
This year Digital3D has already organized numerous workshops on Autodesk software for the students of the School; in particular it has organized a specialized course on Fusion 360 for the students of the fifth classes of mechanical specialization. This is where my adventures with Fusion 360 began.
The Fusion 360-Python Chakra project: An introduction
The project deals with the development of a Python script (my first experience of it) and uses the Fusion 360 API. All the topics are new to me and you have to consider this project as my first approach to 3D graphics issues and use of Fusion 360 API. This product must be considered from an exclusively didactic point of view and aimed to learn the basics of programming in Python with the use of API.
It all begins with this picture:
It represents the Mandala of the seventh Chakra: Sahasrara – ‘The chakra of a thousand petals’. Those not familiar with the esoteric aspects of the spiritual power of the human being can follow it as an artistic construction. The idea is to project this picture to a spherical cap like a decoration on a dome.
The first sketch: concentric circles
The first step has been to create a ‘sketch’ on the XZ plane with a set of circles. The radius of the circles are calculated according to a function derived from the observation of the original image and from the interpolation of these points following a second degree polynomial regression. Therefore these circles do not have a radius which decreases linearly.
This is the formula of the radius variation with the circle index
Y = 4.386161 + 0.207791 * X + 0.143117 * X^2
X=circle index | Y=radius
The first sketch: triangles and splines
The goal of the making of the sketch on the XZ plane is to build the definition curves of the triangles that make up the figure. Although we speak about triangles, please note that the sides of each triangle are not segments: the side in common with the circumference is in fact an arc, and the other two sides are curves.
As you can see from fig. 3, the ‘triangles’ are inside the concentric circumferences and they alternate as follows: one (black) is with the vertex towards the center and the next (white) is with the vertex towards the periphery. The vertices of the triangles are at the intersection between the radius of the circles and the circumferences. The angle with which every radius progresses depends on the number of circles we have chosen inside the code (n). This number, multiplied by two, is equal to the number of triangles for each circle.
Fig 4: Intersections of lines and circumferences
The coordinates of the triangles vertices are calculated according to the solution of the system of equation of the line passing through the axis origin and the one of the circle. The angular coefficient of the line is related with the angle which the line forms with x-axis. Using the analytic geometry formulas we can find the coordinates of each point.
# considering a xy plane
# equation of circle with radius r and center in (0,0): x^2+y^2=r^2
# equation of the line passing through the origin: y = mx
# m = tan (alpha)
# coordinates of the intersection point = system solution of the two equations :
# x^2+y^2=r^2
# y=mx
# solution:
# x = sqrt( r^2 / ( 1+m^2 ) )
# y = x * m
Points coordinates formulas
We build a loop which scans all the circles, from the more 'internal’ one to the more 'external’ and for every step we increment the angle of the line passing through the origin. All the intersection points create a curve which resembles a helix portion and can be considered as a spline on Fusion sketch.
Fig 5: Single spline
If we proceed counterclockwise and we scan every step of the ‘n’ number, we construct a set of independent splines. The same happens if we proceed in the opposite way.
Fig 6: counterclockwise splines
The intersections of all the splines build the set of all the triangles of the picture. The work is almost complete !
Fig 7: All the counterclockwise and clockwise splines
Selection
The next step is to manage to select all the triangles connected to each circumference, choosing only those which have the third vertex inside the circumference and leaving aside the triangles which have the third vertex outside the circumference.
Fig 8: Wrong selection
Fig 9: Correct selection
To make that selection the ‘API and Script’ Fusion 360 forum has been consulted, which was of great help. The reason was that the selection required the use of API which deals with profiles, loops and curves belonging to loops.
It was a critical part of the script and I have to warmly thank ‘liujac’ (Jack) who has brilliantly solved the issue allowing me to learn more about Fusion API. The script functions which return the collection of properly selected triangles, are findProfiles() and isInsideCircle(), written by Jack.
The second sketch
Now we have to define a sketch, built on the XY plane, in which we have to create a profile for the projection of each set of triangles on a spherical cap.
Fig 10: Sketch 2 profile
The side on x-axis is as long as the radius of the more external circle, the side on the y-axis is arbitrarily chosen as a half of the other side. The thickness of the cap is defined in the script according to the variable ‘thickness’ and is arbitrary. The drawing of the arcs that close the profile depends on a calculation of analytic geometry that locates the center of the concentric circles which pass through A and B points. These circles have the center on the y-axis.
This center is represented by the C letter in the fig 10.
Fig. 11: Front view of sketch2 profile
REVOLVE
The profile will be used to perfom a REVOLVE operation and to create a solid of rotation.
Fig 12: Section of the solid of revolution
EXTRUDE and INTERSECT
Inside the script, we can EXTRUDE the triangles which belong to a circumference, by selecting them and make an operation of INTERSECTION with the solid of rotation created in the previous step.
Fig 13: Extrusion of the triangles of a selection
Fig 14: Intersection
Each extrusion of the triangles of a circumference, intersected with the solid of revolution which derives from the REVOLVE of sketch2, brings to one of the levels of the final solid
Fig 15: Example of a single body
Final result
Inserting each one of these operations in a loop and iterating it for each circumference, a separate body will be created and the set of all iterations will ‘construct’ the final result.
Fig 15: Final Result
Fig 16: Top view of final result
I have decided to create a separate ‘body’ for each revolution and each circle so that I can associate a texture and a color to each body. As a consequence we can have a color variant for the entire project in the RENDERING operation.
Fig 17: Bodies view
Fig 18: Rendering with different colors, different number of levels and different thickness
Conclusion
To simplify the project and to speed up its processing I have chosen to draw only 12 circles and 12 triangles per circumference. The final construction could use 32 circles and 32 triangles for each circumference: a total of 1024 triangles (as the ‘1000 petals’ Mandala). In this second case the processing could be rather difficult and a slow system could take longer processing times.
Python Scripting
The script developed in Python is not optimized and, to an expert Python programmer, it may appear 'rough', but for those who are beginners (like me) it may give an opportunity to study and to acquire new concepts and competences. The script does not provide any interaction with the user and it builds, in a single processing step, the whole final solid. The script is attached HERE and all suggestions, criticisms and proposals for error fixing and further improvements are welcome.
Due to space limitation, I have not added more details about the script in this document. However, I am happy to clarify any doubts about the development of the script which could be a starting point to write a more detailed tutorial about the topic.
Please reach out to me in the comments section below or PM me at Autodesk Forums. My username: @dinocoglitore
Many thanks, and hope you've enjoyed the article.
Namaste,
Dino Coglitore
Only PROUD! 🙂
This is impressive. Great job!
One thing to try adding to your code is to use the Sketch.isComputeDeferred property. As you add geometry and constraints to a sketch, Fusion is recomputing the position of geometry in the rest of the sketch and finding valid profiles within the sketch. Setting this property to True stops this computing from happening. You would set it to True, create all of the geometry in the sketch, and then set it back to False to allow the sketch to compute. This should noticeably improve the time it takes to construct the model.
Hi ekinsb,
I thank you for your comment and your suggestion. I will add the use of Sketch.isComputeDeferred in a new release of the script.
I did not know this property of the Sketch object. Your hint improve my Api knowledge and will reduce the script processing time.
Many thanks
Dino
Can you please re-upload the script. It says "This shared file or folder link has been removed or is unavailable to you."