add a new unit failed

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

add a new unit failed

Post by bernd »

I tried to add a new unit to FreeCAD ...

https://github.com/berndhahnebach/FreeC ... e215960e05

I missed something ...

Code: Select all

from FreeCAD import Units 
Units.ElectricVacuumPermittivity
gives

Code: Select all

>>> 
>>> from FreeCAD import Units 
>>> Units.ElectricVacuumPermittivity
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: module 'Units' has no attribute 'ElectricVacuumPermittivity'
>>> 
wheras:

Code: Select all

from FreeCAD import Units 
Units.KinematicViscosity 
works fine:

Code: Select all

>>> 
>>> from FreeCAD import Units 
>>> Units.KinematicViscosity 
Unit: mm^2/s (2,0,-1,0,0,0,0,0) [KinematicViscosity]
>>> 
Erni24
Posts: 13
Joined: Fri Feb 24, 2017 6:00 pm

Re: add a new unit failed

Post by Erni24 »

Not sure, but there is a mistake in your formula. It has to be

Code: Select all

App.Units.ElectricVacuumPermittivity = App.Units.Unit(-3,-1,4,2)
The current is with a power of two!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: add a new unit failed

Post by Kunda1 »

any progress on this?
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
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: add a new unit failed

Post by yorik »

bernd wrote: Wed Aug 07, 2019 10:52 pm AttributeError: module 'Units' has no attribute 'ElectricVacuumPermittivity'
If I do this:

Code: Select all

grep -r KinematicViscosity *
I get:

Code: Select all

App/FreeCADInit.py:App.Units.KinematicViscosity           = App.Units.Unit(2,0,-1)
Base/Unit.cpp:    if(*this == Unit::KinematicViscosity          )       return QString::fromLatin1("KinematicViscosity");
Base/Unit.cpp:Unit Unit::KinematicViscosity          (2,0,-1); 
Base/Unit.h:    static Unit KinematicViscosity;
Make sure ElectricVacuumPermittivity is defined in these 4 locations too, probably one is missing... (My guess is the first one)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: add a new unit failed

Post by bernd »

still no success ...

Code: Select all

$
$ grep -r ElectricVacuumPermittivity
src/App/FreeCADInit.py:App.Units.ElectricVacuumPermittivity = App.Units.Unit(-3,-1,4,2)
src/Base/Unit.h:    static Unit ElectricVacuumPermittivity;
src/Base/Unit.cpp:    if(*this == Unit::ElectricVacuumPermittivity  )       return QString::fromLatin1("ElectricVacuumPermittivity");
src/Base/Unit.cpp:Unit Unit::ElectricVacuumPermittivity(-3,-1,4,2);
$


https://github.com/berndhahnebach/FreeC ... it/502a778


Code: Select all

from FreeCAD import Units 
Units.ElectricVacuumPermittivity

Code: Select all

 
>>>
>>> from FreeCAD import Units
>>> Units.ElectricVacuumPermittivity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'Units' has no attribute 'ElectricVacuumPermittivity'
>>>
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: add a new unit failed

Post by bernd »

commit git commit c3f0288 and PR https://github.com/FreeCAD/FreeCAD/pull/2467 adds a unit to FreeCAD master but it does not work for me ...

Code: Select all

from FreeCAD import Units 
Units.VacuumPermittivity

Code: Select all

>>> 
>>> from FreeCAD import Units 
>>> Units.VacuumPermittivity
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: module 'Units' has no attribute 'VacuumPermittivity'
>>> 
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: add a new unit failed

Post by bernd »

works now for me :D

Code: Select all

from FreeCAD import Units 
Units.VacuumPermittivity

Code: Select all

Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> 
>>> from FreeCAD import Units 
>>> Units.VacuumPermittivity
Unit: s^4*A^2/(mm^3*kg) (-3,-1,4,2,0,0,0,0) [VacuumPermittivity]
>>>


OS: Debian GNU/Linux 10 (buster) (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18231 (Git)
Build type: Unknown
Branch: master
Hash: 9dfcdb983f7dd1c5008b0f7d041247e30fc21a66
Python version: 3.7.3
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: add a new unit failed

Post by bernd »

Is there a difference between VacuumPermittivity and ElectricVacuumPermittivity If not we could rename it in material properties and use it as quantity instead of float. With this we would have all advantages from FreeCAD unit system for this material property. If it is not the same we schould addd ElectricVacuumPermittivity to the FreeCAD unit system.

https://github.com/FreeCAD/FreeCAD/blob ... #L158-L162

Erni24 wrote: ping
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: add a new unit failed

Post by vocx »

bernd wrote: Sun Sep 15, 2019 8:02 pm works now for me
I remembered this thread.

Did you succeed in adding the unit?

With git commit 3500451a04 Werner added a unit. It seems he also added the corresponding property to src/App/Application.cpp, and src/App/PropertyUnits.h(.cpp), in addition to src/Base/Unit.h(.cpp).

See How to add other properties ,such as frequency ?
wmayer wrote: Mon Oct 21, 2019 9:52 am Frequency is now supported: git commit 3500451a0 and git commit d7ca604c9
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.
Post Reply