A Tip on how to view data during development

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
freedman
Veteran
Posts: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

A Tip on how to view data during development

Post by freedman »

We are always looking for good ways to view data, here is a way using Add properties. Make a new add property of string data and view it in the Properties panel, have your code update the property.

See pic; I update my new "Copy_camera" property with getcamera() data in realtime. It's really nice to see all the data easily as I rotate an object, zoom in/out and change views. I didn't format the data at all, it comes out this way from getcamera().

Obviously this could be used in many ways to view lots of string data without much effort. Could add a switch just for debug. The properties could be deleted after usage.
Attachments
y1.JPG
y1.JPG (40.54 KiB) Viewed 3033 times
Last edited by freedman on Sun Aug 01, 2021 2:34 am, edited 1 time in total.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: A Tip on how to view data during development

Post by TheMarkster »

This is very clever.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: A Tip on how to view data during development

Post by Kunda1 »

Nice! Does it update in realtime?

Edit: Sorry, skimmed over the point where you said it does :oops:

Edit2:
marja1 wrote:Heads up
CC @marja1

Edit3:
HakanSeven12 wrote:Heads up
Joel_graff wrote:Heads up
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: A Tip on how to view data during development

Post by HakanSeven12 »

Im using same method for Trails alignments. It saves ailgnment model dictionary as string then I can use it by using eval() function. Its very useful.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: A Tip on how to view data during development

Post by Joel_graff »

That is pretty clever.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: A Tip on how to view data during development

Post by galou_breizh »

Thanks for the tip. Can you explain how you set the property? Do you use the expression engine? I tried but neither getcamera() nor eval are valid expressions for the expression engine.

Thanks,
Gaël
freedman
Veteran
Posts: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: A Tip on how to view data during development

Post by freedman »

With an open document this will create the added property in the first valid object found. I don't use the expression engine so I don't have much feedback.

Code: Select all

doc = FreeCAD.ActiveDocument
if doc != None:
    for obj in doc.Objects:
        if obj.TypeId[:4] == 'Part':
            #######  to view the data  
            obj.addProperty("App::PropertyString","Camera_view_1")
            obj.Camera_view_1 = Gui.ActiveDocument.ActiveView.getCamera()
            #######   or if you want to store the camera view without using a bunch of property view space
            obj.addProperty("App::PropertyPythonObject","Camera_view_2")
            obj.Camera_view_2 = Gui.ActiveDocument.ActiveView.getCamera()
            break
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: A Tip on how to view data during development

Post by galou_breizh »

Thanks for the explanation but I'm still missing something: the properties do not update.
freedman
Veteran
Posts: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: A Tip on how to view data during development

Post by freedman »

The property needs to be updated by software.

If your interested here is a macro that uses the Properties panel as a display and an input device.
It creates two new properties in the first object/Body. The property called "Camera status" is read by the macro on a timer, if set to a "1" the camera property will be updated every 100 milliseconds, if set to "2" the properties are deleted and the timer stopped.
Attachments
camera_prop1.FCMacro
(1001 Bytes) Downloaded 56 times
Post Reply