Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-11 Thread Wangshiraz

Hi Thomas,

I use:
my_shape_list = my_context.get_shapes()
and
iges_writer.AddShape(my_shape_list[0])


I found [0] is the object I wanted from the  test_box_booleans_fillets.py under 
samples\Level2\PAF.

Here are my final code:

from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters

import time

def main():
p = Parameters()  # Create a parameters set
my_context = ParametricModelingContext(p, commit=False) # Create and 
initialize a parametric context
my_context.init_display() # start the graphic display


# we need to register the operations that are used
# for concerns of performance, _only_ operations that are registered
# are associative 
my_context.register_operations(my_context.basic_operations,
   my_context.boolean_operations,
   my_context.local_operations
   )
# Create parameters
p.X1, p.Y1, p.Z1 = 0,0,0
p.X2, p.Y2, p.Z2 = 30,30,30

p.X3, p.Y3, p.Z3 = 5,5,-10
p.X4, p.Y4, p.Z4 = 20,20,40

p.RADIUS = 1

# points box 1  
my_pnt1 = my_context.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, 
name="Pnt1")   # Create the first point box1
my_pnt2 = my_context.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, 
name="Pnt2")   # Create the second point box1

# points box 2
my_pnt3 = my_context.basic_operations.MakePointXYZ(p.X3,p.Y3,p.Z3, 
name="Pnt3")   # Create the first point box2
my_pnt4 = my_context.basic_operations.MakePointXYZ(p.X4,p.Y4,p.Z4, 
name="Pnt4")   # Create the second point box2

# create boxes
box1 = 
my_context.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", 
show=True)# Create the box
box2 = 
my_context.prim_operations.MakeBoxTwoPnt(my_pnt3,my_pnt4,name="Box2", 
show=True)# Create the box

# boolean subtract box2 from box1 
booled_box = my_context.boolean_operations.MakeBoolean( box1, box2, 2, 
name='BooleanBox', show=False)

# add fillets to the booleaned box
fillet_box = my_context.local_operations.MakeFilletAll( booled_box, 
p.RADIUS, name='FilletBox', show=True)

# configuring presentations
pres1, pres2, pres_fillet = my_context.get_presentation(box1), 
my_context.get_presentation(box2), my_context.get_presentation(fillet_box)
pres1.SetTransparency(.8); pres1.SetColor(12) 
pres2.SetTransparency(.8); pres1.SetColor(12)
pres_fillet.SetColor(1)

my_context.start_display()
my_shape_list = my_context.get_shapes()
from OCC import IGESControl
i = IGESControl.IGESControl_Controller()
i.Init()
iges_writer = IGESControl.IGESControl_Writer()
iges_writer.AddShape(my_shape_list[0])
print "added an object to the IGES file. "
iges_writer.Write("my_fillet_n.iges")


def profile_main():
 # This is the main function for profiling 
 # We've renamed our original main() above to real_main()
 import cProfile, pstats
 prof = cProfile.Profile()
 prof = prof.runctx("main()", globals(), locals())
 print ""
 stats = pstats.Stats(prof)
 stats.sort_stats("time")  # Or cumulative
 stats.print_stats(80)  # 80 = how many to print
 # The rest is optional.
 stats.print_callees()
 stats.print_callers()
 print ""

#profile_main()
main()



> 
> With 'upper bound', you mean the last element of the list, right?
> 
> >>> a = [1,2,3,4,5]
> >>> a[-1]
> 5
> 
> Thomas
> 

  
_
一张照片的自白――Windows Live照片的可爱视频介绍
http://windowslivesky.spaces.live.com/blog/cns!5892B6048E2498BD!889.entry___
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users


Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-10 Thread Thomas Paviot
With 'upper bound', you mean the last element of the list, right?

>>> a = [1,2,3,4,5]
>>> a[-1]
5

Thomas

2010/7/10 Wangshiraz 

