Standard / imperial unit system change - short cut

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
xf3qc
Posts: 22
Joined: Fri Aug 04, 2017 5:29 pm

Standard / imperial unit system change - short cut

Postby xf3qc » Sat May 16, 2020 1:51 am

instead of going to Preferences -> Units and switching, is it possible to make a shortcut/tool bar button?
chrisb
Posts: 25204
Joined: Tue Mar 17, 2015 9:14 am

Re: Standard / imperial unit system change - short cut

Postby chrisb » Sat May 16, 2020 5:06 am

You can use a macro which is bound to an icon. See e.g. the macro FC_SU, which changes some preferences: https://forum.freecadweb.org/viewtopic.php?t=41265.
mario52
Posts: 2992
Joined: Wed May 16, 2012 2:13 pm

Re: Standard / imperial unit system change - short cut

Postby mario52 » Sat May 16, 2020 9:57 am

hi

create a button and use this snippet , click the button increment the counter and the unit option is activated and displayed in the Report view

Code: Select all

#16/05/2020
#Mario52
#https://forum.freecadweb.org/viewtopic.php?f=3&t=46393
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("UserSchema")
p += 1
if p > 7:
    p = 0
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)

if p == 0:
    pp = "Standard (mm/kg/s/degree)"
elif p == 1:
    pp = "MKS (m/kg/s/degree)"
elif p == 2:
    pp = "US customary (in/lb)"
elif p == 3:
    pp = "Imperial decimal (in/lb)"
elif p == 4:
    pp = "Building Euro (cm/m2/m3)"
elif p == 5:
    pp = "Building US (ft-in/sqft/cft)"
elif p == 6:
    pp = "Metric small parts e CNC(mm, mm/min)"
elif p == 7:
    pp = "Imperial for Civil Eng (ft, ft/sec)"


print(p,":",pp)
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
drmacro
Posts: 968
Joined: Sun Mar 02, 2014 4:35 pm

Re: Standard / imperial unit system change - short cut

Postby drmacro » Sat May 16, 2020 12:04 pm

Just curious.

What is the use case for switching back and forth?

Is it because you forgot before starting the file?

Is it because you want to enter inches in a constraint, but are in metric?

In the later case simply delete the contents of the box (including the units, for example mm), then type 10".
The resulting value will be 254mm.

For 1 1/4": clear the box, type (1+(1/4))". (or if you happen to know the decimal value, 1.25". (I tend to use the fraction...since, I typically don't remember, for example, what 31/32" is in decimal :roll: )

Just FYI. ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
User avatar
xf3qc
Posts: 22
Joined: Fri Aug 04, 2017 5:29 pm

Re: Standard / imperial unit system change - short cut

Postby xf3qc » Sun May 17, 2020 12:54 am

Thank you chrisb, mario and drmarco.

Never knew how to enter mixed fractions , very helpful.

Everything else is real awesome, using mm and inches back and forth all the time.

Etsy seller here making custom cuts for anyone.
Using FreeCAD for everything and to send snaps to customers. Who are all over world, some metric, some imperial. I end up switching it every 10 minutes sometimes.

(dimensions actually I have lots problem with, can't figure out good way)
Attachments
Screenshot_2020-04-20_11-06-21.png
Screenshot_2020-04-20_11-06-21.png (220.47 KiB) Viewed 268 times
shelf_1.png
shelf_1.png (27.1 KiB) Viewed 268 times
oops.png
oops.png (80.75 KiB) Viewed 268 times
scale2.png
scale2.png (38.35 KiB) Viewed 268 times
nat3.png
nat3.png (36.83 KiB) Viewed 268 times
User avatar
xf3qc
Posts: 22
Joined: Fri Aug 04, 2017 5:29 pm

Re: Standard / imperial unit system change - short cut

Postby xf3qc » Tue May 19, 2020 11:43 pm

mario52 wrote:
Sat May 16, 2020 9:57 am
hi

create a button and use this snippet , click the button increment the counter and the unit option is activated and displayed in the Report view

Code: Select all

#16/05/2020
#Mario52
#https://forum.freecadweb.org/viewtopic.php?f=3&t=46393
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("UserSchema")
p += 1
if p > 7:
    p = 0
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)

if p == 0:
    pp = "Standard (mm/kg/s/degree)"
elif p == 1:
    pp = "MKS (m/kg/s/degree)"
elif p == 2:
    pp = "US customary (in/lb)"
elif p == 3:
    pp = "Imperial decimal (in/lb)"
elif p == 4:
    pp = "Building Euro (cm/m2/m3)"
elif p == 5:
    pp = "Building US (ft-in/sqft/cft)"
elif p == 6:
    pp = "Metric small parts e CNC(mm, mm/min)"
elif p == 7:
    pp = "Imperial for Civil Eng (ft, ft/sec)"


print(p,":",pp)
mario
This does swap it, but changes don't take effect until I run Preferences, Units, OK.
mario52
Posts: 2992
Joined: Wed May 16, 2012 2:13 pm

Re: Standard / imperial unit system change - short cut

Postby mario52 » Wed May 20, 2020 9:52 am

hi

how many units do you use and which ones (listed in the macro)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
xf3qc
Posts: 22
Joined: Fri Aug 04, 2017 5:29 pm

Re: Standard / imperial unit system change - short cut

Postby xf3qc » Wed May 20, 2020 10:07 am

Standard (mm/kg/s/degree)
and
US customary (in/lb)
Need to cycle between the two.
GeneFC
Posts: 1214
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Standard / imperial unit system change - short cut

Postby GeneFC » Wed May 20, 2020 3:39 pm

xf3qc wrote:
Wed May 20, 2020 10:07 am
Standard (mm/kg/s/degree)
and
US customary (in/lb)
Need to cycle between the two.
Be careful!

"US Customary" is anything but customary. It is likely that you want "Imperial decimal".

This has recently been discussed in

Code: Select all

https://forum.freecadweb.org/viewtopic.php?f=3&t=46222
Gene
mario52
Posts: 2992
Joined: Wed May 16, 2012 2:13 pm

Re: Standard / imperial unit system change - short cut

Postby mario52 » Wed May 20, 2020 4:46 pm

hi

i modify the macro flip/flop to Standard (mm/kg/s/degree)/US customary (in/lb)

run the macro the preference window is displayed click directly Ok for validate

Code: Select all

#16/05/2020:20/05/2020
#Mario52
#https://forum.freecadweb.org/viewtopic.php?f=3&t=46393
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("UserSchema")
#p += 1
#if p > 7:
#    p = 0
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)
#if p == 0:
#    pp = "Standard (mm/kg/s/degree)"
#elif p == 2:
#    pp = "US customary (in/lb)"
#elif p == 3:
#    pp = "Imperial decimal (in/lb)"
#elif p == 4:
#    pp = "Building Euro (cm/m2/m3)"
#elif p == 5:
#    pp = "Building US (ft-in/sqft/cft)"
#elif p == 6:
#    pp = "Metric small parts e CNC(mm, mm/min)"
#elif p == 7:
#    pp = "Imperial for Civil Eng (ft, ft/sec)"

if p == 0:
    p = 2
    pp = "US customary (in/lb)"
    FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)
elif p == 2:
    p = 0
    pp = "Standard (mm/kg/s/degree)"
    FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)
else:
    p = 0
    pp = "Standard (mm/kg/s/degree)"
    FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt("UserSchema", p)

print(p,":",pp)

Gui.runCommand('Std_DlgPreferences',0)


mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.