Creating an Image Plane in Python Script

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
phixxx5
Posts: 10
Joined: Tue Jul 27, 2021 1:36 pm

Creating an Image Plane in Python Script

Post by phixxx5 »

Hi,
I'm new to FreeCAD and I'm working on a custom workbench. At the moment I am trying to create an Image Plane in my Python script similarly to the Image Plane I can create in the GUI in the Image workbench. I have tried the following:

Code: Select all

import FreeCAD, FreeCADGui
import Image, ImageGui
import Part, PartGui


class PlaceImage:

    def Activated(self):
        """ This code gets executed when the corresponding button is pressed."""
        doc = FreeCAD.activeDocument()
        img_plane = doc.addObject("Image::ImagePlane', 'ImagePlane")
However I see the error:

Code: Select all

No document object found of type 'Image::ImagePlane', 'ImagePlane'
What am I doing wrong? Do I have to implement my own ImagePlane Class in Python?
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Creating an Image Plane in Python Script

Post by onekk »

Something wrong you wrote:

Code: Select all

img_plane = doc.addObject("Image::ImagePlane', 'ImagePlane")
instead of :

Code: Select all

img_plane = doc.addObject("Image::ImagePlane", "ImagePlane")
or:

Code: Select all

img_plane = doc.addObject('Image::ImagePlane', 'ImagePlane')
the error code:

Code: Select all

'Image::ImagePlane', 'ImagePlane'
is showing that FreeCAD is searching for the whole string shown that is obviously "strange", as there is the name of the object in it instead of:

Code: Select all

'Image::ImagePlane'
That would be more correct for a "object type".


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/
phixxx5
Posts: 10
Joined: Tue Jul 27, 2021 1:36 pm

Re: Creating an Image Plane in Python Script

Post by phixxx5 »

Thank you! What a stupid mistake :oops:
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Creating an Image Plane in Python Script

Post by onekk »

It happens, more frequently than you could immagine.

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/
Post Reply