A few question about Wiki Script Object examples
A few question about Wiki Script Object examples
Hi,
I am trying out the wiki Scripted Object examples and have a few questions. See https://www.freecadweb.org/wiki/Scripted_objects
The Basic example is all good, but when after running the Complex one, I can't see anything on the viewport.
Regards,
John
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13528 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
I am trying out the wiki Scripted Object examples and have a few questions. See https://www.freecadweb.org/wiki/Scripted_objects
The Basic example is all good, but when after running the Complex one, I can't see anything on the viewport.
Regards,
John
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13528 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: A few question about Wiki Script Object examples
I'm currently rewriting the scripted object wiki, so I'm curious as to what doesn't work.
Post your code (use the code tags button </> when you do!) and your system information.. You can get the system information from Help -> About and click 'Copy to Clipboard'. Then paste the results in your message.
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: A few question about Wiki Script Object examples
The basic example, I got a red box on the right. But the complex example, I can't see anything on the right..
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: A few question about Wiki Script Object examples
Right, but it helps to show your code as well. For example, I don't know if you created the ViewProvider and passed it a reference to your ViewObject (which is the last line of that code segment). That can be a chief cause. Another cause would be an error in your code. Is your icon in color or is it gray?
At very least, did you recompute the document? If there's a blue checkmark on the icon, then it means the object needs to be recomputed, so you need to click the two circling arrows (look kind of like a 'recycle' symbol). The other thing you could try is clicking the 'fit view' button. It's the button with the magnifying glass on top of the page at the left of the lower toolbar.
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: A few question about Wiki Script Object examples
The icon is colored with a blue tick.After hiting recompute, all good.
I just copied that 3 part codes in one. Need to add a line for recompute to see the result.
The basic example also needs a recompute, but shows the cube well without the recomputer.
I noticed there is a few lines of string in "". Not led by a comment letter #, but python seems has no issue.
I just copied that 3 part codes in one. Need to add a line for recompute to see the result.
The basic example also needs a recompute, but shows the cube well without the recomputer.
I noticed there is a few lines of string in "". Not led by a comment letter #, but python seems has no issue.
Last edited by johnwang on Sun Mar 31, 2019 1:39 am, edited 1 time in total.
Re: A few question about Wiki Script Object examples
Another question: For the basic example, Where I put the line:
Is it just after this?
I think I should also change to:
But run like that, I don't know where I could see the list of available properties, in Python console?
Code: Select all
obj.supportedPropeties()
Code: Select all
a=FreeCAD.ActiveDocument.addObject("Appp::FeaturePython","Box")
I think I should also change to:
Code: Select all
a.supportedPropeties()
Last edited by johnwang on Sun Mar 31, 2019 7:58 am, edited 4 times in total.
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: A few question about Wiki Script Object examples
You can call supportedProperties() on the object itself and it will tell you which ones it supports. The other thing you can do is type:
Code: Select all
>>> dir(a)
As for the examples, I'm rewriting them completely to be simpler and hopefully clearer, so I'm probably not going to worry too much about corrections to the existing ones at the moment.
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: A few question about Wiki Script Object examples
I suspect you're talking about the doc strings that show up just after the start of a method or class?
Code: Select all
def my_methd(self):
"""
This is a docstring
"""
While I'm thinking of it, if you plan on doing nay significant Python development, you might want to set up a development environment if you haven't already. VSCode is good and has python support (including pylint, which tells you when you're writing badly-formatted or wrong code).
Maybe I should add a section like that to the documentation.
Incidentally, here's the first part of what I've been writing - I don't know if you'll find it useful:
https://www.freecadweb.org/wiki/FeaturePython_Objects
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: A few question about Wiki Script Object examples
Happy to know the folder structure and py file. I was using FCMacro file before.
I thought the inspect attributes part maybe better talk later. I can't see the benefit I know it now.
No argument to call FreeCAD.getUserMarcoDir{) on my computer.
I am interested in making the object selectable.
I thought the inspect attributes part maybe better talk later. I can't see the benefit I know it now.
No argument to call FreeCAD.getUserMarcoDir{) on my computer.
I am interested in making the object selectable.
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: A few question about Wiki Script Object examples
You shouldn't need to pass an argument...?
The current Scripted Objects tutorial has a section on that, but I don't think it's necessary any longer. That is, if you base your scripted object on a Part::FeaturePython (instead of App::FeaturePython), and assign the appropriate ViewProvider, it should behave as a normal object in FreeCAD and should be selectable.
If you have a particular thing you want to create, I recommend starting with that (or a simple example like it), rather than just working through the tutorials. It's often more helpful to create something you want, rather than just reading and following tutorials.

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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers