Page 1 of 1

Help to check FC version

Posted: Tue Jun 28, 2022 12:31 pm
by johnwang
Hi,

How to check FC version?
If FC version=FCver, I want something like this:

Code: Select all

If FCver<0.20:
	import freecad.plot.Plot as Plot
else:	
	from FreeCAD.Plot import Plot
Does it work?

Cheers,

John

Re: Help to check FC version

Posted: Tue Jun 28, 2022 12:41 pm
by onekk
It seems not correct, as usual version is returned as a list containing some data.

Now I'm on mobile so no mean to check for proper code, but If you search in the forum probably you will find easily some hints.

Code: Select all

FreeCAD.Version()
['0', '19', '24366 (Git)', 'https://github.com/conda-forge/freecad-feedstock', '2021/12/04 21:56:30', '(HEAD detached at 0f9259c)', '0f9259cda103ae1824ac16c68ac9b4a0d54b05fc']
you could make some assumptions, so you could aggregate at least first and second element:

Code: Select all

vers = FreeCAD.Version()
print(vers)

ver_num = float(f"{vers[0]}.{vers[1]}")
sub_ver = int(f"{vers[2][:5]}")
print(ver_num, sub_ver)
This way you could check major version as this is a float and subsequent check if needed sub_version (extracted from the third element guessing that is have a 5 figures digit as start element)

Sadly third element is not guaranteed to be correctly formatted for some versions around, making difficult to discriminate between "sub versions" or "build version", this is a know problem and has been discussed in the forum,

https://forum.freecadweb.org/viewtopic. ... 41#p598441

Hope it helps.

Regards

Carlo D.

Re: Help to check FC version

Posted: Tue Jun 28, 2022 3:44 pm
by Syres
To expand on @onekk's input and to 'borrow' what's already in use in the CfdOF Wb, this is the code @oliveroxtoby uses:

Code: Select all

# Check FreeCAD version
ver = FreeCAD.Version()
major_ver = int(ver[0])
minor_vers = ver[1].split('.')
minor_ver = int(minor_vers[0])
message = ""
try:
    import matplotlib
except ImportError:
    matplot_msg = "Could not load matplotlib package (required by Plot module)"
    message += matplot_msg + '\n'
    print(matplot_msg)

plot_ok = False
if major_ver > 0 or minor_ver >= 20:
    try:
        from FreeCAD.Plot import Plot  # Build-in plot module
        plot_ok = True
    except ImportError:
        plot_msg = "Could not load Plot module\nAttempting to use Plot workbench instead"
        message += plot_msg + "\n"
        print(plot_msg)
if not plot_ok:
    try:
        import freecad.plot.Plot as Plot  # Plot workbench
    except ImportError:
        plot_msg = "Could not load legacy Plot module"
        message += plot_msg + '\n'
        print(plot_msg)
Edit: Tested Code in AirPlaneDesign Wb

Re: Help to check FC version

Posted: Wed Jun 29, 2022 7:34 am
by johnwang
onekk wrote: Tue Jun 28, 2022 12:41 pm
Thank you very much.

Re: Help to check FC version

Posted: Wed Jun 29, 2022 7:35 am
by johnwang
Syres wrote: Tue Jun 28, 2022 3:44 pm Edit: Tested Code in AirPlaneDesign Wb
That's very nice. Thank you very much.