displaying a list of global dimensional variables ?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Linear3000
Posts: 13
Joined: Sun Feb 23, 2020 1:10 am

displaying a list of global dimensional variables ?

Postby Linear3000 » Fri Mar 20, 2020 11:43 pm

Hi there, I'm fairly new to FreeCAD and doing quite well with it, but a thought occurred to me ---

in a typical IDE software package, you'll have a variables list feature which will show you what variables you currently have data assigned to, what that data is, and how it changes as you step through a program.

In using FreeCAD software (not editing code in an IDE, but simply while working in the FreeCAD program creating CAD parts) Is there any existing way to similarly view such a list of specifically positional/dimensional variables of the freecad document you're currently working in? i.e. those items that show up in the property view panel (not necessarily to edit them, but could be)

An example of what I'm talking about -- if I type the following in the python console
FreeCAD.getDocument("toy").getObject("Sketch").AttachmentOffset
I get:
Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]

As a first step, I'm thinking that I could write a simple macro to basically loop through all the instantiated objects / variables , and then simply display those variables in the console, as above.

Maybe later I could develop it into some kind of graphical thing.

However, If there's already an easy way to do these things, maybe I should know about that first, before I reinvent the wheel.

I do understand that expressions, dynamic data variables, and assembly workbench variables, spreadsheets, etc already exist as ways to assign values to variables.

All that stuff is a bit cumbersome, and sometimes you just want to see all the relevant variables, all in one place, not having to endlessly click through so many different things in the tree to get there.

Thoughts?
vocx
Posts: 3337
Joined: Thu Oct 18, 2018 9:18 pm

Re: displaying a list of global dimensional variables ?

Postby vocx » Fri Mar 20, 2020 11:56 pm

Linear3000 wrote:
Fri Mar 20, 2020 11:43 pm
...
All that stuff is a bit cumbersome, and sometimes you just want to see all the relevant variables, all in one place, not having to endlessly click through so many different things in the tree to get there.
All objects in the current document are in

Code: Select all

FreeCAD.ActiveDocument.Objects
Then each object has its own set of properties in the attribute PropertiesList.

Code: Select all

for obj in FreeCAD.ActiveDocument.Objects:
    for property in obj.PropertiesList:
        print(property)
Having a single place for all relevant properties doesn't exist, because what is a "relevant property" to you? That's what the property editor is for, it shows you all properties of the active object. If you would like to show all properties of all objects at the same time, then you'd need to loop through all objects in the document, extract the property, and show it somewhere.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
Linear3000
Posts: 13
Joined: Sun Feb 23, 2020 1:10 am

Re: displaying a list of global dimensional variables ?

Postby Linear3000 » Sat Mar 21, 2020 4:19 pm

Thank you! Much appreciated!

One other thing I haven't been able to locate in the documentation is how one might go about creating
graphical elements that are not part of the existing freecad gui, or, for example, to create an alternate panel view like i.e. the property view... something that can be attached to a fixed location inside the freecad window or possibly float outside.

Is that something that could be done at the python level? or would one have to delve into the nitty gritty lower level operations of the program to produce novel graphical features?

as a simple test for handling 'extra' graphical elements, I fired up matplotlib in the python console and much to my surprise,
(note: I do not believe I have "plot" workbench installed in freecad, but this stuff worked nonetheless. )
I succeeded in creating a graphical interactive plot. Now I don't know if matplotlib is doing this independently in some graphical backend that is seperate from freeCAD but when I run this command
>>> plt.get_backend()
I get:
'Qt5Agg'

So should I assume it is using FreeCAD's 'Qt5Agg' backend?

Is there any particular reference or documentation you could refer me to regarding developing novel graphical elements in freecad?
vocx
Posts: 3337
Joined: Thu Oct 18, 2018 9:18 pm

Re: displaying a list of global dimensional variables ?

Postby vocx » Sat Mar 21, 2020 6:08 pm

Linear3000 wrote:
Sat Mar 21, 2020 4:19 pm
...
One other thing I haven't been able to locate in the documentation is how one might go about creating graphical elements that are not part of the existing freecad gui, ...
Obviously it's possible to add more graphical interfaces. This is exactly what many external workbenches do, they add new graphical panes and dialogs.

What you want is located somewhere in the Power users hub or Developer hub. Unfortunately, many pages are very old, created around 2014 and earlier so they haven't been updated significantly in years. They are also hard to find, because there is no clear progression on what you should read first, and what second, or how to return to the beginning, etc.

But if you are willing to dig in, you can find what you need. And you should also check the official Qt docs to see what else is available.

FreeCAD uses Qt5. It accesses it through the PySide wrapper in Python. See the examples there.

If you find references to PyQt in the documentation these are outdated as PyQt hasn't been used since 2013 or so. In many cases you can just substitute PyQt with PySide and the examples should work.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
Linear3000
Posts: 13
Joined: Sun Feb 23, 2020 1:10 am

Re: displaying a list of global dimensional variables ?

Postby Linear3000 » Thu Mar 26, 2020 1:14 pm

Thank you again so much, I really appreciate it! Will see how things go. Cheers!
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: displaying a list of global dimensional variables ?

Postby mario52 » Fri Mar 27, 2020 9:55 am

hi

maybe this macro can help you momentarily Macro FCInfo on selected object

Image

other Macro SimpleProperties

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