Missing import in "importWebGL.py" code?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
nyholku
Posts: 149
Joined: Wed Dec 28, 2016 4:18 pm

Missing import in "importWebGL.py" code?

Post by nyholku »

Hi,

trying to experiment with some code grabbed from 'importWebGL.py' but Eclipse flags

https://github.com/FreeCAD/FreeCAD/blob ... rtWebGL.py

line 183

Code: Select all

wo = Part.Wire(Part.__sortEdges__(w.Edges))
as:

Code: Select all

"Undefined variable from import: Wire"
"Undefined variable from import:__sortEdges__"
I expect the code is correct since I grabbed that from FreeCAD source on my machine.

As I'm not yet able to execute this code this can of course be a false positive
by Eclipse and the possibly the code would execute under FreeCAD.

Still wondering if I'm missing an import (which may be implicit when run under
FreeCAD) and if so, what am I missing and how do I go about in the general
case to find out problems like this?

I looked at the FreeCAD Python API reference for Wire and __sortEdges__ but
drew blank. The reference looks a bit sort to me for a project of this complexity,
is it complete?
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Missing import in "importWebGL.py" code?

Post by yorik »

You have to first import FreeCAD then import Part. For this you have to add the folder containing your FreeCAD.so (Linux and Mac) or FreeCAD.pyd (Windows) to python's sys.path. When importing FreeCAD, it will automatically add all the paths to its submodules, so after that any module such as Part can be imported.

Code: Select all

import sys
sys.path.append("/path/to/your/FreeCAD.so_or_FreeCAD.pyd")
import FreeCAD
import Part
nyholku
Posts: 149
Joined: Wed Dec 28, 2016 4:18 pm

Re: Missing import in "importWebGL.py" code?

Post by nyholku »

For posterity, this is verbatim what I did to make this work, thanks Yorik.

Code: Select all

import sys
sys.path.append("/Applications/FreeCAD.app/Contents/lib")
import FreeCAD
import Part
Still need to convince Eclipse that the 'Wire' thing I mention in the original post is ok as it apparently is cause it looks like not only does the import work but the code executes too without exceptions.
Post Reply