Importing py interfaces of other modules

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
kamichal
Posts: 5
Joined: Thu Dec 21, 2017 8:34 pm

Importing py interfaces of other modules

Postby kamichal » Thu Dec 21, 2017 9:04 pm

Hi all, It's my first post. My name is Michal. Professionally I'm a python developer.

I want to create FreeCad extension for own purposes. I assumed it would be ok to find some similar command as I need and accomodate it to my needs. Now I'm facing import problem (I use Linux Debian). Seems that I don't understand the border between C++ and python world.

I picked _CommandWall from ArchWall.py. With such a code:

Code: Select all

 import Part
trace = Part.LineSegment(start_point, end_point)
I get:

Code: Select all

AttributeError: 'module' object has no attribute 'LineSegment'
So my question is: What's going on?
Seems that ArchWall has no problem with equivalent statement in getPoint() method.

So I can import Part module, but seems it's different one that ArchWall is importing.
When I print path of the imported module just after importing it - I get:

Code: Select all

/usr/lib/freecad/lib/Part.so
in both places (my workbench and Arch workbench).
As I debugged so far dir(Part) also returns the same list of defined symbols.
What do I do wrong?

Thanks in advance.
Michal
kamichal
Posts: 5
Joined: Thu Dec 21, 2017 8:34 pm

Re: Importing py interfaces of other modules

Postby kamichal » Fri Dec 22, 2017 10:20 am

Seems that my question is too long.
Does anyone can tell me what do I miss here?

I start freecad, open any workbench and PythonConsole, then I type that and I'm getting:

Code: Select all

Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> import Part
>>> 
>>> Part.LineSegment()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'LineSegment'
>>>
>>> for s in dir(Part):
...   print s
... 
Arc
ArcOfCircle
ArcOfEllipse
ArcOfHyperbola
ArcOfParabola
BRepOffsetAPI
BSplineCurve
BSplineSurface
BezierCurve
BezierSurface
Circle
CompSolid
Compound
Cone
Cylinder
Edge
Ellipse
Face
Feature
Hyperbola
Line
OCCConstructionError
OCCDimensionError
OCCDomainError
OCCError
OCCRangeError
OffsetCurve
OffsetSurface
Parabola
Plane
PlateSurface
Point
RectangularTrimmedSurface
Shape
Shell
Solid
Sphere
SurfaceOfExtrusion
SurfaceOfRevolution
Toroid
Vertex
Wire
__doc__
__file__
__fromPythonOCC__
__name__
__package__
__sortEdges__
__toPythonOCC__
cast_to_shape
export
exportUnits
getSortedClusters
insert
makeBox
makeCircle
makeCompound
makeCone
makeCylinder
makeFilledFace
makeHelix
makeLine
makeLoft
makeLongHelix
makePlane
makePolygon
makeRevolution
makeRuledSurface
makeShell
makeSolid
makeSphere
makeSweepSurface
makeThread
makeTorus
makeTube
makeWedge
makeWireString
open
read
setStaticValue
show
>>> 
User avatar
Chris_G
Posts: 1203
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Importing py interfaces of other modules

Postby Chris_G » Fri Dec 22, 2017 11:02 am

What is your FC version.
I think Part.LineSegment was not available in FC 0.16
kamichal
Posts: 5
Joined: Thu Dec 21, 2017 8:34 pm

Re: Importing py interfaces of other modules

Postby kamichal » Fri Dec 22, 2017 3:36 pm

I have Freecad at version 0.16. I took the code from github's master branch.
triplus
Posts: 9108
Joined: Mon Dec 12, 2011 4:45 pm

Re: Importing py interfaces of other modules

Postby triplus » Fri Dec 22, 2017 5:30 pm

Hi @kamichal.

The Python API changed:

https://forum.freecadweb.org/viewtopic.php?f=10&t=18767

And likely you are using instructions/documentation not suitable for the version of FreeCAD you use.