>  Hi Thomas,
>
> I am using 0.4. I can export the IGES now. So cool.
>
> Just wondering is there a function to get the upper bound of the list? The
> last shape in the list is what I want to saved.
>
> Regards,
>
> Cean
>
> > Message: 2
> > Date: Fri, 9 Jul 2010 15:25:23 +0200
> > From: Thomas Paviot 
> > Subject: Re: [Pythonocc-users] parametric drawing in PythonOCC
>
> >
> > IGESControl (as well as STEPControl) takes TopoDS_Shape instance as a
> > parameter.
> >
> > If you run pythonOCC-0.4, use the get_shapes() method of the
> > ParametricModelingContext instance. You'll get a list of TopoDS_Shapes
> you
> > can pass to the IGES or STEP exporter.
> >
> > In the latest svn trunk revision, this method was replaced by the
> > get_shape() method: box_shape = my_context.get_shape(my_box)
> >
> > Thomas
> >
> > ***
>
> --
> 使用新一代 Windows Live Messenger 轻松交流和共享! 
> 立刻下载!<http://www.windowslive.cn/messenger/>
>
> ___
> Pythonocc-users mailing list
> Pythonocc-users@gna.org
> https://mail.gna.org/listinfo/pythonocc-users
>
>
___
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users


Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-10 Thread Wangshiraz

Hi Thomas,

I am using 0.4. I can export the IGES now. So cool.

Just wondering is there a function to get the upper bound of the list? The last 
shape in the list is what I want to saved.

Regards,

Cean

> Message: 2
> Date: Fri, 9 Jul 2010 15:25:23 +0200
> From: Thomas Paviot 
> Subject: Re: [Pythonocc-users] parametric drawing in PythonOCC
> 
> IGESControl (as well as STEPControl) takes TopoDS_Shape instance as a
> parameter.
> 
> If you run pythonOCC-0.4, use the get_shapes() method of the
> ParametricModelingContext instance. You'll get a list of TopoDS_Shapes you
> can pass to the IGES or STEP exporter.
> 
> In the latest svn trunk revision, this method was replaced by the
> get_shape() method: box_shape = my_context.get_shape(my_box)
> 
> Thomas
> 
> ***
  
_
MSN十年回馈,每位用户可免费获得价值25元的卡巴斯基反病毒软件2010激活码,快来领取!
http://kaba.msn.com.cn/?k=1___
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users


Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-09 Thread Thomas Paviot
IGESControl (as well as STEPControl) takes TopoDS_Shape instance as a
parameter.

If you run pythonOCC-0.4, use the get_shapes() method of the
ParametricModelingContext instance. You'll get a list of TopoDS_Shapes you
can pass to the IGES or STEP exporter.

In the latest svn trunk revision, this method was replaced by the
get_shape() method: box_shape = my_context.get_shape(my_box)

Thomas

2010/7/9 Wangshiraz 

>  Hi,
>
> I am looking at this PAF sample - test_box.py. But have no idea how to
> export the box in STEP or IGES file. It seems the box can't be added with
> IGESControl.IGESControl_Writer().AddShape().
>
> Any help?
>
> Thanks
>
>
> >
> > An example of how to use both parametric and meshing frameworks using
> > callbacks is available at:
> >
> http://code.google.com/p/pythonocc/source/browse/trunk/src/examples/Level2/PAF/paf_smesh.py
> >
> > ***
>
> --
> 更多热辣资讯尽在新版MSN首页! 立刻访问! 
>
> ___
> Pythonocc-users mailing list
> Pythonocc-users@gna.org
> https://mail.gna.org/listinfo/pythonocc-users
>
>
___
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users


Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-09 Thread Wangshiraz

Hi,

I am looking at this PAF sample - test_box.py. But have no idea how to export 
the box in STEP or IGES file. It seems the box can't be added with 
IGESControl.IGESControl_Writer().AddShape(). 

Any help?

Thanks

> 
> An example of how to use both parametric and meshing frameworks using
> callbacks is available at:
> http://code.google.com/p/pythonocc/source/browse/trunk/src/examples/Level2/PAF/paf_smesh.py
> 
> ***
  
_
约会说不清地方?来试试微软地图最新msn互动功能!
http://ditu.live.com/?form=TL&swm=1___
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users


Re: [Pythonocc-users] parametric drawing in PythonOCC

2010-07-09 Thread Thomas Paviot
Hi Pierre,

The parametric framework has been made interoperable with other packages by
adding two callbacks:
- a 'pre-solver' callback, which is called before the geometric solver is
called;
- a 'post-solver' callback, which is called just after the new geometry is
solved.

