Learn how to get started with the Parametric Application Framework, a package enabling advanced parametric modeling features. This tutorial is available from the following PDF file.
pythonocc_parametric_modeling_tutorial (PDF file)
Please leave any comment to improve it.
3.2: tc/tutorial_context confusion returns. File executes with errors on
tc . register_operations ( tutorial_context . prim_operations)However…
In [4]: run tutorial_paf_part1.pydoes manage to generate a view window! I don't know why it didn't before, when I was entering lines into IPython CLI manually. Correcting tc variable shows wx window properly. Pretty!
3.3.2:
symbols . radius = p. radius . symbolresults in
NameError: name 'symbols' is not definedFix:
radius = p. radius . symboldrop the preceding ‘symbols’
3.4.3:
#create a rule and connect it to the parameter
def IsPositive(x): return x>0
Rule(p, "radius" , IsPositive )
Seems to be out of order, bad indent.
Solution: move function definition to beginning of file, un-indent Rule line
@Ethan Thanks for your insightful comments. Anyway, I have to review this document and update it to the latest improvements of the 0.5 pythonOCC release.
Hi,
The piece of code is not working.
————————————————
C:\pythtut\para.py in ()
8 tc = ParametricModelingContext(p)
9
—> 10 tc.init_display()
11 p.height = 43.3
12
————————————————
when I changed to init_display() and imported ‘from OCC.Display.SimpleGui import *’ line
It starts giving error of
————————————————-
C:\Python26\lib\site-packages\OCC\PAF\Parametric.pyc in __setattr__(self, name,
value)
210 # create a Parameter instance, and add it to the dict
211 # that shadows self.attributes
–> 212 self._parameters[name] = Parameter(name, value)
213
214 # add the parameter to the Interpreter ( which does the real wor
k )
C:\Python26\lib\site-packages\OCC\PAF\Parametric.pyc in __init__(self, name, val
ue)
148 print “[PAF] Parameter %s created”%name
149
–> 150 self._symbol = sympy.Symbol(name)
151 self._value = value
152
NameError: global name ‘sympy’ is not defined
WARNING: Failure executing file:
————————————————–
Please give me the soln and try to run before posting it as tutorial/wiki/blog.
I have installed following things on my windows machine
python 2.6, ipyhton, wxpython, OCC, pythonOCC.
The example files in pythonOCC folder is working fine.
Thanks
Nikhil
@Nikhil You need to install the sympy library (http://code.google.com/p/sympy/). You’ll be able to run the example.
Thanks Thomas,
What is the use of sympy? What making difference that pythonocc tut files are running but not this blog file? Please clarify.
I installed the sympy form the link. While installing I got few message eg:
“Could not set key value” for some fields. Even though it gave me message that installation complete.
I ran again the code after installation and this time same error:
In [11]: run para.py
MSG:..\..\src\GEOMImpl\GEOMImpl_IShapesOperations.cpp [142] : GEOMImpl_IShapesOp
erations::GEOMImpl_IShapesOperations
[PAF] all operations registered
[PAF] ParametricModelingContext initialized
—————————————————————————
AttributeError Traceback (most recent call last)
C:\pythtut\para.py in ()
8 tc = ParametricModelingContext(p)
9
—> 10 tc.init_display()
11 p.height = 43.3
12
AttributeError: ‘ParametricModelingContext’ object has no attribute ‘init_displa
y’
WARNING: Failure executing file:
Thanks
Nikhil
Some how I am able to now to run the code without any error. Here are my final lines. I have to do some changes.
—————-
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters
from OCC.Display.SimpleGui import *
p = Parameters()
tc = ParametricModelingContext(p)
init_display()
p.height = 43.3
p.radius = 12.9
tc.register_operations(tc.prim_operations)
my_cylinder = tc.prim_operations.MakeCylinderRH(p.radius,
p.height, name=”cylinder1″, show=True)
—————————-
It is opening the pythonocc 3d viewer, but not showing the cylinder in this viewer.
Here is message in the console.
———————————
In [10]: run para.py
MSG:..\..\src\GEOMImpl\GEOMImpl_IShapesOperations.cpp [142] : GEOMImpl_IShapesOp
erations::GEOMImpl_IShapesOperations
[PAF] all operations registered
[PAF] ParametricModelingContext initialized
###### 3D rendering pipe initialisation #####
Display3d class initialization starting …
WNT Graphic device created.
WNT window created.
Viewer created.
Interactive context created.
Display3d class successfully initialized.
########################################
[PAF] Parameter height created
[PAF] parameter: _commit value: False
[PAF] Parameter radius created
[PAF] parameter: _commit value: False
[PAF] parameter: radius value: 12.9
[PAF] parameter: height value: 43.3
[PAF] got *args: (, <OCC.P
AF.Parametric.Parameter; proxy of >, <OCC.PAF.Parametric.Parameter; proxy of >)
[PAF] modified args: (<OCC.PAF.Parametric.Parameter; proxy of >, <OCC.PAF.Parametric.Parameter; proxy of
>)
[PAF] got **kwargs: {‘name’: ‘cylinder1′, ‘show’: True}
[PAF] initialized context with
[PAF] start operation
[PAF] result: <OCC.SGEOM.Handle_GEOM_Object; proxy of >
[PAF] finish operation
[PAF] set object name: cylinder1
In [11]:
————————-
@nikhil Use ipython rather than the standard python console. If you use wxPython as a GUI, just do:
ipython -wthread
if you use PyQt4:
ipython -q4thread
Hi Thomas,
I am using iPython console for windows not normal python, I have installed follwing things:
python 2.6, ipyhton, wxpython, OCC, pythonOCC.
I am using following set of commnads:
ipython -wthread
run para.py
para.py contains following lines:
————————————————
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters
from OCC.Display.SimpleGui import *
p = Parameters()
tc = ParametricModelingContext(p)
init_display()
p.height = 43.3
p.radius = 12.9
tc.register_operations(tc.prim_operations)
my_cylinder = tc.prim_operations.MakeCylinderRH(p.radius,
p.height, name=”cylinder1″, show=True)
box_shape = tc.get_shape(my_cylinder)
——————————————————
NIkhil