MACRO:Work Feature 2014_12

Need help, or want to share a macro? Post here!
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

MACRO:Work Feature 2014_12

Postby rentlau_64 » Mon Dec 22, 2014 9:27 am

Hi every body!
I am just a new comer to FreeCAD, I discovered few months ago.

I Just want to thank every people involved in FreeCAD for their work, it is really a very nice and useful tool !!!

Using already existing MACROS, I rewrite a set of Work Features to help me in my FreeCAD projects, and I would like to
share with all of you, hope it can be of some help to other users.

First I would like to Thank for original ideas and codes from :
* Javier Marti­nez Garci­a 2014
* Gui ideas from by Jonathan Wiedemann 2014
* Mario52 for bounding box codes

With the Work_Feature_2014_12 Macro you can create points, lines, planes and bounding boxes using already existing objects...

Feel free to give me any advice/comment.

Here after a flavour of the tool, showing Point tab tools:
WF.png
WF.png (228.77 KiB) Viewed 6545 times
The last release of this MACRO can be found in :
https://github.com/Rentlau/WorkFeature.git

To learn how to install a MACRO :
http://freecadweb.org/wiki/index.php?ti ... tall_HowTo

And here the icon I use in the part toolbar.
WF_centerObjectsPlanes.png
WF_centerObjectsPlanes.png (5.91 KiB) Viewed 6545 times
WF_centerObjectsPlanes.svg
(12.03 KiB) Downloaded 243 times
Have a nice end of year.
Rentlau_64
Attachments
WorkFeatures_2014_12.zip
(140.8 KiB) Downloaded 243 times
Last edited by rentlau_64 on Mon Apr 20, 2015 6:56 am, edited 1 time in total.
wmayer
Site Admin
Posts: 14887
Joined: Thu Feb 19, 2009 10:32 am

Re: MACRO:Work Feature 2014_12

Postby wmayer » Mon Dec 22, 2014 10:09 am

That's pretty cool work!

Here are some comments:
Point:
* The .py file you offer is created from a .ui form and is based on PyQt. In the recent past we moved from PyQt to PySide. So, could you also offer the original .ui file please so that this can be ported to PySide if needed?
* The command Object(s) Center doesn't do what I would expect. For example, when I create a circle in the sketcher, select it and press the button it creates a point outside the circle. I would have expected to get the circle's center point
Axis:
* The command Object(s) X,Y,Z axes creates only a single axis
* The command Cylinder(s) axis doesn't seem to do anything
* There is a typo in the tooltip of Axis=(Plane, Axis): "anoher"
* The command Axis=(Plane,Plane) gives me an error when I select two perpendicular faces of a cube that share a common edge. It tells me that the planes are parallel
* The axes created by Object(s) Base Axes are a bit too long because when doing a view fit all objects are almost invisible
Plane:
* When I select a line and one of its end points the command Plane=(Point,Axis) fails. It only seems to work when using a point and line from different objects
* This also happens for the command Plane=(Point, _| Axis)
* This also happens for the command Plane=(Point, Plane)
Boxes:
* Both commands create faces instead of a box and pop ups many warning messages
User avatar
rockn
Posts: 1578
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: MACRO:Work Feature 2014_12

Postby rockn » Mon Dec 22, 2014 10:28 am

Hi rentlau_64 and welcome !

Your work is awesome, the Gui is really nice. Well done !

I am just wondering if you can use pyside istead of pyqt, since FreeCAD use pyside, pyqt is not needed at the installation so I think it will be more compatible with pyside.
Formations et tutoriels FreeCAD en Français, soutenez moi : https://www.tipeee.com/formations-freecad
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Mon Dec 22, 2014 1:01 pm

wmayer,
* The .py file you offer is created from a .ui form and is based on PyQt. In the recent past we moved from PyQt to PySide. So, could you also offer the original .ui file please so that this can be ported to PySide if needed?
Here after the ui file as requested.
WFGui_2014-12.ui.zip
(2.72 KiB) Downloaded 131 times
rockn, wmayer,

If you can give me a link to a simple example of Pyside vs PyQt, I guess I can translate the GUI file into PySide.
Merci.


* The command Object(s) Center doesn't do what I would expect. For example, when I create a circle in the sketcher, select it and press the button it creates a point outside the circle. I would have expected to get the circle's center point
Axis:
* The command Object(s) X,Y,Z axes creates only a single axis
* The command Cylinder(s) axis doesn't seem to do anything
* There is a typo in the tooltip of Axis=(Plane, Axis): "anoher"
* The command Axis=(Plane,Plane) gives me an error when I select two perpendicular faces of a cube that share a common edge. It tells me that the planes are parallel
* The axes created by Object(s) Base Axes are a bit too long because when doing a view fit all objects are almost invisible
Plane:
* When I select a line and one of its end points the command Plane=(Point,Axis) fails. It only seems to work when using a point and line from different objects
* This also happens for the command Plane=(Point, _| Axis)
* This also happens for the command Plane=(Point, Plane)
Boxes:
* Both commands create faces instead of a box and pop ups many warning messages
wmayer,Thank you very much for your comments/help, I will try mimic the behavior you describe and correct/improve all asap.

I am also working on a "cutter tool" to separate one object into 2 objects along a cut line and a plane... if you are interrested I can post it very soon; I still just need to manage the object directory tree.

Bonne fetes de fin d'année a tous!
Have a nice end of year celebrations!
Rentlau_64
wmayer
Site Admin
Posts: 14887
Joined: Thu Feb 19, 2009 10:32 am

Re: MACRO:Work Feature 2014_12

Postby wmayer » Mon Dec 22, 2014 2:19 pm

