[Solved] Draft upgrade to wire

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: [Solved] Draft upgrade to wire

Post by jfc4120 »

@onekk

I have all solved. If it's an oblong elbow:

Case 1:

The miter is on the long part of oblong, then I just:

Code: Select all

STRT = STRT / math.cos(math.radians(DEG))
   ##### inches and degrees I work in#######
Case 2:

The miter is on short part of oblong, then The STRT value remains the same as input value.

I am also looking over your code. And thank you for sharing the different list techniques.

The original code I was only concerned with the elliptical polygon, and was an in work. Now I can tweak it to work with either elliptical polygons or elliptical circle parts. I do appreciate all the help and advice.

Just a side note, I have programmed all of this stuff in another language. I am just converting much of it to Freecad python and of course there are differences.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [Solved] Draft upgrade to wire

Post by onekk »

jfc4120 wrote: Fri Sep 23, 2022 5:04 pm ...
I am also looking over your code. And thank you for sharing the different list techniques.
It is only some more python compliant, code, in other word some rules taken from PEP8:

https://peps.python.org/pep-0008/


like the multiple imports and some order of imports, like standard Python module imported prior to FreeCAD modules, (I know this may seem only cosmetics, but it make the code more readable).

You could consider "my personal approach" not to use Gui and App as I prefer to have clear from which the module names are imported, with some exceptions, for "long name" modules.

To shorten code, I've found very useful to do:

Code: Select all

from FreeCAD import Placement, Rotation, Vector
and using maybe some placeholder like:

Code: Select all

VZOR = Vector(0, 0, 0)
ROT0 = Rotation(0, 0, 0)
RZ90 = Rotation(90, 0, 0)  # Rotation is specified as angles in this order ZYX (roughly a Tait-Bryant convention)
RY90 = Rotation(0, 90, 0)
RX90 = Rotation(0, 0, 90)
But note that if you evolve and use a proper editor that will enforce some PEP8 conventions with a linter like pylint or pyflake8 (most used ones), you will have to place a space after the comma, I use Emacs, that is an old dynosaur, other prefer to use VSCode or similar debranded versions, or Atom, or similar editor, but in the end I have found that Emacs, with some modification, is a very good alternative to most modern editors.

But Python could be even more complex than basic, so probably your code has some more space to be "optimized", but it has to be done "by steps", when you have a working code as example:

Code: Select all

    KOUNT = KOUNT + 1
    DEGREE = DEGREE + PART
    TODEGREE = DEGREE + PART
could be written as:

Code: Select all

    KOUNT += 1
    DEGREE += PART
    TODEGREE = DEGREE + PART
but KOUNT is not used so maybe as it depend on the M

Code: Select all

KOUNT =  M
will suffice, try maybe:

Code: Select all

   KOUNT = KOUNT + 1
   print(f"KOUNT: {KOUNT} >> M: {M}")
to see what I mean.

And take note that python has even the construct:

Code: Select all

if condition:
	do something
elif condition:
	do some other thing
else:
	do what is not in other cases
https://www.w3resource.com/python/pytho ... ements.php

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply