What's new

Breaking scripts into reusable classes

bolsover

Senior Member
Hi Nate, Stefan

I think the current script works well for wheels (horological for gear) having a tooth count > 12.
For pinions (generally small gears < = 12 leaves (leaf is horological for tooth)), there are some extra rules regarding tooth angle, addendum and addendum radius. Also, the dedendum of the wheel is sometimes adjusted to allow some extra 'slop' in the gearing.

You may have wondered why the pinion count is included in the input. It's because there is an interdependence between wheel and pinion - if you look at CycloidalGear.addendum_factor(), you'll notice reference to pinion_count.

I do intend to update the scripts with the above in mind but I'm in no great rush since the clock I'm building uses lantern pinions where the leaves are actually small pieces of blued pinion steel..

Screenshot 2021-01-29 144948.jpg Screenshot 2021-01-29 151033.jpg

Once I'm completely happy with the scripts I post again. Ultimate goal has to be to draw both wheel and pinion and add these to an assembly... but may take some time.

Also, I will be including credits to Dr. Rainer Hessmer and Hugh Sparks whose earlier work provided much of the logic for my scripts.

Thanks for all your assistance.

David
 

NateLiquidGravity

Alibre Super User
Just a few things for python I thought I would mention.

You shouldn't put ; at the end of a line. Python uses whitespace. A newline is enough for a new line.

Python variable names are case sensitive so be careful of capitalization. For example these will all be different variables:
tacocat = 1
Tacocat = 2
TacoCat = 3
TACOCAT = 4

For the record though I'm not looking at your code at the moment - so I'm just going by memory for the names in the rest of this.

You don't need to use a get/set function to simply get/set parameters of an object unless you need to override something. For example point.GetX() in this would be the same as using point.x

Similarly overriding __getattribute__ is unnecessary if you aren't overriding anything when it's being called. It exists by default.

Python has no private variables, methods or parameters. It's sort of on the honor system for programmers to avoid using things that start with a single _ or double __ underscore so they don't mess up other people's code, but sometimes it's necessary. There are much better explanations out there for this.

However Python does have variable scope that is important to understand. I tested and explained things here: https://www.alibreforum.com/forum/index.php?threads/explaining-python-variable-scope.20738/
 

bolsover

Senior Member
Hi Nate

Thanks for this - particularly the info re private variables... eek - dreadful security risk!
I'm quite used to programming using a strongly typed language but some habits are hard to break - like ; at the end of a statement.

I found a few bits of info re naming conventions.. Not sure I'm following all of this was helpful:.

module_name, package_name, ClassName, method_name, ExceptionName, function_name, GLOBAL_CONSTANT_NAME, global_var_name, instance_var_name, function_parameter_name, local_var_name.

I have a lot to learn - like what is the difference between a Method and a Function in Python? From what I can see, a function does not reference (self) whereas a method does. Functions appear to be private to a class whereas Methods are always public?

I have made a number of improvements to my script. Attached.

Quite a bit of the coding was actually done using Jetbrains PyCharm (I have been using IntelliJ for several years). It makes changing variable and method names a breeze and also helps with formatting. Unfortunately I've not managed to get it working with the compiled Alibre libraries - but it is still way better than using the Alibre interface.

I also have dotPeek which allows introspection of the compiled Alibre .dll libraries. There are many interesting questions.

Have a good day. David
 

Attachments

  • CycloidalGearGenerator.zip
    49 KB · Views: 3

vec

Member
If I want to define a specific polyline in alibre script, I construct the list of points first in python spyder. So I can see the variables, use plot and debug more quickly. Of course alibre functions do not work in python, but i put these at the end of my script later.
(custom) function can be defined in the same way as in python.
 
Top