I can't provide a good tutorial for porting from PyQt to PySide but in general it's not that complicated. But what I can tell you is that the major differences is that QString doesn't exist in PySide. You simply use Python's own string classes.

So, in order to port it you first have to generate the .py file from the .ui resource. Use the tool pyside-uic therefore.

The .ui file you uploaded has some strange paths for the icons and when loading it into Qt designer no icons are displayed. I fixed all these paths manually. However, for the generated .py file I still don't get any icons at runtime. Maybe someone else can have a look?

The fix in FCMacro is pretty simple. Replace PyQt with PySide and replace "QtCore.QString.fromUtf8" with _fromUtf8.

Attached is are the sources.
Attachments
WFGui.zip
(22.08 KiB) Downloaded 96 times
User avatar
yorik
Site Admin
Posts: 11552
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: MACRO:Work Feature 2014_12

Postby yorik » Mon Dec 22, 2014 2:23 pm

The GUI work is gorgeous! Congrats
User avatar
yorik
Site Admin
Posts: 11552
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: MACRO:Work Feature 2014_12

Postby yorik » Mon Dec 22, 2014 2:39 pm

wmayer wrote:However, for the generated .py file I still don't get any icons at runtime. Maybe someone else can have a look?
About icon paths, they don't appear for me either, but I already noticed pyside seems to sometimes do strange things with relative paths...
I just found I could display the icons by adding this line:

Code: Select all

QtCore.QDir.setCurrent("/home/yorik/.FreeCAD")
in WF_2014_12.FCMacro at line 2305 (just before self.ui = WFGui.Ui_Form() ) but I'm not sure it's a very safe way to proceed, it might change the current working directory for the whole FreeCAD application...
wmayer
Site Admin
Posts: 14887
Joined: Thu Feb 19, 2009 10:32 am

Re: MACRO:Work Feature 2014_12

Postby wmayer » Mon Dec 22, 2014 2:50 pm

Ok, the problem is indeed with relative paths. PyQt does this much cleverer because it generates something like this in the header section:

Code: Select all

import os.path
ICONS_PATH = os.path.dirname(__file__)
and then for the icons it uses

Code: Select all

icon.addPixmap(QtGui.QPixmap(_fromUtf8(str(ICONS_PATH) + "/Icons/WF_Axes.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
So, this way the paths are always absolute but portable. With PySide I can't see a similar way to achieve this.
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Mon Dec 22, 2014 3:40 pm

I use the following :

OS: Ubuntu 12.04.3 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4252 (Git)
Branch: master
Hash: c02590c666c6dd7d33bf3cb795497311b6badadb
Python version: 2.7.3
Qt version: 4.8.1
Coin version: 3.1.3
OCC version: 6.7.1

Yorik,
Thank you very much for your comment and thank you very much for all the work you are doing to help people.

Wmayer,
You are right, In fact the relative path from QT4 designer is alway dirty so once I generated the WFGui_2014_12.py file from the WFGui_2014_12.ui file
I fixed the relative path as follow:

1 - First get the absolute path where are the 2 files (MACRO directory) and the Icons directory
./Icons
WF_2014_12.FCMacro
WFGui_2014_12.py

2 - so into WFGui_2014_12.py add the following :

Code: Select all

import os.path
ICONS_PATH = os.path.dirname(__file__)
3 - update all the icons path with :

Code: Select all

icon.addPixmap(QtGui.QPixmap(_fromUtf8(str(ICONS_PATH) + "/Icons/WF_Axes.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Thank you for the advices for PySide I will look at them carefuly.

I tested some of the bug comments you gave me:
some first ideas/turn around:
Point:
* The command Object(s) Center doesn't do what I would expect. For example, when I create a circle in the sketcher,
select it and press the button it creates a point outside the circle. I would have expected to get the circle's center point
OK I mimic the behavior you got:
- The Object(s) center do not work as expected (but was not designed for sketch)...I will continue to look after to fix for sketch.
- but the Circle(s) center works for a sketch circle.
Axis:
* The command Object(s) X,Y,Z axes creates only a single axis
OK I mimic the behavior you got:
- True for "Flat" sketch objects belonging to one of the XY, XZ or YZ plane ...(same "bug" as previous as I used the center point
and it was not designed for sketch)...I will continue to look after to fix for sketch.
Axis:
* The command Cylinder(s) axis doesn't seem to do anything
Houps for me I get an axis as illustrated here after:
CylinderAxis.png
CylinderAxis.png (185.95 KiB) Viewed 6456 times
Could you give me a FreeCAD file where it is not working or explain how to mimic your bug?
* The command Axis=(Plane,Plane) gives me an error when I select two perpendicular faces of a cube that share a common edge. It tells me that the planes are parallel
Again for me it is working as illustrated below:
2FacesOfCube.png
2FacesOfCube.png (176.44 KiB) Viewed 6456 times
Could you give me a FreeCAD file where it is not working or explain how to mimic your bug?
Plane:
* When I select a line and one of its end points the command Plane=(Point,Axis) fails. It only seems to work when using a point and line from different objects
- Yes normal you need at least 3 none aligned points to generate a plane...I will change the error message to ask to select a line
and a point not aligned with the line.
Boxes:
* Both commands create faces instead of a box and pop ups many warning messages
- Yes I will try to add the box object (but I will keep the Faces too)

Have a nice day
Rentlau_64
User avatar
saso
Posts: 1332
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: MACRO:Work Feature 2014_12

Postby saso » Mon Dec 22, 2014 7:20 pm

Love it, Thanks to everyone involved to have bring it this far! But could someone help me understand what is this "macro" supposed to mean? Is it just the current implementation for testing or is it meant to stay like that? I would sure hope it could get in as a standard feature of FreeCAD :|