Path to FeaturePython with PropertyFile

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Path to FeaturePython with PropertyFile

Post by keithsloan52 »

If I have created a FeaturePython with a Property of "App::PropertyFile" how do I obtain the Path to the file?

I assume it is one of the main FreeCAD calls.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path to FeaturePython with PropertyFile

Post by onekk »

keithsloan52 wrote: Sat Feb 04, 2023 12:24 am If I have created a FeaturePython with a Property of "App::PropertyFile" how do I obtain the Path to the file?

I assume it is one of the main FreeCAD calls.
It is not available as a property of DocumentObject?

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Path to FeaturePython with PropertyFile

Post by keithsloan52 »

Well it has created one, I assume it creates a file in the same directory that will be used when the freecad file is saved as a zip Fc? No?
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Path to FeaturePython with PropertyFile

Post by keithsloan52 »

Looking at property App::PropertyFileInclude https://wiki.freecad.org/FeaturePython_ ... leIncluded

I think it might be getDocTransientPath().

I will try when I get back to hotel this evening.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path to FeaturePython with PropertyFile

Post by onekk »

keithsloan52 wrote: Sat Feb 04, 2023 8:31 am Well it has created one, I assume it creates a file in the same directory that will be used when the freecad file is saved as a zip Fc? No?
From what I know, it usually reuse the last path, or probably the Home dir of the user, if you don't specify one, there is also a preference in Preferences, reachable with

Code: Select all

print(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetString('FileOpenSavePath'))
and writable with:

Code: Select all

FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").SetString('FileOpenSavePath',   "<Your Desired Path>")
Hope it helps

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path to FeaturePython with PropertyFile

Post by onekk »

keithsloan52 wrote: Sat Feb 04, 2023 8:44 am Looking at property App::PropertyFileInclude https://wiki.freecad.org/FeaturePython_ ... leIncluded

I think it might be getDocTransientPath().

I will try when I get back to hotel this evening.

Code: Select all

DOC.getPropertyByName('FileName')
return the full path of the file name.

Code: Select all

DOC.getPropertyByName('TransientDir')
Will return instead the temp directory in the user directory (in my installation of 0.20.2 on Linux)


But I have tested them only on "standard objects" and not FeaturePython Objects.

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Path to FeaturePython with PropertyFile

Post by Roy_043 »

App::PropertyFile and App::PropertyFileIncluded are quite different. You should not mix them up. Which are we talking about?
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Path to FeaturePython with PropertyFile

Post by keithsloan52 »

Roy_043 wrote: Sat Feb 04, 2023 11:43 am App::PropertyFile and App::PropertyFileIncluded are quite different. You should not mix them up. Which are we talking about?
I know that, but the FileIncluded Doc mentioned getDocTransientPath() App::PropertyFile does not mention anything about where the file can be found.

I am trying to create a PythonFeature which has a property that has a File, that will get saved when the Object gets saved and I can add code to drive an external editor to edit the file.

York uses FileIncluded in the Arch workbench but think the usage is different
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path to FeaturePython with PropertyFile

Post by onekk »

keithsloan52 wrote: Sat Feb 04, 2023 5:28 pm
Roy_043 wrote: Sat Feb 04, 2023 11:43 am App::PropertyFile and App::PropertyFileIncluded are quite different. You should not mix them up. Which are we talking about?
I know that, but the FileIncluded Doc mentioned getDocTransientPath() App::PropertyFile does not mention anything about where the file can be found.

I am trying to create a PythonFeature which has a property that has a File, that will get saved when the Object gets saved and I can add code to drive an external editor to edit the file.

York uses FileIncluded in the Arch workbench but think the usage is different
This will save a Txt file that I use as example to add "documentation" to a FCStd file, it is visible in when you open a FCStd document.

Code: Select all

info_txt = '''
Text file with new lines that
is saved in the final FCStd doc.

Regards
'''

txt_doc = out_doc.addObject("App::TextDocument","Text document")
txt_doc.Label = "Documentation"
txt_doc.Text = info_txt
But there is a way to add other things, let me see if I find

viewtopic.php?t=38201

and

Embedding other files
in: https://wiki.freecad.org/File_Format_FCStd

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Path to FeaturePython with PropertyFile

Post by keithsloan52 »

Well if I use App::PropertyFile then I can achieve the desired functionality between the new OpenSCAD objects and an external editor (Emacs)
but the file is not saved with the FreeCAD file.

If I try App::PropertyFileIncluded then the file does not stay around long enough for me to use with an external editor.

A prototype replacement for the OpenSCAD work bench is at https://www.dropbox.com/scl/fo/m00vb2be ... 6o4gblubpo

The relevant source is OpenSCADFeatures.py class definition class SCADObject
External editor is hard coded EMACs on MacOS
Communication with Emacs uses pipes.
Post Reply