Launch Non-FreeCAD Files

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!
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Launch Non-FreeCAD Files

Post by drmacro »

onekk wrote: Tue Mar 14, 2023 12:17 pm ...
Sorry but I'm not a GUI user, I prefer to make thing using scripts, so. :oops:

...
You are a unique anomaly. ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
rich61
Posts: 156
Joined: Sat Jul 20, 2019 9:56 am

Re: Launch Non-FreeCAD Files

Post by rich61 »

I haven't been in the habit of using Label2, thanks for mentioning it.

Label2.png
Label2.png (13.19 KiB) Viewed 760 times

Only one problem, when I click it, it doesn't open the PDF file. ;)

Edit: I mocked up the image a bit, that shouldn't be a // but just a single / in the path name
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Launch Non-FreeCAD Files

Post by drmacro »

Just an FYI.

Two lines of Python will perform said launching.
(Here on Linux, but, probably similar on other platforms.)
The following is entered at the python console and assumes the odt file exists.
There is apparently other magic needed to have it run as a macro/Python file. (If anyone knows this magic, please edificate me... :) ) Run from a Python file it complains about the the subprocess module can't be found...something to do with shibroken2...(shiboken2, it's always some dang thing with shiboken :roll: )

Code: Select all

import subprocess
>>> process_one = subprocess.Popen(['libreoffice', '\\home\\mac\\Documents\\afile.odt'])
Update: it works fine from both the FC Python console or a Python/macro file...it I make content of the file correct. :roll: Cut&Paste gets me again...
Last edited by drmacro on Tue Mar 14, 2023 2:43 pm, edited 1 time in total.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
rich61
Posts: 156
Joined: Sat Jul 20, 2019 9:56 am

Re: Launch Non-FreeCAD Files

Post by rich61 »

I got this to work from the command line.

python3 -m webbrowser [ url or file path here ]

the browser may come up with a save or open dialog.

Works equally well with local file path
rich61
Posts: 156
Joined: Sat Jul 20, 2019 9:56 am

Re: Launch Non-FreeCAD Files

Post by rich61 »

Thanks drmacro for this. It works fine in an older apt and also app install, but I get an error with my snap version.
My non-snap versions are different freecad versions.

Code: Select all

import subprocess
p=subprocess.Popen(['firefox', 'example.com'])
But fails in my snap install.

Code: Select all

>>> import subprocess
>>> p=subprocess.Popen(['firefox', 'example.com'])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/snap/freecad/655/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/snap/freecad/655/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'firefox'
>>> 

Code: Select all

OS: Ubuntu Core 20 (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.21.0.32235 (Git) Snap 655
Build type: Release
Branch: master
Hash: 4ed6150231c27968e142bf5cac80d9cfe626f24b
Python 3.8.10, Qt 5.15.5, Coin 4.0.0, Vtk 7.1.1, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Assembly3 0.11.3
  * fasteners 0.4.54
  * ThreadProfile 1.84.0
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Launch Non-FreeCAD Files

Post by adrianinsaval »

AFAIK you can't directly run other apps from a snap package because it is sandboxed, see it's not that simple of a feature ;)
rich61
Posts: 156
Joined: Sat Jul 20, 2019 9:56 am

Re: Launch Non-FreeCAD Files

Post by rich61 »

Thanks adrian, I didn't know that. A closed universe.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Launch Non-FreeCAD Files

Post by yorik »

My 2 cents here:

1. The Label2 should be renamed to something more meaningful like "Description" or "Notes"
2. We could have an "Edit Label2" tool that could for ex:

- open a more advanced editor dialog
- detect rich/html text (and maybe more, such as markdown) and renders it correctly
- detect links and make them clickable

Such tool could probably more or less easily be don in python, a simple macro could do it. Then, once it works well, it could be integrated into the FreeCAD UI
rich61
Posts: 156
Joined: Sat Jul 20, 2019 9:56 am

Re: Launch Non-FreeCAD Files

Post by rich61 »

I keep an external libreoffice document now, and embed hyperlinks to any other files such as PDF vendor drawings and specification documents on my file system or on the web, in my project directory to try to say organized. Its just a way to keep track of reference documents that relate to the model. Everyone has a system.

Just a few examples what could be done if its worth it. Just bring up a context menu on one of the Text document list, and open the system level link in the OS environment.

1. Existing Internal Text document
2. detect a link or command, launch external file
3. Just the file only and the OS decides how to open it
4. A web link, not sure I like that since it could distribute a bad site

ExternalFiles.png
ExternalFiles.png (27 KiB) Viewed 447 times
When FCStd files are distributed, the external files would not be included in the FreeCAD file. So to distribute them would be a deliberate action.

The property Label2 is part of every object. Label2 always in the description column once entered.

An alternate approach is to have an external utility program read and parse the Document.xml file to get the links and any documentation in a Text Document or in the Description fields.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Launch Non-FreeCAD Files

Post by yorik »

This is good and simple, actually. Maybe the label2 in the tree should become clickable if a link is detected? Not sure if it's such a good idea... Seems like an invite for spam/malicious links...
Post Reply