Ticket #4264 - Draft.makeArray Polar Array

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Ticket #4264 - Draft.makeArray Polar Array

Post by louisgag »

In the the Draft workbench, makeArray Python "constructor"-function does not allow direct construction of a polar array.
This bug does not show from the GUI because it always first makes an orthogonal array and then converts it.

I've created a bug report on the tracker and I am transcribing it here below.

I verified it on 0.19 and 0.18.4 but it probably also affects other earlier versions.

When in Python mode, trying to construct an array with a name using for example

Code: Select all

Draft.makeArray(App.getDocument('Unnamed').getObject('Cylinder'),App.Vector(0,0,0),360,4,"testArray")

from the function (line 1249 from Draft.py) does not allow to directly make a polar array with a name.

Indeed, the instructions in the code say

Code: Select all

makeArray(object,center,totalangle,totalnum,[name]) for polar array

but because of this part from the code:

Code: Select all

    elif arg4:
        obj.ArrayType = "ortho"
it forces any call with a non-null "arg4" argument (in this case the name of the array) to make an Orthogonal array, or when the arguments for are polar array are given to simply return an error about wrong argument type.

Here a simple example:
Make a new document, go to Part workbench, make a cylinder, go to python console, type:

Code: Select all

import Draft
Draft.makeArray(App.getDocument('Unnamed').getObject('Cylinder'),App.Vector(0,0,0),360,4,"testArray")
the results will be this error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/louis/local/Mod/Draft/Draft.py", line 1295, in makeArray
obj.IntervalY = arg2
TypeError: type must be 'Vector' or tuple of three floats, not int
because it thinks an ortho array is requested.

OS: Ubuntu 18.04.4 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.Unknown
Build type: Unknown
Python version: 2.7.17
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: C/Default (C)
Last edited by Kunda1 on Sun Feb 06, 2022 11:15 pm, edited 1 time in total.
Reason: Added ticket number to thread title
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [BUG]: Draft.makeArray Polar Array

Post by vocx »

louisgag wrote: Wed Feb 19, 2020 3:52 pm In the the Draft workbench, makeArray Python "constructor"-function does not allow direct construction of a polar array.
...
Making the creation of arrays more user friendly

The Draft_Array command is actually three arrays in one, so it is a bit complicated. It would be better to split them apart. What I mean is, the Draft._Array object is a single Proxy class which internally can behave like an orthogonal, polar, or circular array. Maybe it would be better to be a single Array class for the first type, a PolarArray class for the other, and a CircularArrray for the third. Then the arrays would be completely separate.

I built the Draft_PolarArray and Draft_CircularArray GUI commands, and in doing so I also provided new programming functions (make_polar_array, make_circular_array) that are located inside Draft/draftobjects/. Ideally the functions should be separated more, because these two just call the original makeArray.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [BUG]: Draft.makeArray Polar Array

Post by vocx »

louisgag wrote: Wed Feb 19, 2020 3:52 pm ...
Indeed, the instructions in the code say

Code: Select all

makeArray(object,center,totalangle,totalnum,[name]) for polar array
...
Just note that the "instructions" in the code are very often obsolete and thus do not correspond to the actual code. The code tells you how it really works. In this case, the documentation string, or "docstring", is obsolete and should be removed.

In particular, in Python you can access the arguments using key=value pairs.

This is what my function does, it is just an abstraction over the basic makeArray function.

https://github.com/FreeCAD/FreeCAD/blob ... py#L34-L42

Code: Select all

def make_polar_array(obj,
                     center=App.Vector(0, 0, 0), angle=180, number=4,
                     use_link=False):
    """Create a polar array from the given object.
    """
    obj = Draft.makeArray(obj,
                          arg1=center, arg2=angle, arg3=number,
                          useLink=use_link)
    return obj
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [BUG]: Draft.makeArray Polar Array

Post by Kunda1 »

Moved to Draft subforum
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: [BUG]: Draft.makeArray Polar Array

Post by louisgag »

Thanks for the feedback and the workaround vocx.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [BUG]: Draft.makeArray Polar Array

Post by Kunda1 »

louisgag wrote: Fri Feb 21, 2020 8:26 am Thanks for the feedback and the workaround vocx.
what do you suggest we do with issue #4264?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: Ticket #4264 - Draft.makeArray Polar Array

Post by louisgag »

If nobody wants to modify the code, then maybe just including a small note on the polar array wiki page ?
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Ticket #4264 - Draft.makeArray Polar Array

Post by Roy_043 »

The makeArray function is deprecated and the make_array function that replaces does not have a name argument. AFAICT only 3 make_ functions have a name argument. And in the case of make_layer it is used for the Label. :mrgreen:

louisgag wrote: Mon Feb 07, 2022 12:16 pm If nobody wants to modify the code, then maybe just including a small note on the polar array wiki page ?
IMO changing the code would only make sense if this then done for all make_ functions. Considering the recent refactoring this seems unlikely.

For completeness in V0.18 this did work:

Code: Select all

import Draft
Draft.makeArray(App.getDocument('Unnamed').getObject('Cylinder'), App.Vector(0, 0, 0), 360, 4, name="testArray")
In V0.19 en V0.20 the code still works, but the name is ignored as makeArray calls make_array.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #4264 - Draft.makeArray Polar Array

Post by Kunda1 »

moving forward, what is the solution?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Ticket #4264 - Draft.makeArray Polar Array

Post by Roy_043 »

IMO this can be closed. If louisgag wants to pursue this it should be considered a feature request instead.
Post Reply