python scripting

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
emills
Posts: 36
Joined: Fri Jan 06, 2012 3:17 am

python scripting

Post by emills »

OS: Windows 7
Platform: 32-bit
Version: 0.13.1828
Python version: 2.6.2
Qt version: 4.5.2
Coin version: 3.1.0
SoQt version: 1.4.1
OCC version: 6.3.0

hi, i'm trying to use the following snippet (that i lifted from one of Werner's examples) in my code

Code: Select all

shape = App.ActiveDocument.ActiveObject.Shape
and it works in the console, but when i embed it in a script and run the script i get

Code: Select all

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:/Users/Edward/Desktop/EVM/freecad stuff/FCPython\reconstruct_SVG_import.py", line 4, in <module>
    shape = App.ActiveDocument.ActiveObject.Shape
NameError: name 'App' is not defined
here are the imports at the beginning of my script

Code: Select all

import Part
from FreeCAD import Base
from FreeCAD import Gui
import math
i don't know where to pull "App" from. I don't know if this is the best method to pass my selection.

my goal here is to extract BSpline info from imported SVG files, and if i put each line in the interpreter it all works. Any help greatly appreciated :)
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: python scripting

Post by shoogen »

Code: Select all

import FreeCAD
import FreeCADGui
App=FreeCAD
Gui=FreeCADGui
emills
Posts: 36
Joined: Fri Jan 06, 2012 3:17 am

Re: python scripting

Post by emills »

thanks, that works.
Post Reply