Macro for creating Draft arrays

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Macro for creating Draft arrays

Post by alonso_jamm »

I worked on a script to make Draft arrays a little bit easier. It is more of a proof of concept since it does not have all features required to make all types of arrays. However, now it more or less works! I am showing it so I can get feedback on the functionality of the script. Here is the link for the script.

I was inspired by how SolidWorks works and the Sketch Workbench. When creating a new object in SolidWorks, a tab is open where configuration for the new object is set. I used the Tasks panel in FreeCAD to more or less model that functionality of SolidWorks.

Like I mentioned, the script is not as functional as I wish. But I want to know what other people think about the current way of how it works. Some of the features that the script has that I found quite interesting are:
  • Being able to just click on a part and get its name (For now it only works when clicking a link)
  • Being able to configure the array before creating it (I think this is a more intuitive way of creating arrays)
  • For a polar array, selecting a center by just clicking a coordinate system or a datum line
  • How the interface works (I found it kind of intuitive)
The way I used the script is to just put the Macro file and the ui file in the Macro folder (I have only used it in Linux so the script will not work on Windows). For making it work in Windows, line number 8 in the Macro file should be modified to the location of the ui File.

Here are some pictures of the macro. Here the cube is called "selte" and the datum axis is called "Axis_1."
TestLinkArray0.png
TestLinkArray0.png (6.54 KiB) Viewed 840 times
TestLinkArray1.png
TestLinkArray1.png (23.47 KiB) Viewed 840 times
TestLinkArray2.png
TestLinkArray2.png (25.03 KiB) Viewed 840 times
TestLinkArray3.png
TestLinkArray3.png (20.82 KiB) Viewed 840 times
Again, I ask for feedback on the macro so I can improve it. I also would appreciate feedback on the code since I am not sure if the way I wrote it is the best way. Eventually I would like to include the functionality of this macro into Assembly 4 or maybe the Draft Workbench.

Thanks!
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro for creating Draft arrays

Post by chrisb »

I have read here in the forum, that the idea was, to have user friendly dialogs for all operations. So once you have finished, it may well be integrated in the core system.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro for creating Draft arrays

Post by chrisb »

To install, does the .ui file go in the macro directory as well?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Macro for creating Draft arrays

Post by carlopav »

Nice! would be nice to have it in Draft...
follow my experiments on BIM modelling for architecture design
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Macro for creating Draft arrays

Post by sgrogan »

alonso_jamm wrote: Sun Dec 08, 2019 7:43 am The way I used the script is to just put the Macro file and the ui file in the Macro folder (I have only used it in Linux so the script will not work on Windows). For making it work in Windows, line number 8 in the Macro file should be modified to the location of the ui File.
See here: https://forum.freecadweb.org/viewtopic. ... 42#p139122
"fight the good fight"
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Macro for creating Draft arrays

Post by mario52 »

hi
alonso_jamm wrote: Sun Dec 08, 2019 7:43 am The way I used the script is to just put the Macro file and the ui file in the Macro folder (I have only used it in Linux so the script will not work on Windows). For making it work in Windows, line number 8 in the Macro file should be modified to the location of the ui File.
replace:

Code: Select all

home = expanduser("~")
uiLocation = home + "/.FreeCAD/Macro/LinkArrayTest.ui" # Location I used to store the .ui file
by

Code: Select all

param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
path  = param.GetString("MacroPath","") + "/"                       # macro path
uiLocation = path.replace("\\","/")
uiLocation = uiLocation + "LinkArrayTest.ui"
print(uiLocation)

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Macro for creating Draft arrays

Post by alonso_jamm »

mario52 wrote: Sun Dec 08, 2019 2:13 pm hi
alonso_jamm wrote: Sun Dec 08, 2019 7:43 am The way I used the script is to just put the Macro file and the ui file in the Macro folder (I have only used it in Linux so the script will not work on Windows). For making it work in Windows, line number 8 in the Macro file should be modified to the location of the ui File.
replace:

Code: Select all

home = expanduser("~")
uiLocation = home + "/.FreeCAD/Macro/LinkArrayTest.ui" # Location I used to store the .ui file
by

Code: Select all

param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
path  = param.GetString("MacroPath","") + "/"                       # macro path
uiLocation = path.replace("\\","/")
uiLocation = uiLocation + "LinkArrayTest.ui"
print(uiLocation)

sgrogan wrote: Sun Dec 08, 2019 1:11 pm See here: https://forum.freecadweb.org/viewtopic. ... 42#p139122
Thanks! I tested it on windows and it seems that the macro works as intended.
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Macro for creating Draft arrays

Post by alonso_jamm »

chrisb wrote: Sun Dec 08, 2019 8:25 am To install, does the .ui file go in the macro directory as well?
Yes, the ui file and the macro file go inside the macro directory. I am not sure if this is the best way of doing this, but I think it is the easiest. Also, I modified the macro so it also works on Windows
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Macro for creating Draft arrays

Post by Zolko »

alonso_jamm wrote: Sun Dec 08, 2019 7:43 am Eventually I would like to include the functionality of this macro into Assembly 4 or maybe the Draft Workbench.
It would be great to have this in Assembly4, though I don't have the time to test it right now
try the Assembly4 workbench for FreCAD — tutorials here and here
Post Reply