You can register as many functions as you want into these callbacks. You can
get the current state of the TopoDS_Shape.

An example of how to use both parametric and meshing frameworks using
callbacks is available at:
http://code.google.com/p/pythonocc/source/browse/trunk/src/examples/Level2/PAF/paf_smesh.py

The most important line of this example is the line 118:

my_context.register_post_solver_callback(mesh_and_display)

The 'mesh_and_display' function will be called each time a parameter is
changed.

Best Regards,

Thomas

2010/7/6 Pierre JUILLARD 

>
> Dear all,
>
> May I know what is the current status of the pythonOCC parametric
> framework?
> I have read in this email last year that it was a hard work going on, and
> that the next step would be to link this framework with solvers (constraint
> programming, evolutionary computing etc.).
> May I know if this step has begun, and if some constraint solvers have been
> evaluated?
>
> Thanks in advance for the news.
>
> Bests,
>
> Pierre
>
>
>
>
> Posted by *Thomas Paviot* on July 05, 2009 - 10:36:
> Hi all,
>
> Based on the SalomeGEOM library, which was included a few weeks ago in
> pythonOCC (see the subversion trunk), a pure python prametric framework is
> currently being (actively) developped.
>
> This parametric framework is based on four main classes:
> - the Parameter class: creation of parameters,
> - the Facotry class: creation of geometry based on the parameters,
> - the Rule class: enable to attach one or more rules to a Parameter. The
> rule consists of a function that returns a boolean: True if the rule is
> validated, false otherwise,
> - the Relation class: create relations between parameters. This class is
> based on sympy (http://code.google.com/p/sympy/), a Python library for
> symbolic mathematics.
>
> Then, each time a parameter is changed (which can be done from a ipython
> -wthread interactive console):
> - the new values of parameters are computed according to the different
> Relations that have been set up,
> - the Rules are checked.
>
> It's not finished yet, and the result has not yet been uploaded to the
> subversion trunk, but it should be done in a few days (weeks?), once the API
> is stable (it's still moving almost every day). It's mostly based on python
> descriptors (http://users.rcn.com/python/download/Descriptor.htm), with an
> intensive use of callbacks and operator overloading. Of course, thanks to
> the magic of Python, this framework is currently only 500 lines of
> pythoncode.
>
> Although it's not available yet, here is a small sample I made, called the
> 'gears' sample. The diameter of the gears and the relative position are
> driven by two parameters: the velocity ratio (r) and the distance between
> axis (a). Every change in those parameters modifies the geometry in
> consequence, if the rules are validated. The syntax could change in the
> future, but the architecture is defined and should be stable.
>
> The work that still have to be done:
> - simplify the API (there's still a possible confusion with the handle of
> parameters by strings "p.X" or attributes p.X),
> - check the stability of the API, in case, for instance, of cyclic
> references between parameters,
> - and, in a mid term, link this framework with solvers (constraint
> programming, evolutionary computing etc.) in order to find solutions to
> engineering problems as defined by the (Rules,Relations).
>
> Of course, I'll let you know about the future developments of this project.
>
> Best Regards,
>
> Thomas
>
> ##Copyright 2009 Thomas Paviot (tpav...@x)
> ##
> ##This file is part of pythonOCC.
> ##
> ##pythonOCC is free software: you can redistribute it and/or modify
> ##it under the terms of the GNU General Public License as published by
> ##the Free Software Foundation, either version 3 of the License, or
> ##(at your option) any later version.
> ##
> ##pythonOCC is distributed in the hope that it will be useful,
> ##but WITHOUT ANY WARRANTY; without even the implied warranty of
> ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> ##GNU General Public License for more details.
> ##
> ##You should have received a copy of the GNU General Public License
> ##along with pythonOCC.  If not, see .
>
> # A sample that shows how to generate the gear geometry according
> # to knowledge
>
> from Context import Context
> import Parametric
> from Parametric import Parameters, symb, Relation
> import Factory
> import Presentation
> from math import pi
> from sympy import *
>
> #
> # Initialization
> #
> my_context = Context()
> my_context.Init()
> my_presentation = Presentation.Presentation(my_context)
> p = Parameters(my_context)
> p.