├── src ├── Rice │ ├── __init__.py │ ├── baseClasses │ │ ├── __init__.py │ │ ├── anyObject.py │ │ └── collection.py │ ├── abstractObjects │ │ ├── __init__.py │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ ├── pad.py │ │ │ ├── pocket.py │ │ │ └── circPattern.py │ │ ├── documents │ │ │ ├── __init__.py │ │ │ └── part.py │ │ ├── hybridShapes │ │ │ ├── __init__.py │ │ │ ├── join.py │ │ │ ├── fill.py │ │ │ ├── spline.py │ │ │ ├── point.py │ │ │ ├── line.py │ │ │ ├── plane.py │ │ │ └── combine.py │ │ ├── geometric2Delements │ │ │ ├── __init__.py │ │ │ ├── curve2D.py │ │ │ ├── controlPoint2D.py │ │ │ ├── point2D.py │ │ │ ├── spline2D.py │ │ │ ├── line2D.py │ │ │ └── circle2D.py │ │ ├── geometricElement.py │ │ ├── hybridShape.py │ │ ├── geometry2D.py │ │ ├── document.py │ │ └── shape.py │ ├── collectionsObject │ │ ├── __init__.py │ │ ├── windows.py │ │ ├── geometricElements.py │ │ ├── parameters.py │ │ ├── relations.py │ │ ├── sketches.py │ │ ├── orderedGeometricalSets.py │ │ ├── bodies.py │ │ ├── settings.py │ │ ├── documents.py │ │ ├── hybridBodies.py │ │ └── constraints.py │ ├── generalObjects │ │ ├── __init__.py │ │ ├── point.py │ │ ├── relation.py │ │ ├── selection.py │ │ ├── parameter.py │ │ ├── orderedGeometricalSet.py │ │ ├── constraint.py │ │ ├── originElements.py │ │ ├── factory.py │ │ ├── hybridBody.py │ │ ├── body.py │ │ └── sketch.py │ ├── factoryTypes │ │ ├── 2DfactoryMeth │ │ │ ├── __init__.py │ │ │ ├── addPoint.py │ │ │ ├── addSpline.py │ │ │ ├── addControlPoint.py │ │ │ ├── addCircle.py │ │ │ ├── addLine.py │ │ │ └── addArc.py │ │ ├── __init__.py │ │ ├── shapeFactoryMeth │ │ │ ├── __init__.py │ │ │ ├── addNewPad.py │ │ │ ├── addNewPocket.py │ │ │ └── addNewSurfacicCircPattern.py │ │ ├── hybridShapeFactoryMeth │ │ │ ├── __init__.py │ │ │ ├── addNewPlane1Curve.py │ │ │ ├── addNewLinePtPt.py │ │ │ ├── addNewSpline.py │ │ │ ├── addNewPointCoord.py │ │ │ ├── addNewFill.py │ │ │ ├── addNewPlaneOffset.py │ │ │ ├── addNewCombine.py │ │ │ └── addNewJoin.py │ │ ├── factory2D.py │ │ ├── hybridShapeFactory.py │ │ └── shapeFactory.py │ ├── miscellaneous │ │ ├── __init__.py │ │ ├── stdOutput.py │ │ ├── tools.py │ │ └── orderDict.py │ └── application.py └── setup.py ├── readme_images ├── alabe.png ├── 50mmCube.png └── 50mmPocket.png └── README.md /src/Rice/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/baseClasses/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/documents/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | -------------------------------------------------------------------------------- /src/Rice/miscellaneous/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | -------------------------------------------------------------------------------- /src/Rice/miscellaneous/stdOutput.py: -------------------------------------------------------------------------------- 1 | 2 | def output(x): 3 | print(x) -------------------------------------------------------------------------------- /src/Rice/factoryTypes/shapeFactoryMeth/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/curve2D.py: -------------------------------------------------------------------------------- 1 | 2 | class Curve2D(object): 3 | pass -------------------------------------------------------------------------------- /readme_images/alabe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robertpardillo/rice/HEAD/readme_images/alabe.png -------------------------------------------------------------------------------- /readme_images/50mmCube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robertpardillo/rice/HEAD/readme_images/50mmCube.png -------------------------------------------------------------------------------- /readme_images/50mmPocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robertpardillo/rice/HEAD/readme_images/50mmPocket.png -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewPlane1Curve.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | 4 | def AddNewPlane1Curve(parent, cat_constructor, curve): 5 | pass -------------------------------------------------------------------------------- /src/Rice/generalObjects/point.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Point(object): 4 | def __init__(self, parent, cat_constructor=None, *args): 5 | self.parent = parent 6 | self.cat_constructor = cat_constructor -------------------------------------------------------------------------------- /src/Rice/collectionsObject/windows.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | 4 | 5 | class Windows(Collection): 6 | def __init__(self, parents_dict): 7 | super(Windows, self).__init__(parents_dict, 'Windows') 8 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/relation.py: -------------------------------------------------------------------------------- 1 | 2 | class Relation(object): 3 | def __init__(self, parent, cat_constructor): 4 | self.parent = parent[parent[-1]] 5 | self.parentsDict = parent 6 | self.cat_constructor = cat_constructor 7 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addPoint.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.point2D import Point2D 3 | 4 | 5 | def AddPoint(self, xc, yc): 6 | obj = Point2D(self.parentsDict._copy(), self, xc, yc) 7 | obj.paint() 8 | 9 | return obj -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addSpline.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.spline2D import Spline2D 3 | 4 | 5 | def AddSpline(self, points): 6 | obj = Spline2D(self.parentsDict._copy(), self, points) 7 | obj.paint() 8 | 9 | return obj -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addControlPoint.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.controlPoint2D import ControlPoint2D 3 | 4 | 5 | def AddControlPoint(self, point): 6 | obj = ControlPoint2D(self.parentsDict._copy(), self, point) 7 | obj.paint() 8 | 9 | return obj -------------------------------------------------------------------------------- /src/Rice/miscellaneous/tools.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import numpy 4 | 5 | __author__ = 'roberto' 6 | 7 | 8 | def rad_degrees(type_to, value): 9 | if type_to == 'rad': 10 | value = value*numpy.pi/180 11 | if type_to == 'deg': 12 | value = value*180/numpy.pi 13 | return value -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addCircle.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.circle2D import Circle2D 3 | 4 | 5 | def AddCircle(self, center, r): 6 | obj = Circle2D(self.parentsDict._copy(), self, center, r, 0, 0) 7 | obj.paint() 8 | obj.center_point() 9 | 10 | return obj -------------------------------------------------------------------------------- /src/Rice/factoryTypes/shapeFactoryMeth/addNewPad.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.shapes.pad import Pad 3 | 4 | 5 | def AddNewPad(self, parent, sketch, limit): 6 | cat_constructor = self.cat_constructor.AddNewPad(sketch.cat_constructor, limit) 7 | pad = Pad(parent, cat_constructor, sketch, limit) 8 | return pad -------------------------------------------------------------------------------- /src/Rice/abstractObjects/shapes/pad.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from ..shape import Shape 4 | 5 | 6 | class Pad(Shape): 7 | 8 | def __init__(self, parent, cat_constructor, sketch, limit): 9 | super(Pad, self).__init__(parent, cat_constructor) 10 | self.sketch = sketch 11 | self.limit = limit 12 | 13 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/join.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Join(HybridShape): 6 | """ 7 | Result of join operation 8 | """ 9 | def __init__(self, parent, cat_constructor, objs): 10 | super(Join, self).__init__(parent, cat_constructor) 11 | self.objs = objs -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addLine.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.point2D import Point2D 3 | from ...abstractObjects.geometric2Delements.line2D import Line2D 4 | 5 | 6 | def AddLine(self, start, end): 7 | obj = Line2D(self.parentsDict._copy(), self, start, end) 8 | obj.paint() 9 | 10 | return obj -------------------------------------------------------------------------------- /src/Rice/factoryTypes/shapeFactoryMeth/addNewPocket.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | from ...abstractObjects.shapes.pocket import Pocket 4 | 5 | 6 | def AddNewPocket(self, parent, sketch, limit): 7 | construc = self.cat_constructor.AddNewPocket(sketch.cat_constructor, limit) 8 | poc = Pocket(parent, construc, sketch, limit) 9 | return poc -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/fill.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Fill(HybridShape): 6 | """ 7 | Result of fill operation. 8 | """ 9 | def __init__(self, parent, cat_constructor, references): 10 | super(Fill, self).__init__(parent, cat_constructor) 11 | self.objs = references -------------------------------------------------------------------------------- /src/Rice/collectionsObject/geometricElements.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | 4 | 5 | class GeometricElements(Collection): 6 | 7 | def __init__(self, parent): 8 | super(GeometricElements, self).__init__(parent, 'GeometricElements') 9 | 10 | def add(self, obj): 11 | super(GeometricElements, self).add(obj) 12 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/2DfactoryMeth/addArc.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.circle2D import Circle2D 3 | 4 | 5 | def AddArc(self, center, r, start, end): 6 | obj = Circle2D(self.parentsDict._copy(), self, center, r, start, end) 7 | obj.paint() 8 | obj.start_point() 9 | obj.center_point() 10 | obj.end_point() 11 | 12 | return obj -------------------------------------------------------------------------------- /src/Rice/abstractObjects/shapes/pocket.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | from ..shape import Shape 4 | 5 | 6 | class Pocket(Shape): 7 | """ 8 | Result of pocket operation 9 | """ 10 | def __init__(self, parent, cat_constructor, sketch, limit): 11 | super(Pocket, self).__init__(parent, cat_constructor) 12 | self.sketch = sketch 13 | self.limit = limit 14 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/spline.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Spline(HybridShape): 6 | """ 7 | Spline 3D. 8 | """ 9 | def __init__(self, parent, cat_constructor, points): 10 | super(Spline, self).__init__(parent, cat_constructor) 11 | self.points = points 12 | 13 | def _ref_object(self): 14 | return self 15 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/selection.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Selection(object): 4 | 5 | def __init__(self, parent): 6 | """ 7 | parent: document object 8 | :param parent: 9 | """ 10 | self.parent = parent[parent[-1]] 11 | self.parentsDict = parent 12 | self.cat_constructor = self.parent.cat_constructo.Selection 13 | 14 | def add(self, obj): 15 | self.cat_constructor.Add() 16 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/point.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Point(HybridShape): 6 | pass 7 | 8 | 9 | class PointCoord(Point): 10 | """ 11 | Point 3D. Point by coord 12 | """ 13 | def __init__(self, parent, cat_constructor, coords, references): 14 | super(PointCoord, self).__init__(parent, cat_constructor) 15 | self.coords = coords 16 | self.references = references -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/line.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | from ...baseClasses.anyObject import AnyObject 4 | 5 | 6 | class Line(HybridShape): 7 | pass 8 | 9 | 10 | class LinePtPt(Line): 11 | """ 12 | Result of operation line 3D. Option point to point 13 | """ 14 | def __init__(self, parent, cat_constructor, start, end): 15 | super(LinePtPt, self).__init__(parent, cat_constructor) 16 | self.start = start 17 | self.end = end 18 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/parameters.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.parameter import Parameter 4 | 5 | 6 | class Parameters(Collection): 7 | def __init__(self, parent): 8 | super(Parameters, self).__init__(parent, 'Parameters') 9 | 10 | def create_real(self, parameterName, value): 11 | cat_constructor = self.cat_constructor.CreateReal(parameterName, value) 12 | obj = Parameter(self.parentsDict._copy(),cat_constructor) 13 | self.deque.append(obj) 14 | return obj 15 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/parameter.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class Parameter(object): 5 | def __init__(self, parent, cat_constructor): 6 | self.parent = parent[parent[-1]] 7 | self.parentsDict = parent 8 | self.cat_constructor = cat_constructor 9 | 10 | @property 11 | def name(self): 12 | name = self.cat_constructor.Name 13 | name_s = re.findall(".*\\\(.*)", name)[0] 14 | return name_s 15 | 16 | @name.setter 17 | def name(self, value): 18 | self.cat_constructor.Name = value 19 | 20 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewLinePtPt.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.line import LinePtPt 3 | 4 | 5 | def AddNewLinePtPt(self, geometrical_set, start, end): 6 | part = geometrical_set.parentsDict['Part'] 7 | reference1 = part._createReferenceFromObject(start) 8 | reference2 = part._createReferenceFromObject(end) 9 | cat_constructor = self.cat_constructor.AddNewLinePtPt(reference1, reference2) 10 | geometrical_set.cat_constructor.AppendHybridShape(cat_constructor) 11 | line = LinePtPt(geometrical_set.parentsDict, cat_constructor, start, end) 12 | 13 | return line -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewSpline.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.spline import Spline 3 | 4 | 5 | def AddNewSpline(self, geom, objs): 6 | cat_constructor = self.cat_constructor.AddNewSpline() 7 | cat_constructor.SetSplineType(0) 8 | cat_constructor.SetClosing(0) 9 | part = geom.parentsDict['Part'] 10 | for i in objs: 11 | cat_constructor.AddPointWithConstraintExplicit(part._createReferenceFromObject(i), None, -1.00000, 1.00000, None, 0.0000) 12 | geom.cat_constructor.AppendHybridShape(cat_constructor) 13 | spline = Spline(geom.parentsDict, cat_constructor, objs) 14 | return spline 15 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometricElement.py: -------------------------------------------------------------------------------- 1 | 2 | from Rice.baseClasses.anyObject import AnyObject 3 | 4 | 5 | class GeometricElement(AnyObject): 6 | 7 | def __init__(self, parent): 8 | """ 9 | 10 | :param parent: 11 | :param cat_constructor: 12 | """ 13 | self.isPainted = False 14 | self.parent = parent[parent[-1]] 15 | self.parentsDict = parent 16 | self.parentsDict['Part'].update() 17 | 18 | 19 | @property 20 | def name(self): 21 | return self.cat_constructor.Name 22 | 23 | @name.setter 24 | def name(self, value): 25 | self.cat_constructor.Name = value -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/controlPoint2D.py: -------------------------------------------------------------------------------- 1 | 2 | from ..geometry2D import Geometry2D 3 | 4 | 5 | class ControlPoint2D(Geometry2D): 6 | def __init__(self, parent, factory2d, point): 7 | super().__init__(parent) 8 | self.parent = parent[parent[-1]] 9 | self.parentsDict = parent 10 | self.factory2d = factory2d 11 | self.point = point 12 | 13 | def paint(self): 14 | self.cat_constructor = self.factory2d.cat_constructor.CreateControlPoint(self.point[0], self.point[1]) 15 | self.parentsDict[self.name] = self 16 | self.parent._children[self.name] = self 17 | del self.point 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/point2D.py: -------------------------------------------------------------------------------- 1 | 2 | from ..geometry2D import Geometry2D 3 | 4 | 5 | class Point2D(Geometry2D): 6 | def __init__(self,parent, factory2d, x, y): 7 | super().__init__(parent) 8 | self.parent = parent[parent[-1]] 9 | self.parentsDict = parent 10 | self.factory2d = factory2d 11 | self.values = [x, y] 12 | 13 | def paint(self): 14 | self.cat_constructor = self.factory2d.cat_constructor.CreatePoint(self.values[0], self.values[1]) 15 | self.parent._children[self.name] = self 16 | self.parentsDict[self.name] = self 17 | 18 | def __getitem__(self, item): 19 | return self.values[item] -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShape.py: -------------------------------------------------------------------------------- 1 | 2 | class HybridShape(object): 3 | """ 4 | Python class to manage Catia's Hybrid Shape Abstract Object 5 | """ 6 | def __init__(self, parent, cat_constructor): 7 | """ 8 | 9 | :param parent: 10 | :param cat_constructor: 11 | """ 12 | self.parent = parent[parent[-1]] 13 | self.parentsDict = parent 14 | self.cat_constructor = cat_constructor 15 | self.parentsDict['Part'].update() 16 | 17 | @property 18 | def name(self): 19 | return self.cat_constructor.Name 20 | 21 | @name.setter 22 | def name(self, value): 23 | self.cat_constructor.Name = value -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewPointCoord.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.point import PointCoord 3 | 4 | 5 | def AddNewPointCoord(self, geometric_set, coords=None,reference=None): 6 | if coords: 7 | cat_constructor = self.cat_constructor.AddNewPointCoord(coords[0],coords[1],coords[2]) 8 | else: 9 | cat_constructor = self.cat_constructor.AddNewPointCoord(0.0,0.0,0.0) 10 | if reference: 11 | cat_constructor.PtRef = reference 12 | else: 13 | pass 14 | geometric_set.cat_constructor.AppendHybridShape(cat_constructor) 15 | point = PointCoord(geometric_set.parentsDict, cat_constructor, coords, reference) 16 | return point -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewFill.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.fill import Fill 3 | 4 | 5 | def AddNewFill(self, geometrical_set, objs): 6 | 7 | cat_constructor = self.cat_constructor.AddNewFill() 8 | for i in objs: 9 | 10 | try:reference = geometrical_set.parentsDict['Part']._createReferenceFromObject(i._ref_object()) 11 | except:reference = geometrical_set.parentsDict['Part']._createReferenceFromObject(i) 12 | cat_constructor.AddBound(reference) 13 | cat_constructor.Continuity = 0 14 | geometrical_set.cat_constructor.AppendHybridShape(cat_constructor) 15 | fill = Fill(geometrical_set.parentsDict, cat_constructor, objs) 16 | return fill -------------------------------------------------------------------------------- /src/Rice/factoryTypes/factory2D.py: -------------------------------------------------------------------------------- 1 | 2 | from types import MethodType 3 | 4 | 5 | class Factory2D(object): 6 | 7 | def __init__(self, parent): 8 | self.parent = parent[parent[-1]] 9 | self.parentsDict = parent 10 | self.cat_constructor = self.parent.cat_constructor.Factory2D 11 | self.imported = dict() 12 | 13 | def __getattr__(self, item): 14 | item0 = '{}{}'.format(item[0].lower(), item[1:]) 15 | meth = __import__('factoryTypes.2DfactoryMeth.{}'.format(item0), globals(), locals(), [item], level=2) 16 | meth = meth.__dict__[item] 17 | 18 | self.__setattr__(item, MethodType(meth, self)) 19 | 20 | return object.__getattribute__(self, item) 21 | 22 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewPlaneOffset.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.plane import PlaneOffset 3 | 4 | 5 | def AddNewPlaneOffset(self, geometrical_set, reference, offset, reverse_direction=False): 6 | reference_1 = self.parentsDict['Part']._createReferenceFromObject(reference) 7 | cat_constructor = self.cat_constructor.AddNewPlaneOffset(reference_1, offset, reverse_direction) 8 | geometrical_set.cat_constructor.AppendHybridShape(cat_constructor) 9 | cat_constructor = geometrical_set.cat_constructor.HybridShapes.Item(cat_constructor.Name) 10 | geometrical_set.parentsDict['Part'].update() 11 | plane = PlaneOffset(self.parentsDict, cat_constructor, reference) 12 | return plane 13 | 14 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactory.py: -------------------------------------------------------------------------------- 1 | 2 | from types import MethodType 3 | 4 | 5 | class HybridShapeFactory(object): 6 | def __init__(self, parent): 7 | self.parent = parent[parent[-1]] 8 | self.parentsDict = parent 9 | self.cat_constructor = self.parentsDict['Part'].cat_constructor.HybridShapeFactory 10 | self.imported = {} 11 | 12 | def __getattr__(self, item): 13 | item0 = '{}{}'.format(item[0].lower(), item[1:]) 14 | meth = __import__('factoryTypes.hybridShapeFactoryMeth.{}'.format(item0), globals(), locals(),[item], level=2) 15 | meth = meth.__dict__[item] 16 | 17 | self.__setattr__(item, MethodType(meth, self)) 18 | 19 | return object.__getattribute__(self, item) -------------------------------------------------------------------------------- /src/Rice/generalObjects/orderedGeometricalSet.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class OrderedGeometricalSet(object): 4 | def __init__(self, parent, *args): 5 | self.parent = parent[parent[-1]] 6 | self.parentsDict = parent 7 | self.cat_constructor = self.parent.cat_constructor.Add() 8 | self.parentsDict[self.name] = self 9 | 10 | @property 11 | def name(self): 12 | """ 13 | Get Catia element name 14 | :return: string 15 | """ 16 | return self.cat_constructor.Name 17 | 18 | @name.setter 19 | def name(self, value): 20 | """ 21 | Set Catia element name 22 | :param value: string 23 | :return: None 24 | """ 25 | self.cat_constructor.Name = value -------------------------------------------------------------------------------- /src/Rice/collectionsObject/relations.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.relation import Relation 4 | import inspect 5 | 6 | 7 | class Relations(Collection): 8 | def __init__(self, parent): 9 | super(Relations, self).__init__(parent, 'Relations') 10 | 11 | def create_formula(self, name, output, formula, comment): 12 | if "" in [str(i) for i in inspect.getmro(type(formula))]: 13 | formula = formula.name 14 | 15 | cat_constructor = self.cat_constructor.CreateFormula(name, comment, output, formula) 16 | obj = Relation(self.parentsDict._copy(), cat_constructor) 17 | self.deque.append(obj) 18 | return obj 19 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/shapeFactory.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | 4 | from types import MethodType 5 | 6 | 7 | class ShapeFactory(object): 8 | def __init__(self, parent): 9 | self.parent = parent[parent[-1]] 10 | self.parentsDict = parent 11 | self.cat_constructor = self.parentsDict['Part'].cat_constructor.ShapeFactory 12 | self.imported = {} 13 | 14 | def __getattr__(self, item): 15 | item0 = '{}{}'.format(item[0].lower(), item[1:]) 16 | meth = __import__('factoryTypes.shapeFactoryMeth.{}'.format(item0), globals(), locals(), [item], level=2) 17 | meth = meth.__dict__[item] 18 | 19 | self.__setattr__(item, MethodType(meth, self)) 20 | 21 | return object.__getattribute__(self,item) 22 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/shapes/circPattern.py: -------------------------------------------------------------------------------- 1 | 2 | from ..shape import Shape 3 | 4 | 5 | class CircPattern(Shape): 6 | """ 7 | Python class to manage Catia's Hybrid Shape Abstract Object. Result of circular patter operation 8 | """ 9 | def __init__(self, parent, cat_constructor, obj, rotation_axis, instances, deltaTheta): 10 | """ 11 | 12 | :param parent: 13 | :param cat_constructor: 14 | :param obj: 15 | :param rotation_axis: 16 | :param instances: 17 | :param deltaTheta: 18 | """ 19 | super(CircPattern, self).__init__(parent, cat_constructor) 20 | self.obj = obj 21 | self. rotationa_axis = rotation_axis 22 | self.instances = instances 23 | self.deltaTheta = deltaTheta -------------------------------------------------------------------------------- /src/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | setup( 4 | name='rice', 5 | version='0.1', 6 | packages=['Rice', 'Rice.baseClasses', 'Rice.factoryTypes', 'Rice.factoryTypes.2DfactoryMeth', 7 | 'Rice.factoryTypes.shapeFactoryMeth', 'Rice.factoryTypes.hybridShapeFactoryMeth', 'Rice.miscellaneous', 8 | 'Rice.generalObjects', 'Rice.abstractObjects', 'Rice.abstractObjects.shapes', 9 | 'Rice.abstractObjects.documents', 'Rice.abstractObjects.hybridShapes', 10 | 'Rice.abstractObjects.geometric2Delements', 'Rice.collectionsObject'], 11 | url='https://github.com/robertpardillo/rice', 12 | license='MIT', 13 | author='Roberto', 14 | author_email='', 15 | description='Automating CAD models generation with CATIA' 16 | ) 17 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometry2D.py: -------------------------------------------------------------------------------- 1 | 2 | from .geometricElement import GeometricElement 3 | 4 | 5 | class Geometry2D(GeometricElement): 6 | def contruction(self, value): 7 | """ 8 | Set if the object is a construction element 9 | :param value: 10 | :return: bool 11 | """ 12 | self.cat_constructor.Construction = value 13 | 14 | def __getattribute__(self, item): 15 | if object.__getattribute__(self, 'isPainted') and item == 'paint': 16 | return object.__getattribute__(self, '_out') 17 | elif item == 'paint' and not object.__getattribute__(self, 'isPainted'): 18 | self.isPainted = True 19 | return object.__getattribute__(self, item) 20 | 21 | def _out(self): 22 | print('Already printed') -------------------------------------------------------------------------------- /src/Rice/generalObjects/constraint.py: -------------------------------------------------------------------------------- 1 | 2 | class Constraint(object): 3 | def __init__(self, parent, cat_constructor,*args): 4 | self.parentsDict = parent 5 | self.parent=parent[parent[-1]] 6 | self.cat_constructor = cat_constructor 7 | self.references = [i for i in args] 8 | 9 | @property 10 | def name(self): 11 | return self.cat_constructor.Name 12 | 13 | @name.setter 14 | def name(self, value): 15 | self.cat_constructor.Name.Value = value 16 | 17 | @property 18 | def dimension(self): 19 | return self.cat_constructor.Dimension 20 | 21 | @dimension.setter 22 | def dimension(self, value): 23 | self.cat_constructor.Dimension.Value = value 24 | 25 | def remove(self): 26 | self.parent.remove(self) -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/plane.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Plane(HybridShape): 6 | pass 7 | 8 | 9 | class PlaneOffset(Plane): 10 | def __init__(self, parentsDict, cat_constructor, reference): 11 | """ 12 | 13 | :param parentsDict: Parents 14 | :type parentsDict: :class:`~Rice.miscellaneous.orderDict.OrderDict` 15 | :param cat_constructor: COM Object 16 | :type cat_constructor: COM Object 17 | :param reference: reference plane 18 | :type reference: :class:`~Rice.abstractObjects.hybridShapes.plane.Plane` 19 | """ 20 | super(PlaneOffset, self).__init__(parentsDict, cat_constructor) 21 | self.reference = reference 22 | 23 | def offset(self): 24 | return self.cat_constructor.Offset -------------------------------------------------------------------------------- /src/Rice/collectionsObject/sketches.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.sketch import Sketch 4 | 5 | 6 | class Sketches(Collection): 7 | def __init__(self, parent): 8 | super(Sketches, self).__init__(parent, 'Sketches') 9 | 10 | def add(self, *args): 11 | obj = Sketch(self.parentsDict._copy(), *args) 12 | self.deque.append(obj) 13 | return obj 14 | 15 | def item(self, index_name): 16 | if isinstance(index_name, int): 17 | return self.deque[index_name] 18 | elif isinstance(index_name, str): 19 | for i in self.deque: 20 | if i.Name == index_name: 21 | return i 22 | 23 | def get_boundary(self, name): 24 | #TODO 25 | pass 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewCombine.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | from ...abstractObjects.hybridShapes.plane import Plane 4 | from ...abstractObjects.hybridShapes.combine import Combine 5 | 6 | 7 | def AddNewCombine(self, geometric_set, reference1, reference2, option): 8 | part = geometric_set.parentsDict['Part'].cat_constructor 9 | reference1 = part.CreateReferenceFromObject(reference1) 10 | reference2 = part.CreateReferenceFromObject(reference2) 11 | cat_constructor = self.cat_constructor.AddNewCombine(reference1, reference2, option) 12 | geometric_set.cat_constructor.AppendHybridShape(cat_constructor) 13 | plane = Plane(geometric_set.parentsDict, cat_constructor) 14 | comb = Combine(geometric_set.parentsDict, cat_constructor, reference1, reference2, option, plane) 15 | return comb -------------------------------------------------------------------------------- /src/Rice/abstractObjects/hybridShapes/combine.py: -------------------------------------------------------------------------------- 1 | 2 | from ..hybridShape import HybridShape 3 | 4 | 5 | class Combine(HybridShape): 6 | """ 7 | Result of combine operation 8 | """ 9 | def __init__(self, parent, cat_constructor, reference1, reference2, option, plane): 10 | """ 11 | 12 | :param parent: object's parents 13 | :type: :class:`~Rice.miscellaneous.orderDict.OderDict` 14 | :param cat_constructor: COM Object 15 | :type: COM Object 16 | :param reference1: 17 | :param reference2: 18 | :param option: 19 | :param plane: 20 | """ 21 | super(HybridShape, self).__init__(parent, cat_constructor) 22 | self.reference1 = reference1 23 | self.reference2 = reference2 24 | self.option = option 25 | self.plane = plane -------------------------------------------------------------------------------- /src/Rice/baseClasses/anyObject.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class AnyObject(object): 4 | """ 5 | def get_address(self): 6 | order_list = self.parentsDict.order_list 7 | address = list() 8 | for i in range(len(order_list))[::-1]: 9 | if isinstance(self.parentsDict[order_list[i]], Collection): 10 | continue 11 | elif isinstance(self.parentsDict[order_list[i]], Part): 12 | address.append(order_list[i]) 13 | break 14 | address.append(order_list[i]) 15 | string_address = "" 16 | for i in address[::-1]: 17 | string_address += "{}\\".format(i) 18 | 19 | return string_address[0:-1] 20 | """ 21 | @property 22 | def name(self): 23 | return self.cat_constructor.Name 24 | 25 | @name.setter 26 | def name(self, value): 27 | self.cat_constructor.Name = value 28 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/orderedGeometricalSets.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.orderedGeometricalSet import OrderedGeometricalSet 4 | 5 | 6 | class OrderedGeometricalSets(Collection): 7 | """ 8 | Ordered geometrical set object 9 | """ 10 | def __init__(self, parent, *args): 11 | """ 12 | 13 | :param parent: 14 | :rtype: :class:´~Rice.miscellaneous.orderDict.OrderDict´ 15 | :param args: 16 | """ 17 | super(OrderedGeometricalSets, self).__init__(parent, 'OrderedGeometricalSets') 18 | 19 | def add(self): 20 | obj = OrderedGeometricalSet(self.parentsDict._copy()) 21 | super(OrderedGeometricalSets, self).add(obj) 22 | return obj 23 | 24 | @property 25 | def name(self): 26 | return self.cat_constructor.Name 27 | 28 | @name.setter 29 | def name(self, value): 30 | self.cat_constructor.Name = value -------------------------------------------------------------------------------- /src/Rice/factoryTypes/shapeFactoryMeth/addNewSurfacicCircPattern.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.shapes.circPattern import CircPattern 3 | 4 | 5 | def AddNewSurfacicCircPattern(self, parent, rotation_axis, instances, deltaTheta, obj): 6 | part = self.parentsDict['Part'].cat_constructor 7 | reference1 = part.CreateReferenceFromName("") 8 | reference2 = part.CreateReferenceFromName("") 9 | 10 | cat_constructor = self.cat_constructor.AddNewSurfacicCircPattern(obj.cat_constructor, 1,2,20.00, 45.00,1,1,reference1,reference2,True,0.0000, True,False) 11 | 12 | cat_constructor.AngularRepartition.AngularSpacing.Value = deltaTheta 13 | cat_constructor.AngularRepartition.InstancesCount.Value = instances 14 | 15 | reference=part.CreateReferenceFromObject(rotation_axis.cat_constructor) 16 | cat_constructor.SetRotationAxis(reference) 17 | 18 | circPattern = CircPattern(parent, cat_constructor, obj, rotation_axis, instances, deltaTheta) 19 | return circPattern 20 | 21 | -------------------------------------------------------------------------------- /src/Rice/factoryTypes/hybridShapeFactoryMeth/addNewJoin.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.hybridShapes.join import Join 3 | 4 | 5 | def AddNewJoin(self, geometrical_set, objs): 6 | part = geometrical_set.parentsDict['Part'] 7 | references = list() 8 | for i in objs: 9 | references.append(part._createReferenceFromObject(i)) 10 | cat_constructor = self.cat_constructor.AddNewJoin(references[0], references[1]) 11 | for i in range(2, len(references)): 12 | cat_constructor.AddElement(references[i]) 13 | 14 | cat_constructor.SetConnex(1) 15 | cat_constructor.SetManifold(0) 16 | cat_constructor.SetSimplify(0) 17 | cat_constructor.SetSuppressMode(0) 18 | cat_constructor.SetDeviation(0.001000) 19 | cat_constructor.SetAngularTolerance(0) 20 | cat_constructor.SetFederationPropagation(0) 21 | geometrical_set.cat_constructor.AppendHybridShape(cat_constructor) 22 | 23 | join = Join(geometrical_set.parentsDict, cat_constructor, objs) 24 | 25 | return join -------------------------------------------------------------------------------- /src/Rice/collectionsObject/bodies.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.body import Body 4 | 5 | 6 | class Bodies(Collection): 7 | def __init__(self, parent): 8 | super(Bodies, self).__init__(parent, 'Bodies') 9 | 10 | def add(self, *args): 11 | """ 12 | 13 | Initialize and instance an object of the class imported, then adds it to the deque. 14 | 15 | :param args: 16 | :return: 17 | """ 18 | if len(args)>0: 19 | obj = Body(self.parentsDict._copy(), 'PartBody') 20 | else: 21 | obj = Body(self.parentsDict._copy()) 22 | self.deque.append(obj) 23 | return obj 24 | 25 | def item(self, index_name): 26 | if isinstance(index_name, int): 27 | return self.deque[index_name] 28 | elif isinstance(index_name, str): 29 | for i in self.deque: 30 | if i.Name == index_name: 31 | return i 32 | 33 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/document.py: -------------------------------------------------------------------------------- 1 | 2 | import inspect 3 | import re 4 | from ..baseClasses.anyObject import AnyObject 5 | 6 | 7 | class Document(AnyObject): 8 | def __init__(self, parent=None, document_type=None): 9 | """ 10 | 11 | :param parent: Application Object 12 | :param document_type: Part 13 | 14 | """ 15 | self.parent = parent[parent[-1]] 16 | self.parentsDict = parent 17 | self.cat_constructor = self.parent.cat_constructor.Add(document_type) 18 | self.parentsDict[self.name] = self 19 | cls = __import__('abstractObjects.documents.{}'.format(document_type.lower()), globals(), locals(), [document_type], level=2) 20 | cls = cls.__dict__[document_type] 21 | 22 | self.__setattr__(document_type, cls(self.parentsDict._copy())) 23 | 24 | def export_data(self, file_path, extension): 25 | self.cat_constructor.ExportData(file_path, extension) 26 | 27 | def save(self, file_path): 28 | self.cat_constructor.SaveAs(file_path) 29 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/spline2D.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | from ...abstractObjects.geometry2D import Geometry2D 4 | 5 | 6 | class Spline2D(Geometry2D): 7 | def __init__(self, parent, factory2d, points): 8 | super().__init__(parent) 9 | self.parent = parent[parent[-1]] 10 | self.parentsDict = parent 11 | self.factory2d = factory2d 12 | self.points = points 13 | 14 | def _ref_object(self): 15 | return self.parentsDict[self.parentsDict[-2]] 16 | 17 | def paint(self): 18 | list_of_control = list() 19 | self.control_points=list() 20 | for i in self.points: 21 | control_point = self.factory2d.AddControlPoint(i) 22 | self.control_points.append(control_point) 23 | list_of_control.append(control_point.cat_constructor) 24 | self.cat_constructor = self.factory2d.cat_constructor.CreateSpline(list_of_control) 25 | self.parentsDict[self.name] = self 26 | self.parent._children[self.name] = self 27 | 28 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/originElements.py: -------------------------------------------------------------------------------- 1 | 2 | from ..abstractObjects.hybridShapes.plane import Plane 3 | 4 | 5 | class OriginElements(object): 6 | def __init__(self, parent): 7 | self.parent = parent[parent[-1]] 8 | self.parentsDict = parent 9 | self.cat_constructor = self.parent.cat_constructor.OriginElements 10 | self.parentsDict['OriginElements'] = self 11 | self.originsPlanes = dict() 12 | 13 | self.originsPlanes['xy'] = Plane(self.parentsDict, self.cat_constructor.PlaneXY) 14 | self.originsPlanes['yz'] = Plane(self.parentsDict, self.cat_constructor.PlaneYZ) 15 | self.originsPlanes['zx'] = Plane(self.parentsDict, self.cat_constructor.PlaneZX) 16 | 17 | def get(self, plane): 18 | if plane.lower() in ['xy', 'yx']: 19 | plane = 'xy' 20 | elif plane.lower() in ['yz', 'zy']: 21 | plane = 'yz' 22 | elif plane.lower() in ['zx', 'xz']: 23 | plane = 'zx' 24 | return self.originsPlanes[plane] 25 | 26 | @property 27 | def name(self): 28 | return self.cat_constructor.Name 29 | 30 | @name.setter 31 | def name(self, value): 32 | self.cat_constructor.Name = value 33 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/settings.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | 4 | 5 | class Settings(Collection): 6 | def __init__(self, parent, *args): 7 | self.parent = parent[parent[-1]] 8 | self.parentsDict = parent 9 | self.cat_constructor = self.parent.cat_constructor 10 | self.parentsDict[self.name] = self 11 | self.setting_dict = dict() 12 | 13 | @property 14 | def name(self): 15 | return self.cat_constructor.Name 16 | 17 | @name.setter 18 | def name(self, value): 19 | self.cat_constructor.Name = value 20 | 21 | def change(self, path, name, *args): 22 | ## Example path: Infrastructure.PartInfrastructure.PartDocument 23 | path = path.split('.') 24 | cls = __import__('collectionsObject.settingF.{}.{}'.format(path[0], path[1]), [path]) 25 | func = cls.__dict__['settingF'].__dict__[path[0]].__dict__[path[1]].__dict__[path[2]] 26 | func(self.parent, name, args) 27 | self.setting_dict[name] = [path, args] 28 | 29 | def __getitem__(self, item): 30 | return self.setting_dict[item] 31 | 32 | def __setitem__(self, key, value): 33 | self.setting_dict[key][1] = value 34 | self.change(self.setting_dict[key][0],key,value) 35 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/documents.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import re 3 | from ..baseClasses.collection import Collection 4 | from ..abstractObjects.document import Document 5 | 6 | 7 | class Documents(Collection): 8 | """ 9 | Application 10 | Documents 11 | Document ----> Part, Product, Drawing 12 | 13 | Document class 14 | """ 15 | def __init__(self, parents_dict): 16 | super(Documents, self).__init__(parents_dict, 'Documents') 17 | self.imported = list() 18 | 19 | def add(self, docType): 20 | """ 21 | 22 | Initialize and instance an object of the class imported, then adds it to the deque. 23 | 24 | :param args: 25 | :return: 26 | """ 27 | 28 | obj = Document(self.parentsDict._copy(), docType) 29 | self.deque.append(obj) 30 | return obj 31 | 32 | def item(self, index_name): 33 | if isinstance(index_name, int): 34 | return self.deque[index_name] 35 | elif isinstance(index_name, str): 36 | for i in self.deque: 37 | if i.Name == index_name: 38 | return i 39 | 40 | def new_from(self, file_path): 41 | pass 42 | 43 | def open(self, file_path): 44 | pass 45 | 46 | def read(self, file_path): 47 | pass 48 | 49 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/shape.py: -------------------------------------------------------------------------------- 1 | 2 | class Shape(object): 3 | """ 4 | 5 | Python class to manage Catia's Shape Abstract Object 6 | 7 | """ 8 | def __init__(self, parent, cat_constructor): 9 | self.parent = parent[parent[-1]] 10 | self.parentsDict = parent 11 | self.cat_constructor = cat_constructor 12 | self.model_string = "Selection_RSur:(Face:(Brp:({};{};None:();Cf11:());{}_ResultOUT;Z0;G4074)" 13 | self.parentsDict['Part'].update() 14 | 15 | def _create_reference(self, item): 16 | if item == 'up': 17 | reference = self.model_string.format(self.name, "{})".format(2), self.name) 18 | elif item == 'down': 19 | reference = self.model_string.format(self.name, "{})".format(1), self.name) 20 | elif type(item) == int: 21 | number = self.sketch._children.order('Line.{}'.format(item)) 22 | string2 = "0:(Brp:({};{})))".format(self.sketch.name, number) 23 | reference = self.model_string.format(self.name, string2, self.name) 24 | reference = self.parentsDict['Part']._create_reference_from_name(reference) 25 | return reference 26 | 27 | @property 28 | def name(self): 29 | return self.cat_constructor.Name 30 | 31 | @name.setter 32 | def name(self, value): 33 | self.cat_constructor.Name = value 34 | 35 | def __getitem__(self, item): 36 | ref = self._create_reference(item) 37 | return ref -------------------------------------------------------------------------------- /src/Rice/collectionsObject/hybridBodies.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | from ..baseClasses.collection import Collection 4 | from ..generalObjects.hybridBody import HybridBody 5 | 6 | 7 | class HybridBodies(Collection): 8 | """ 9 | Possible Origins: 10 | 11 | Application Application Application 12 | Documents Documents Documents 13 | Part Part Part 14 | Bodies HybridBodies HybridBodies 15 | Body HybridBody HybridBody 16 | HybridBodies HybridBodies 17 | HybridBody HybridBody 18 | 19 | 20 | 21 | """ 22 | #TODO 23 | def __init__(self, parent, *args): 24 | super(HybridBodies,self).__init__(parent, 'HybridBodies') 25 | 26 | def add(self): 27 | obj = HybridBody(self.parentsDict._copy()) 28 | super(HybridBodies, self).add(obj) 29 | return obj 30 | 31 | def item(self, index_name): 32 | if isinstance(index_name, int): 33 | return self.deque[index_name] 34 | elif isinstance(index_name, str): 35 | for i in self.deque: 36 | if i.Name == index_name: 37 | return i 38 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/line2D.py: -------------------------------------------------------------------------------- 1 | 2 | from ...abstractObjects.geometric2Delements.point2D import Point2D 3 | from ...miscellaneous.stdOutput import output 4 | from ..geometry2D import Geometry2D 5 | 6 | 7 | class Line2D(Geometry2D): 8 | def __init__(self,parent, factory2d, start, end): 9 | super(Line2D, self).__init__(parent) 10 | self.parent = parent[parent[-1]] 11 | self.parentsDict = parent 12 | self.factory2d = factory2d 13 | self.start = start 14 | self.end = end 15 | 16 | def paint(self): 17 | x1 = self.start[0] 18 | y1 = self.start[1] 19 | 20 | x2 = self.end[0] 21 | y2 = self.end[1] 22 | 23 | if isinstance(self.start, Point2D): 24 | pass 25 | else: 26 | output('changing values of line from list to Point2D objects') 27 | 28 | self.start = self.factory2d.AddPoint(x1, y1) 29 | 30 | if isinstance(self.end, Point2D): 31 | pass 32 | else: 33 | output('changing values of line from list to Point2D objects') 34 | 35 | self.end = self.factory2d.AddPoint(x2, y2) 36 | 37 | self.cat_constructor = self.factory2d.cat_constructor.CreateLine(x1, y1, x2, y2) 38 | self.parentsDict[self.name] = self 39 | self.parent._children[self.name] = self 40 | 41 | def start_point(self): 42 | self.start.paint() 43 | self.cat_constructor.StartPoint = self.start.cat_constructor 44 | 45 | def end_point(self): 46 | self.end.paint() 47 | self.cat_constructor.EndPoint = self.end.cat_constructor 48 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/factory.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | 3 | 4 | class Factory(object): 5 | def __init__(self, parent): 6 | self.imported = {} 7 | self.parentsDict = parent 8 | 9 | def factory2d(self): 10 | if 'Factory2D' not in self.imported.keys(): 11 | cls = __import__('factoryTypes.factory2D', globals(), locals(), ['Factory2D'], level=2) 12 | cls = cls.__dict__['Factory2D'] 13 | self.imported['Factory2D'] = cls(self.parentsDict._copy()) 14 | 15 | obj = self.imported['Factory2D'] 16 | return obj 17 | 18 | def shape_factory(self): 19 | if 'ShapeFactory' not in self.imported.keys(): 20 | cls = __import__('factoryTypes.shapeFactory', globals(), locals(), ['ShapeFactory'], level = 2) 21 | cls = cls.__dict__['ShapeFactory'] 22 | self.imported['ShapeFactory'] = cls(self.parentsDict._copy()) 23 | 24 | obj = self.imported['ShapeFactory'] 25 | return obj 26 | 27 | def hybrid_shape_factory(self): 28 | """ 29 | Class to contain all hybrid shape operations. If hybrid shape factory has not been created, it is created and then returned. 30 | If hybrid shape factory has been created it is returned. 31 | 32 | :return: 33 | """ 34 | if 'HybridShapeFactory' not in self.imported.keys(): 35 | cls = __import__('factoryTypes.hybridShapeFactory', globals(), locals(), ['HybridShapeFactory'], level = 2) 36 | cls = cls.__dict__['HybridShapeFactory'] 37 | self.imported['HybridShapeFactory'] = cls(self.parentsDict._copy()) 38 | 39 | obj = self.imported['HybridShapeFactory'] 40 | 41 | return obj 42 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/geometric2Delements/circle2D.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | from .point2D import Point2D 4 | from ..geometry2D import Geometry2D 5 | 6 | 7 | class Circle2D(Geometry2D): 8 | def __init__(self, parent, factory2d, center, r, start, end): 9 | super().__init__(parent) 10 | self.parent = parent[parent[-1]] 11 | self.parentsDict = parent 12 | self.factory2d = factory2d 13 | self.values = [center, r, start, end] 14 | 15 | def paint(self): 16 | self.cat_constructor = self.factory2d.cat_constructor.CreateCircle(self.values[0][0],self.values[0][1],self.values[1], 17 | self.values[2],self.values[3]) 18 | 19 | self.parent._children[self.name] = self 20 | self.parentsDict[self.name] = self 21 | 22 | def center_point(self): 23 | if isinstance(self.values[0], Point2D): 24 | pass 25 | else: 26 | point = self.factory2d.AddPoint(self.values[0][0], self.values[0][1]) 27 | point.paint() 28 | self.values[0] = point 29 | self.cat_constructor.CenterPoint = self.values[0].cat_constructor 30 | 31 | def start_point(self): 32 | xs = self.values[0][0] + self.values[1]*np.cos(self.values[2]) 33 | ys = self.values[0][1] + self.values[1]*np.sin(self.values[2]) 34 | 35 | p_start = self.factory2d.AddPoint(xs, ys) 36 | p_start.paint() 37 | self.values[2] = p_start 38 | 39 | self.cat_constructor.StartPoint = p_start.cat_constructor 40 | 41 | def end_point(self): 42 | xe = self.values[0][0] + self.values[1]*np.cos(self.values[3]) 43 | ye = self.values[0][1] + self.values[1]*np.sin(self.values[3]) 44 | 45 | p_end = self.factory2d.AddPoint(xe, ye) 46 | p_end.paint() 47 | self.values[3] = p_end 48 | 49 | self.cat_constructor.EndPoint = p_end.cat_constructor 50 | 51 | def changePoint(self,point, newx,newy): 52 | if point=='start': 53 | point = self.factory2d.AddPoint(newx,newy) 54 | point.paint() 55 | self.values[2]= point 56 | self.cat_constructor.StartPoint = point 57 | 58 | elif point=='end': 59 | point = self.factory2d.AddPoint(newx,newy) 60 | point.paint() 61 | self.values[3]= point 62 | self.cat_constructor.EndPoint = point 63 | -------------------------------------------------------------------------------- /src/Rice/application.py: -------------------------------------------------------------------------------- 1 | 2 | from win32com.client import dynamic 3 | from .miscellaneous.orderDict import OrderDict 4 | import inspect 5 | import re 6 | from .collectionsObject.documents import Documents 7 | from .collectionsObject.windows import Windows 8 | from .abstractObjects.documents.part import Part 9 | 10 | 11 | class Application(object): 12 | """ 13 | 14 | Root class which is the origin of the rest. It contains all the objects and all the instantiated data. 15 | 16 | It initializes connection with CATIA. 17 | 18 | """ 19 | 20 | def __init__(self, visible=True): 21 | """ 22 | 23 | :param visible: Catia's window visible or not 24 | :type visible: bool 25 | """ 26 | self.parent = None 27 | self.cat_constructor = dynamic.Dispatch("CATIA.Application") 28 | self.cat_constructor.Visible = visible 29 | self.name = self.cat_constructor.Name 30 | self.parentsDict = OrderDict() 31 | self.parentsDict[self.name] = self 32 | self.documents_COLL = Documents(self.parentsDict._copy()) 33 | self.windows_COLL = Windows(self.parentsDict._copy()) 34 | caller = inspect.getouterframes(inspect.currentframe())[1][1] 35 | caller = re.findall('([a-z]*)\.py.*', caller)[0] 36 | if caller in ['part', 'product', 'drawing']: 37 | print('Not create Document') 38 | pass 39 | else: 40 | self.documents_COLL.add('Part') 41 | pass 42 | 43 | def add_part(self): 44 | """ 45 | Add a Part 46 | """ 47 | self.documents_COLL.add('Part') 48 | 49 | def get_parts(self): 50 | """ 51 | Get all created Parts 52 | 53 | :return: list of created Parts 54 | :rtype: list of :class:`~Rice.abstractObjects.documents.part.Part` 55 | """ 56 | result = list() 57 | for i in self.documents_COLL.deque: 58 | result.append(i.Part) 59 | return result 60 | 61 | def active_document(self): 62 | """ 63 | TO-DO 64 | """ 65 | return self.value 66 | 67 | def active_window(self): 68 | return self.value 69 | 70 | def documents(self): 71 | return self.value 72 | 73 | def windows(self): 74 | return self.value 75 | 76 | def visible(self): 77 | return self.value 78 | 79 | def quit(self): 80 | self.cat_obj.Quit() 81 | 82 | -------------------------------------------------------------------------------- /src/Rice/baseClasses/collection.py: -------------------------------------------------------------------------------- 1 | 2 | from collections import deque 3 | 4 | 5 | class Collection(object): 6 | """ 7 | 8 | Base Class of Collections object types. 9 | Manage the creations and handle its behaviour. 10 | 11 | Objects variables: 12 | - parent Object of upper class, the type of collection rules the type of parent 13 | - parentsDict OrderDict object, contains the parents of collections 14 | - collectionType Catia's collection name 15 | - deque Deque object, list of object instantiated by collection 16 | - cat_constructor Catia's working variables, python COMObject 17 | - cls Declaration of class, ruled by the type of the collection 18 | - name Property, name of the collection 19 | """ 20 | 21 | def __init__(self, parent, collectionType): 22 | """ 23 | 24 | Import the collection type referenced by import_path and saves its class declaration. 25 | 26 | :param parent: orderDict object, Contains the parents of the object. See also OrderDict doc. 27 | :param collectionType: Catia's collection name 28 | :return: 29 | """ 30 | self.parent = parent[parent[-1]] 31 | self.parentsDict = parent 32 | self.collectionType = collectionType 33 | self.deque = deque() 34 | self.cat_constructor = eval('self.parent.cat_constructor.{}'.format(self.collectionType)) 35 | 36 | self.parentsDict[self.name] = self 37 | 38 | @property 39 | def name(self): 40 | return self.cat_constructor.Name 41 | 42 | @name.setter 43 | def name(self, value): 44 | self.cat_constructor.Name = value 45 | 46 | @property 47 | def application(self): 48 | return self.cat_constructor.Application 49 | 50 | @property 51 | def Count(self): 52 | return self.cat_constructor.Count 53 | 54 | @property 55 | def Parent(self): 56 | return self.cat_constructor.Parent 57 | 58 | def GetItem(self, name): 59 | return self.cat_constructor.GetItem(name) 60 | 61 | def item(self,index_name): 62 | obj = self.cat_constructor.Item(index_name) 63 | return obj 64 | 65 | def new_from(self, file_path): 66 | #TODO 67 | pass 68 | 69 | def open(self, file_path): 70 | #TODO 71 | pass 72 | 73 | def read(self, file_path): 74 | #TODO 75 | pass 76 | 77 | def add(self, obj): 78 | self.deque.append(obj) 79 | -------------------------------------------------------------------------------- /src/Rice/miscellaneous/orderDict.py: -------------------------------------------------------------------------------- 1 | __author__ = 'roberto' 2 | import inspect 3 | import re 4 | 5 | 6 | class OrderDict(object): 7 | """ 8 | Handle the parents of the object. 9 | The objects and its values are contained into dic[key] = value and the order of adding is contained into 10 | order_list. 11 | Example: 12 | obj = OrderDict() 13 | obj['key1']=1 # dic = {'key1':1} ; order_list=['key1'] 14 | obj['key2']=2 # dic = {'key1':1,'key2':2} ; order_list=['key1','key2'] 15 | obj['key3']=3 # dic = {'key1':1,'key2':2,'key3':3} ; order_list=['key1','key2','key3'] 16 | 17 | """ 18 | def __init__(self): 19 | self.dic = {} 20 | self.order_list = [] 21 | 22 | def __setitem__(self, key, value): 23 | """ 24 | Add key:value to the dict and append the key to order_list to register its order 25 | Example: 26 | obj['key4']=4 # dic = {'key1':1,'key2':2,'key3':3,'key4':4} ; order_list=['key1','key2','key3','key4'] 27 | :param key: string 28 | :param value: any object 29 | :return: 30 | """ 31 | self.dic[key] = value 32 | self.order_list.append(key) 33 | 34 | def __getitem__(self, item): 35 | """ 36 | If item is a string return dic[item] 37 | If item is a integer return order_list[item] 38 | Example: 39 | 40 | :param item: str or int 41 | :return: 42 | """ 43 | if type(item)==str: 44 | try:obj = self.dic[item] 45 | except: 46 | for i in self.dic.keys(): 47 | result = re.findall('{}[0-9]+'.format(item),i) 48 | if len(result)>0: 49 | obj = self.dic[result[0]] 50 | break 51 | elif type(item)==int: 52 | obj = self.order_list[item] 53 | 54 | return obj 55 | 56 | def order(self, item): 57 | """ 58 | Return the place in the order of item 59 | Example: 60 | 61 | :param item: string 62 | :return:integer 63 | """ 64 | index = self.order_list.index(item)+1 65 | return index 66 | 67 | def _copy(self): 68 | """ 69 | Copy dir and order_list and create a new instance of OrderDict with that dir and order_list 70 | Example: 71 | 72 | :return:OrderDict object 73 | """ 74 | obj = OrderDict() 75 | obj.dic = self.dic.copy() 76 | obj.order_list = self.order_list.copy() 77 | 78 | return obj 79 | 80 | def _treeParent(self): 81 | """ 82 | Represents in a visual way the upper tree of the object 83 | Example: 84 | ... 85 | Part 86 | Sketch 87 | Line 88 | ... 89 | :return: string 90 | """ 91 | string='' 92 | for i in range(len(self.order_list)): 93 | string += ' '*i*2 + '{}\n'.format(self.order_list[i]) 94 | return string 95 | 96 | def __str__(self): 97 | return self._treeParent() 98 | 99 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/hybridBody.py: -------------------------------------------------------------------------------- 1 | from ..baseClasses.collection import Collection 2 | from ..generalObjects.factory import Factory 3 | 4 | 5 | class HybridBody(object): 6 | """ 7 | Possible Origins: 8 | 9 | Application Application Application 10 | Documents Documents Documents 11 | Part Part Part 12 | Bodies HybridBodies HybridBodies 13 | Body HybridBody HybridBody 14 | HybridBodies HybridBodies 15 | HybridBody HybridBody 16 | 17 | HybridBody object 18 | 19 | Object variables: 20 | 21 | 22 | """ 23 | #TODO 24 | def __init__(self, parent, *args): 25 | self.parent = parent[parent[-1]] 26 | self.parentsDict = parent 27 | self.cat_constructor = self.parent.cat_constructor.Add() 28 | self.parentsDict[self.name] = self 29 | self.factory = Factory(self.parentsDict) 30 | 31 | @property 32 | def name(self): 33 | """ 34 | Get Catia element name 35 | :return: string 36 | """ 37 | return self.cat_constructor.Name 38 | 39 | @name.setter 40 | def name(self, value): 41 | """ 42 | Set Catia element name 43 | :param value: string 44 | :return: None 45 | """ 46 | self.cat_constructor.Name = value 47 | 48 | def add_sketch(self, plane): 49 | """ 50 | Add sketch to geometrical set 51 | :param plane: 52 | :return: 53 | """ 54 | try: 55 | if plane.lower() in ['xy', 'yx', 'zx', 'xz', 'zy', 'yz']: 56 | plane = self.parent.parent.originElements.get(plane) 57 | except: 58 | pass 59 | try : 60 | self.__getattribute__('sketches_COLL') 61 | except AttributeError: 62 | self.sketches_COLL = Collection(self.parentsDict._copy(), 'collectionsObject.sketchesF.sketches.Sketch', 'HybridSketches') 63 | 64 | self.sketches_COLL.add(plane) 65 | 66 | return self.sketches_COLL.deque[-1] 67 | 68 | def plane(self, option, reference, *args): 69 | """ 70 | Add plane 71 | :param option: string, 72 | :param reference: 73 | :param args: 74 | :return: 75 | """ 76 | if reference.lower() in ['xy','yx','zx','xz','zy','yz']: 77 | reference = self.parent.parent.originElements.get(reference).cat_constructor 78 | hybridFactory = self.factory.hybrid_shape_factory() 79 | if option == 'Offset from plane': 80 | 81 | try: reverse = args[1] 82 | except:reverse = False 83 | plane = hybridFactory.AddNewPlaneOffset(self, reference, args[0], reverse) 84 | elif option == 'Angle/Normal to plane': 85 | pass 86 | else: 87 | pass 88 | return plane 89 | 90 | def combine(self, sketch1, sketch2, option=0): 91 | """ 92 | Combine operation 93 | :param sketch1: 94 | :param sketch2: 95 | :param option: 96 | :return: 97 | """ 98 | hybridFactory = self.factory.hybrid_shape_factory() 99 | comb = hybridFactory.AddNewCombine(self, sketch1, sketch2, option) 100 | return comb 101 | -------------------------------------------------------------------------------- /src/Rice/collectionsObject/constraints.py: -------------------------------------------------------------------------------- 1 | 2 | from ..baseClasses.collection import Collection 3 | from ..generalObjects.constraint import Constraint 4 | 5 | catConstraintTypeDict = { 6 | "catCstTypeReference":0, 7 | "catCstTypeDistance":1, 8 | "catCstTypeOn":2, 9 | "catCstTypeConcentricity":3, 10 | "catCstTypeTangency":4, 11 | "catCstTypeLength":5, 12 | "catCstTypeAngle":6, 13 | "catCstTypePlanarAngle":7, 14 | "catCstTypeParallelism":8, 15 | "catCstTypeAxisParallelism":9, 16 | "catCstTypeHorizontality":10, 17 | "catCstTypePerpendicularity":11, 18 | "catCstTypeAxisPerpendicularity":12, 19 | "catCstTypeVerticality":13, 20 | "catCstTypeRadius":14, 21 | "catCstTypeSymmetry":15, 22 | "catCstTypeMidPoint":16, 23 | "catCstTypeEquidistance":17, 24 | "catCstTypeMajorRadius":18, 25 | "catCstTypeMinorRadius":19, 26 | "catCstTypeSurfContact":20, 27 | "catCstTypeLinContact":21, 28 | "catCstTypePoncContact":22, 29 | "catCstTypeChamfer":23, 30 | "catCstTypeChamferPerpend":24, 31 | "catCstTypeAnnulContact":25, 32 | "catCstTypeCylinderRadius":26, 33 | "catCstTypeStContinuity":27, 34 | "catCstTypeStDistance":28, 35 | "catCstTypeSdContinuity":29, 36 | "catCstTypeSdShape":30 37 | 38 | } 39 | 40 | 41 | class Constraints(Collection): 42 | def __init__(self, parent, cat_constructor=None): 43 | """ 44 | 45 | Initialized the object and sketches_COLL to handle the sketches creation. 46 | Initialized to Factory object. 47 | 48 | :param parent: 49 | :param cat_constructor: 50 | :return: 51 | """ 52 | super(Constraints, self).__init__(parent, 'Constraints') 53 | 54 | def AddBiEltCst(self, CatConstraintType,reference0, reference1): 55 | constraintType = self._checkConstraint(CatConstraintType) 56 | reference0_ = self.parentsDict['Part']._createReferenceFromObject(reference0) 57 | reference1_ = self.parentsDict['Part']._createReferenceFromObject(reference1) 58 | cat_constructor = self.cat_constructor.AddBiEltCst(catConstraintTypeDict[constraintType], reference0_, reference1_) 59 | obj = Constraint(self.parentsDict._copy(), cat_constructor, reference0, reference1) 60 | self.deque.append(obj) 61 | return obj 62 | 63 | def AddMonoEltCst(self, CatConstraintType,reference0): 64 | constraintType = self._checkConstraint(CatConstraintType) 65 | reference0_ = self.parentsDict['Part']._createReferenceFromObject(reference0) 66 | cat_constructor = self.cat_constructor.AddMonoEltCst(catConstraintTypeDict[constraintType], reference0_) 67 | obj = Constraint(self.parentsDict._copy(), cat_constructor, reference0) 68 | self.deque.append(obj) 69 | return obj 70 | 71 | def AddTriEltCst(self, CatConstraintType, reference0, reference1, reference2): 72 | constraintType = self._checkConstraint(CatConstraintType) 73 | reference0_ = self.parentsDict['Part']._createReferenceFromObject(reference0) 74 | reference1_ = self.parentsDict['Part']._createReferenceFromObject(reference1) 75 | reference2_ = self.parentsDict['Part']._createReferenceFromObject(reference2) 76 | cat_constructor = self.cat_constructor.AddTriEltCst(catConstraintTypeDict[constraintType], reference0_, 77 | reference1_, reference2_) 78 | obj = Constraint(self.parentsDict._copy(), cat_constructor, reference0, reference1, reference2) 79 | self.deque.append(obj) 80 | return obj 81 | 82 | @staticmethod 83 | def _checkConstraint(CatConstraintType): 84 | if isinstance(CatConstraintType, int): 85 | CatConstraintType = [i for i in catConstraintTypeDict if catConstraintTypeDict[i] == CatConstraintType] 86 | else: 87 | pass 88 | 89 | return CatConstraintType[0] 90 | 91 | def remove(self, item): 92 | self.deque.remove(item) 93 | self.cat_constructor.Remove(item.name) 94 | -------------------------------------------------------------------------------- /src/Rice/generalObjects/body.py: -------------------------------------------------------------------------------- 1 | 2 | from .factory import Factory 3 | from ..collectionsObject.sketches import Sketches 4 | from ..collectionsObject.hybridBodies import HybridBodies 5 | 6 | 7 | def _in_work_object(func): 8 | def f(*args,**kwargs): 9 | self = args[0] 10 | self.parentsDict['Part'].cat_constructor.InWorkObject = self.cat_constructor 11 | obj = func(*args, **kwargs) 12 | return obj 13 | return f 14 | 15 | 16 | class Body(object): 17 | """ 18 | Possible Origins: 19 | 20 | Application Application 21 | Documents Documents 22 | Part Part 23 | Bodies HybridBodies 24 | Body HybridBody 25 | Bodies 26 | Body 27 | 28 | Handles and contains the Body object and Body methods 29 | This class objects are generated by collection class that contains all the instance of this class 30 | 31 | Object variables: 32 | - parent Bodies collection Object 33 | - parentsDict OrderDict object, contains object's parents 34 | - cat_constructor Catia's working variable, python COMObject 35 | - sketches_COLL Sketches collection object 36 | - factory Instance of generalObjects.factory.Factory, handles some types of Factories. 37 | See also Factory doc. 38 | - hybrid_bodies_COLL Object of HybridBodies Collection. See also Collection doc. Handle HybridBody objects. 39 | - name Property, catia's working name 40 | """ 41 | 42 | def __init__(self, parent, cat_constructor=None): 43 | """ 44 | 45 | Initialized the object and sketches_COLL to handle the sketches creation. 46 | Initialized to Factory object. 47 | 48 | :param parent: 49 | :param cat_constructor: 50 | """ 51 | self.parent = parent[parent[-1]] 52 | self.parentsDict = parent 53 | if not cat_constructor: 54 | self.cat_constructor = self.parent.cat_constructor.Add() 55 | else: 56 | self.cat_constructor = self.parent.cat_constructor.Item('PartBody') 57 | self.parentsDict[self.name] = self 58 | self.factory = Factory(self.parentsDict._copy()) 59 | 60 | self.sketches_COLL = Sketches(self.parentsDict._copy()) 61 | 62 | @property 63 | def name(self): 64 | """ 65 | Return Object's Catia name 66 | :return: Object's name 67 | :rtype: str 68 | """ 69 | return self.cat_constructor.Name 70 | 71 | @name.setter 72 | def name(self, value): 73 | self.cat_constructor.Name = value 74 | 75 | @_in_work_object 76 | def add_sketch(self, plane): 77 | """ 78 | Add sketch to "plane" 79 | Example: 80 | - sketch = body.add_sketch('XY') # type(plane) = str 81 | 82 | - sketch = body.add_sketch(pad[0]) # type(plane) = COMObject GetReferenceFromName 83 | 84 | :param plane: string or reference 85 | :return: Created sketch 86 | :rtype: :class:`~Rice.generalObjects.sketch.Sketch` 87 | """ 88 | try: 89 | if plane.lower() in ['xy','yx','zx','xz','zy','yz']: 90 | plane = self.parent.parent.originElements.get(plane) 91 | except: 92 | pass 93 | self.sketches_COLL.add(plane) 94 | 95 | return self.sketches_COLL.deque[-1] 96 | 97 | def geometrical_set(self): 98 | """ 99 | Insert a new Geometrical Set 100 | 101 | Example: 102 | - geometricalSet = body.geometrical_set() 103 | :return: Created Geometrical Set 104 | :rtype: :class:`~Rice.collectionsObject.hybridBodies.HybridBodies` 105 | """ 106 | try: 107 | return self.hybrid_bodies_COLL 108 | 109 | except AttributeError: 110 | self.hybrid_bodies_COLL = HybridBodies(self.parentsDict._copy()) 111 | self.hybrid_bodies_COLL.add() 112 | return self.hybrid_bodies_COLL.deque[-1] 113 | 114 | @_in_work_object 115 | def pad(self, sketch, limit): 116 | """ 117 | Pad operation. 118 | 119 | :param sketch: Sketch Object 120 | :param limit: double or int 121 | :return: Pad Object 122 | :rtype: :class:`~Rice.abstractObjects.shapes.pad.Pad` 123 | """ 124 | 125 | shapefactory = self.factory.shape_factory() 126 | 127 | pad = shapefactory.AddNewPad(self.parentsDict, sketch, limit) 128 | return pad 129 | 130 | @_in_work_object 131 | def pocket(self, sketch, limit): 132 | """ 133 | Pocket operation. 134 | 135 | :param sketch: Sketch Object 136 | :param limit: double or int 137 | :return: Pocket Object 138 | :rtype: :class:`~Rice.abstractObjects.shapes.pocket.Pocket` 139 | """ 140 | shapefactory = self.factory.shape_factory() 141 | pocket = shapefactory.AddNewPocket(self.parentsDict, sketch, limit) 142 | 143 | return pocket 144 | 145 | @_in_work_object 146 | def surf_circular_pattern(self, instances, total_angle, obj, rotation_axis): 147 | """ 148 | Only implemented for Instances and total angle option 149 | :param instances: instances to repeat 150 | :type instances: int 151 | :param total_angle: total angle to repeat, degrees 152 | :type total_angle: float 153 | :param obj: object to repeat 154 | :type obj: :class:`~Rice.abstractObjects.shape.Shape` 155 | :param rotation_axis: axis 156 | :type rotation_axis: :class:`~Rice.abstractObjects.hybridShapes.line.Line` 157 | :return: Circular pattern 158 | :rtype: :class:`~Rice.abstractObjects.shapes.circPattern.CircPattern` 159 | """ 160 | deltaTheta = total_angle/instances 161 | circPattern = self.factory.shape_factory().AddNewSurfacicCircPattern(self.parentsDict, rotation_axis, instances, deltaTheta, obj) 162 | return circPattern -------------------------------------------------------------------------------- /src/Rice/generalObjects/sketch.py: -------------------------------------------------------------------------------- 1 | from ..generalObjects.factory import Factory 2 | from ..abstractObjects.hybridShapes.plane import Plane 3 | from ..miscellaneous.tools import rad_degrees 4 | from ..miscellaneous.orderDict import OrderDict 5 | import numpy as np 6 | from collections import namedtuple 7 | from math import sqrt 8 | from ..collectionsObject.constraints import Constraints 9 | 10 | 11 | def Open_Close(func): 12 | def f(*args,**kwargs): 13 | self = args[0] 14 | self._open_edition() 15 | try: self.factory2d 16 | except: self.factory2D() 17 | obj = func(*args, **kwargs) 18 | self._close_edition() 19 | self.parentsDict['Part'].update() 20 | return obj 21 | return f 22 | 23 | 24 | class Sketch(object): 25 | def __init__(self, parent, *args): 26 | self.parent = parent[parent[-1]] 27 | self.parentsDict = parent 28 | if not isinstance(args[0], Plane): 29 | self.cat_constructor = self.parent.cat_constructor.Add(args[0]) 30 | else: 31 | self.cat_constructor = self.parent.cat_constructor.Add(args[0].cat_constructor) 32 | self.parentsDict[self.name] = self 33 | self._children = OrderDict() 34 | self.constraints_coll = Constraints(self.parentsDict._copy()) 35 | 36 | def factory2D(self): 37 | self.factory2d = Factory(self.parentsDict).factory2d() 38 | 39 | def _add_children(self, obj): 40 | pass 41 | 42 | def _close_edition(self): 43 | self.cat_constructor.CloseEdition() 44 | #self.parentsDict['Part'].update() 45 | 46 | def _open_edition(self): 47 | self.cat_constructor.OpenEdition() 48 | 49 | @Open_Close 50 | def set_constraint(self, cstType, *references): 51 | """ 52 | "catCstTypeReference":0, 53 | "catCstTypeDistance":1, 54 | "catCstTypeOn":2, 55 | "catCstTypeConcentricity":3, 56 | "catCstTypeTangency":4, 57 | "catCstTypeLength":5, 58 | "catCstTypeAngle":6, 59 | "catCstTypePlanarAngle":7, 60 | "catCstTypeParallelism":8, 61 | "catCstTypeAxisParallelism":9, 62 | "catCstTypeHorizontality":10, 63 | "catCstTypePerpendicularity":11, 64 | "catCstTypeAxisPerpendicularity":12, 65 | "catCstTypeVerticality":13, 66 | "catCstTypeRadius":14, 67 | "catCstTypeSymmetry":15, 68 | "catCstTypeMidPoint":16, 69 | "catCstTypeEquidistance":17, 70 | "catCstTypeMajorRadius":18, 71 | "catCstTypeMinorRadius":19, 72 | "catCstTypeSurfContact":20, 73 | "catCstTypeLinContact":21, 74 | "catCstTypePoncContact":22, 75 | "catCstTypeChamfer":23, 76 | "catCstTypeChamferPerpend":24, 77 | "catCstTypeAnnulContact":25, 78 | "catCstTypeCylinderRadius":26, 79 | "catCstTypeStContinuity":27, 80 | "catCstTypeStDistance":28, 81 | "catCstTypeSdContinuity":29, 82 | "catCstTypeSdShape":30 83 | :param cstType: Constraint Type 84 | :type cstType: int 85 | :param references: 86 | :return: Created Constraint 87 | :rtype: :class:`~Rice.generalObjects.constraint.Constraint` 88 | """ 89 | if len(references)==1: 90 | const = self.constraints_coll.AddMonoEltCst(cstType, references[0]) 91 | elif len(references)==2: 92 | const = self.constraints_coll.AddBiEltCst(cstType, *references) 93 | elif len(references) == 3: 94 | const = self.constraints_coll.AddTriEltCst(cstType, *references) 95 | else: 96 | raise AttributeError('"references" must have 1,2 or 3 elements') 97 | return const 98 | 99 | @Open_Close 100 | def remove_constraint(self, const): 101 | self.constraints_coll.remove(const) 102 | 103 | @property 104 | def name(self): 105 | return self.cat_constructor.Name 106 | 107 | @name.setter 108 | def name(self, value): 109 | self.cat_constructor.Name = value 110 | 111 | @Open_Close 112 | def arc(self, center, r, start, end, angle='deg'): 113 | """ 114 | 115 | :param center: arc's center, [float, float] 116 | :type center: list of float 117 | :param r: radius of arc 118 | :type r: float 119 | :param start: starting angle 120 | :type start: float 121 | :param end: ending angle 122 | :type end: float 123 | :param angle: measuring units of angles 124 | :type angle: str 125 | :return: Created Arc 126 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.circle2D.Circle2D` 127 | """ 128 | if angle == 'deg': 129 | start = rad_degrees('rad', start) 130 | end = rad_degrees('rad', end) 131 | circle = self.factory2d.AddArc(center, r, start, end) 132 | 133 | return circle 134 | 135 | @Open_Close 136 | def circle(self, center, r): 137 | """ 138 | 139 | :param center: arc's center, [float, float] 140 | :type center: list of float 141 | :param r: radius of arc 142 | :type r: float 143 | :return: Created Circle 144 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.circle2D.Circle2D` 145 | """ 146 | 147 | circle = self.factory2d.AddCircle(center, r) 148 | 149 | return circle 150 | 151 | @Open_Close 152 | def line2D(self, start, end, paint_start=True, paint_end=True): 153 | """ 154 | 155 | :param start: [float, float] coordinates of starting point 156 | :type start: list of float 157 | :param end: [float, float] coordinates of starting point 158 | :type end: list of float 159 | :param paint_start: Do you want paint the starting point? 160 | :type paint_start: bool 161 | :param paint_end:Do you want paint the ending point? 162 | :type paint_end: bool 163 | :return: Created Line 164 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.line2D.Line2D` 165 | """ 166 | 167 | line = self.factory2d.AddLine(start, end) 168 | 169 | if paint_start: 170 | line.start_point() 171 | if paint_end: 172 | line.end_point() 173 | 174 | return line 175 | 176 | @Open_Close 177 | def point2D(self, xc, yc): 178 | """ 179 | 180 | :param xc: x coordinate 181 | :type xc: float 182 | :param yc: y coordinate 183 | :type yc: float 184 | :return: Created point 185 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.point2D.Point2D` 186 | """ 187 | 188 | point = self.factory2d.AddPoint(xc, yc) 189 | 190 | return point 191 | 192 | def close_path(self, points): 193 | """ 194 | Creates a closed path of points 195 | :param points: list of points [[float, float], [float, float], ...] 196 | :type points: list of (list of float) 197 | :return: list of lines 198 | :rtype: list of :class:`~Rice.abstractObjects.geometric2Delements.line2D.Line2D` 199 | """ 200 | line_list = list() 201 | start = points[0] 202 | for i in range(len(points)-1): 203 | line = self.line2D(start, points[i+1], paint_start=True, paint_end=True) 204 | start = line.end 205 | line_list.append(line) 206 | else: 207 | line = self.line2D(start, line_list[0].start, paint_start=True, paint_end=True) 208 | line_list.append(line) 209 | 210 | return line_list 211 | 212 | @Open_Close 213 | def spline2D(self, points): 214 | """ 215 | 216 | :param points: list of points 217 | :type points: list of (list of float or :class:`~Rice.abstractObjects.geometric2Delements.point2D.Point2D`) 218 | :return: Created Spline 219 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.spline2D.Spline2D` 220 | """ 221 | 222 | spline = self.factory2d.AddSpline(points) 223 | 224 | return spline 225 | 226 | def arc_by_points(self, point1, point2, r, solution): 227 | """ 228 | Create a circle arc that pass through two points 229 | :param point1: coordinates of one point 230 | :type point1: list of float 231 | :param point2: coordinates of another point 232 | :type point2: list of float 233 | :param r: radius 234 | :type r: float 235 | :param solution: 0 or 1 236 | :return: Created circle 237 | :rtype: :class:`~Rice.abstractObjects.geometric2Delements.circle2D.Circle2D` 238 | """ 239 | 240 | Pt = namedtuple('Pt', 'x, y') 241 | Circle = Cir = namedtuple('Circle', 'x, y, r') 242 | def circles_from_p1p2r(p1, p2, r): 243 | 'Following explanation at http://mathforum.org/library/drmath/view/53027.html' 244 | if r == 0.0: 245 | raise ValueError('radius of zero') 246 | (x1, y1), (x2, y2) = p1, p2 247 | if p1 == p2: 248 | raise ValueError('coincident points gives infinite number of Circles') 249 | # delta x, delta y between points 250 | dx, dy = x2 - x1, y2 - y1 251 | # dist between points 252 | q = sqrt(dx**2 + dy**2) 253 | if q > 2.0*r: 254 | raise ValueError('separation of points > diameter') 255 | # halfway point 256 | x3, y3 = (x1+x2)/2, (y1+y2)/2 257 | # distance along the mirror line 258 | d = sqrt(r**2-(q/2)**2) 259 | # One answer 260 | c1 = Cir(x = x3 - d*dy/q, 261 | y = y3 + d*dx/q, 262 | r = abs(r)) 263 | # The other answer 264 | c2 = Cir(x = x3 + d*dy/q, 265 | y = y3 - d*dx/q, 266 | r = abs(r)) 267 | return c1, c2 268 | 269 | result = circles_from_p1p2r(point1, point2, r) 270 | alpha1 = np.arctan2((point1[1]-result[0].y),(point1[0]-result[solution].x)) 271 | alpha2 = np.arctan2((point2[1]-result[0].y),(point2[0]-result[solution].x)) 272 | 273 | circle = self.arc([result[0].x,result[0].y], r,alpha1, alpha2, angle='rad') 274 | return circle 275 | -------------------------------------------------------------------------------- /src/Rice/abstractObjects/documents/part.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from ...generalObjects.factory import Factory 4 | from ...generalObjects.originElements import OriginElements 5 | from ...collectionsObject.hybridBodies import HybridBodies 6 | from ...collectionsObject.bodies import Bodies 7 | from ...collectionsObject.parameters import Parameters 8 | from ...collectionsObject.relations import Relations 9 | from ...collectionsObject.orderedGeometricalSets import OrderedGeometricalSets 10 | from ...baseClasses.anyObject import AnyObject 11 | 12 | 13 | class Part(AnyObject): 14 | """ 15 | Catia's PART object 16 | """ 17 | def __init__(self, parent=None): 18 | 19 | self.parent = parent[parent[-1]] 20 | self.parentsDict = parent 21 | self.cat_constructor = self.parent.cat_constructor.Part 22 | self.parentsDict[self.name] = self 23 | self.bodies_COLL = Bodies(self.parentsDict._copy()) 24 | self.bodies_COLL.add('PartBody') 25 | 26 | self.originElements = OriginElements(self.parentsDict._copy()) 27 | 28 | self.factory = Factory(self.parentsDict) 29 | 30 | @property 31 | def name(self): 32 | """ 33 | Return the Catia's element name 34 | 35 | :return: 36 | :rtype: str 37 | """ 38 | return self.cat_constructor.Name 39 | 40 | @name.setter 41 | def name(self, value): 42 | """ 43 | Set the Catia's element name 44 | """ 45 | self.cat_constructor.Name = value 46 | 47 | def add_body(self): 48 | """ 49 | Add a body to the part 50 | 51 | :return: Last Body created 52 | :rtype: :class:`~Rice.generalObjects.body.Body` 53 | """ 54 | self.bodies_COLL.add() 55 | return self.bodies_COLL.deque[-1] 56 | 57 | def get_geometrical_set(self): 58 | """ 59 | Get all geometrical sets 60 | 61 | :return: list of geometrical sets created 62 | :rtype: list of :class:`~Rice.generalObjects.hybridBody.HybridBody` 63 | """ 64 | return self.hybrid_bodies_COLL.deque 65 | 66 | def get_bodies(self): 67 | """ 68 | Get all created bodies. 69 | 70 | :return: list of created bodies 71 | :rtype: list of :class:`~Rice.generalObjects.body.Body` 72 | """ 73 | return self.bodies_COLL.deque 74 | 75 | def _create_reference_from_name(self, reference): 76 | obj = self.cat_constructor.CreateReferenceFromName(reference) 77 | return obj 78 | 79 | def add_ordered_geometrical_set(self): 80 | """ 81 | Add an ordered geometrical set 82 | 83 | :return: Last OrderedGeometricalSet 84 | :rtype: :class:`~Rice.generalObjects.orderedGeometricalSet.OrderedGeometricalSet` 85 | """ 86 | try: 87 | self.ordered_geometrical_set_COLL.add() 88 | 89 | except AttributeError: 90 | self.ordered_geometrical_set_COLL = OrderedGeometricalSets(self.parentsDict._copy()) 91 | self.ordered_geometrical_set_COLL.add() 92 | return self.ordered_geometrical_set_COLL.deque[-1] 93 | 94 | def get_ordered_geometrical_set(self): 95 | """ 96 | Get all ordered geometrical sets created 97 | :return: 98 | :rtype: list of :class:`~Rice.generalObjects.orderedGeometricalSet.OrderedGeometricalSet` 99 | """ 100 | return self.ordered_geometrical_set_COLL.deque 101 | 102 | def geometrical_set(self): 103 | """ 104 | Add a geometrical set or get the geometrical sets created 105 | 106 | :return: Last geometricalSet or list of geometricalSet 107 | :rtype: list of :class:`~Rice.generalObjects.hybridBody.HybridBody` or :class:`~Rice.generalObjects.hybridBody.HybridBody` 108 | """ 109 | try: 110 | return self.hybrid_bodies_COLL 111 | 112 | except AttributeError: 113 | self.hybrid_bodies_COLL = HybridBodies(self.parentsDict._copy()) 114 | self.hybrid_bodies_COLL.add() 115 | return self.hybrid_bodies_COLL.deque[-1] 116 | """ 117 | def setting(self): 118 | 119 | Add a settings object to change Catia's settings 120 | 121 | :return: Last or list of settings object (:py:class:`~collectionsObject.settingsF.settings.Settings`) 122 | 123 | try: 124 | return self.setting_COLL 125 | 126 | except AttributeError: 127 | self.setting_COLL = Collection(self.parentsDict['CNEXT'].parentsDict._copy(), 'collectionsObject.settingF.setting.Settings', 'SettingControllers') 128 | self.setting_COLL.add() 129 | return self.setting_COLL.deque[-1] 130 | """ 131 | def plane(self, option, reference, *args): 132 | """ 133 | Create a plane on Part. 134 | 135 | +---------------------------+-------------------------------------------------------+ 136 | | option | args | 137 | +---------------------------+-------------------------------------------------------+ 138 | | Offset from plane | (distance, reverse ) | 139 | | | | 140 | | | distance: | 141 | | | Distance from reference to new plane | 142 | | | reverse: | 143 | | | True ---> reverse direction | 144 | | | False --> not reverse | 145 | +---------------------------+-------------------------------------------------------+ 146 | | | 147 | | Only implemented for offset from plane | 148 | +---------------------------+-------------------------------------------------------+ 149 | 150 | :param option: options, see docstring to more information 151 | :type option: str 152 | :param reference: 153 | :type reference: str or :class:`~Rice.abstractObjects.hybridShapes.plane.Plane` 154 | :param args: list of arguments needed 155 | :return: Created plane 156 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.plane.Plane` 157 | """ 158 | self.geometrical_set() 159 | if reference.lower() in ['xy','yx','zx','xz','zy','yz']: 160 | reference = self.originElements.get(reference) 161 | hybridFactory = self.factory.hybrid_shape_factory() 162 | if option == 'Offset from plane': 163 | try: reverse = args[1] 164 | except:reverse = False 165 | plane = hybridFactory.AddNewPlaneOffset(self.hybrid_bodies_COLL.deque[-1], reference, args[0], reverse) 166 | elif option == 'Angle/Normal to plane': 167 | pass 168 | else: 169 | pass 170 | return plane 171 | 172 | def export_data(self, file_path, extension): 173 | """ 174 | Exports CATPart to other format. 175 | 176 | Extension: 177 | - stl 178 | - igs 179 | - model 180 | - stp 181 | - 3dmap 182 | - 3dxml 183 | - cgr 184 | - hcg 185 | - icem 186 | - NavRep 187 | - vps 188 | - wrl 189 | 190 | :param file_path 191 | :type file_path: str 192 | :param extension: type of exported data 193 | :type extension: str 194 | """ 195 | self.parent.export_data(file_path, extension) 196 | 197 | def save(self, file_path): 198 | """ 199 | Path to saved file 200 | :param file_path: path 201 | :type file_path: str 202 | """ 203 | self.parent.save(file_path) 204 | 205 | def line3D(self, start, end, st1=None,sl1=None,st2=None, sl2=None,geometrical_set=None): #OJOOOOOOOOOOOOOOOOOOoo cambiado 206 | """ 207 | 208 | Create a 3D line from two points. 209 | 210 | :param start: Start Point 211 | :type start: list of float or :class:`~Rice.abstractObjects.hybridShapes.point.PointCoord` 212 | :param end: End point 213 | :type end: list of float or :class:`~Rice.abstractObjects.hybridShapes.point.PointCoord` 214 | :param st1: TODO 215 | :param sl1: TODO 216 | :param st2: TODO 217 | :param sl2: TODO 218 | :param geometrical_set: geometrical set 219 | :type geometrical_set: :py:class:`~collectionsObject.hybridBodiesF.hybridBodies.HybridBody` 220 | :return: Line created 221 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.line.LinePtPt` 222 | """ 223 | if geometrical_set: 224 | geom = geometrical_set 225 | else: 226 | self.geometrical_set() 227 | geom = self.get_geometrical_set()[0] 228 | start = self.point3D(start, st1, sl1) 229 | end = self.point3D(end, st2, sl2) 230 | line = self.factory.hybrid_shape_factory().AddNewLinePtPt(geom, start, end) 231 | return line 232 | 233 | def point3D(self, obj,st=None, sl=None, geometrical_set=None): 234 | """ 235 | Create a 3D point from its coordinates. 236 | 237 | :param obj: coords of point 238 | :type obj: list of float or :class:`~Rice.abstractObjects.hybridShapes.point.PointCoord` 239 | :param st: TODO 240 | :param sl: TODO 241 | :param geometrical_set: geometrical set used 242 | :type geometrical_set: :class:`~Rice.collectionsObject.hybridBodies.HybridBody` 243 | :return: Point created 244 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.point.PointCoord` 245 | """ 246 | if geometrical_set: 247 | geom = geometrical_set 248 | else: 249 | self.geometrical_set() 250 | geom = self.get_geometrical_set()[0] 251 | if isinstance(obj, list): 252 | result = [obj, None] 253 | else: 254 | result = [None, self._createReferenceFromBRepName(obj, st, sl)] 255 | point = self.factory.hybrid_shape_factory().AddNewPointCoord(geom, *result) 256 | return point 257 | 258 | def fill(self, objs, geometrical_set=None): 259 | """ 260 | Catia`s fill operation. Create a surface between objects. 261 | 262 | :param objs: objects to fill. 263 | :type objs: list of (:class:`~Rice.generalObjects.sketch.Sketch` or :class:`~Rice.abstractObjects.hybridShape.HybridShape`) 264 | :param geometrical_set: geometrical set used 265 | :type geometrical_set: :class:`~Rice.collectionsObject.hybridBodies.HybridBody` 266 | :return: Created surface 267 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.fill.Fill` 268 | """ 269 | if geometrical_set: 270 | geom = geometrical_set 271 | else: 272 | self.geometrical_set() 273 | geom = self.get_geometrical_set()[0] 274 | 275 | fill = self.factory.hybrid_shape_factory().AddNewFill(geom, objs) 276 | return fill 277 | 278 | def join(self, objs, geometrical_set=None): 279 | """ 280 | Catia's join operation 281 | 282 | :param objs: objs to join 283 | :type objs: list of :class:`~Rice.abstractObjects.hybridShape.HybridShape` 284 | :param geometrical_set: geometrical set used 285 | :type geometrical_set: :class:`~Rice.collectionsObject.hybridBodies.HybridBody` 286 | :return: Joined surface 287 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.join.Join` 288 | """ 289 | if geometrical_set: 290 | geom = geometrical_set 291 | else: 292 | self.geometrical_set() 293 | geom = self.get_geometrical_set()[0] 294 | 295 | join = self.factory.hybrid_shape_factory().AddNewJoin(geom, objs) 296 | return join 297 | 298 | def spline(self, points, geometrical_set=None): 299 | """ 300 | Catia's spline 3D operation. 301 | 302 | :param points: list of points 303 | :type points: list of (list of(int or float or :class:`~Rice.abstractObjects.hybridShapes.point.PointCoord`)) 304 | :param geometrical_set: geometrical set used 305 | :type geometrical_set: :class:`~Rice.collectionsObject.hybridBodies.HybridBody` 306 | :return: Spline created 307 | :rtype: :class:`~Rice.abstractObjects.hybridShapes.spline.Spline` 308 | """ 309 | if geometrical_set: 310 | geom = geometrical_set 311 | else: 312 | self.geometrical_set() 313 | geom = self.get_geometrical_set()[0] 314 | references = list() 315 | for i in points: 316 | if isinstance(i, list): 317 | references.append(self.point3D(i)) 318 | else: 319 | references.append(i) 320 | spline = self.factory.hybrid_shape_factory().AddNewSpline(geom, references) 321 | return spline 322 | 323 | def _createReferenceFromBRepName(self, obj, param1, param2): 324 | """ 325 | Only implemented for spline's Vertex 326 | param1 = 2 if obj is spline's first point 327 | 3 if obj is spline's last point 328 | param2 = +1 if obj is spline's first point 329 | -1 if obj is spline's last point 330 | :param obj: 331 | :return: 332 | """ 333 | sketch1 = obj.parent 334 | reference1 = self.cat_constructor.CreateReferenceFromBRepName( 335 | "BorderFVertex:(BEdge:(Brp:({};{});None:(Limits1:();Limits2:();{});Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)".format( 336 | sketch1.name, param1, param2), sketch1.cat_constructor) 337 | return reference1 338 | 339 | def _createReferenceFromObject(self, obj): 340 | """ 341 | :param obj: 342 | :return: 343 | """ 344 | reference1 = self.cat_constructor.CreateReferenceFromObject(obj.cat_constructor) 345 | return reference1 346 | 347 | def create_param(self, param_type, name, value): 348 | """ 349 | 350 | :param param_type: real, .... 351 | :type param_type: str 352 | :param name: Parameter's name 353 | :type name: str 354 | :param value: value of parameter 355 | :type value: float 356 | :return: Created parameter 357 | :rtype: :class:`~Rice.generalObjects.parameter.Parameter` 358 | """ 359 | try: self.param_coll 360 | except: self.param_coll = Parameters(self.parentsDict._copy()) 361 | 362 | obj = self.param_coll.__getattribute__('create_{}'.format(param_type))(name, value) 363 | return obj 364 | 365 | def create_formula(self, name, output, formula, comment=""): 366 | """ 367 | 368 | :param name: Formula's name 369 | :type name: str 370 | :param output: Parameter object of the formula 371 | :type output: str 372 | :param formula: Expression 373 | :type formula: str 374 | :param comment: 375 | :return: formula created 376 | :rtype: :class:`~Rice.generalObjects.relation.Relation` 377 | """ 378 | try: self.relations_coll 379 | except: self.relations_coll = Relations(self.parentsDict._copy()) 380 | 381 | obj = self.relations_coll.create_formula(name, output, formula, comment) 382 | 383 | return obj 384 | 385 | def update(self): 386 | """ 387 | Update part 388 | """ 389 | self.cat_constructor.Update() 390 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [RICE](RICE) 2 | 3 | > An API for easily automating creation 3D model using CATIA V5. 4 | RICE implements some operations to work with solids and surfaces. 5 | 6 | # Table of contents 7 | - [Installing / Getting started](#installing-getting-started) 8 | - [Examples](#examples) 9 | - [Cube](#cube) 10 | - [Compressor blade](#compressor-blade) 11 | - [Implemented operations](#implemented-operations>) 12 | - [Mechanical Design](#mechanical-design) 13 | - [Part Design](#part-design) 14 | - [Add body](#add-body) 15 | - [Pad](#pad) 16 | - [Pocket](#pocket) 17 | - [Sketch](#sketch) 18 | - [2D Line](#2d-line) 19 | - [Arc](#arc) 20 | - [Circle](#circle) 21 | - [Close path](#close-path) 22 | - [2D spline](#2d-spline) 23 | - [Arc by points](#arc-by-points) 24 | - [Constraints](#constraints) 25 | - [Shape](#shape) 26 | - [Generative Shape Design](#generative-shape-design) 27 | - [Fill](#fill) 28 | - [Join](#join) 29 | - [Common](#common) 30 | - [Create plane](#create-plane) 31 | - [Offset from plane](#offset-from-plane) 32 | - [3D line](#3d-line) 33 | - [Line Point to Point](#line-point-to-point) 34 | - [3D point](#3d-point) 35 | - [Point from cords](#point-from-cords) 36 | - [3D spline](#3d-spline) 37 | - [Create parameter](#create-parameter) 38 | - [Create relation](#create-relation) 39 | - [Formula](#formula) 40 | - [Save](#save) 41 | - [Export data](#export-data) 42 | 43 | ## Installing / Getting started 44 | 45 | - Installing library: 46 | Download src folder and then install it via shell. 47 | ````shell 48 | python setup.py 49 | ```` 50 | Then import it, 51 | ````python 52 | from Rice.application import Application 53 | ```` 54 | - Copying library: 55 | Download src folder and copy it to the root folder of your project. Then import it like a normal module. 56 | ````python 57 | from Rice.application import Application 58 | ```` 59 | # Examples 60 | 61 | - #### Cube 62 | ![alt text](readme_images/50mmCube.png) 63 | 64 | ````python 65 | from Rice.application import Application 66 | import os 67 | 68 | # Initializing connection with Catia 69 | app = Application() 70 | 71 | # Get created parts 72 | parts = app.get_parts() 73 | part = parts[0] 74 | 75 | # Get created bodies 76 | body = part.get_bodies()[0] 77 | 78 | # Add a sketch on XY plane 79 | sketch = body.add_sketch('xy') 80 | 81 | # Add a close path to sketch 82 | sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 83 | 84 | # Generating "Pad" operation with "sketch" and 50 mm height 85 | pad = body.pad(sketch, 50) 86 | 87 | # Save part, name.CatPART 88 | part.save(os.path.join(os.path.abspath(''),'name')) 89 | ```` 90 | - #### Compressor blade 91 | 92 | ![alt text](readme_images/alabe.png) 93 | 94 | ````python 95 | from Rice.application import Application 96 | import os 97 | import pickle 98 | 99 | # Getting blade geometry 100 | f = open('blade_data', 'rb') 101 | blade_data = pickle.load(f) 102 | args=blade_data 103 | 104 | # Initializing connection with Catia 105 | app = Application() 106 | 107 | # Get created parts 108 | parts = app.get_parts() 109 | part = parts[0] 110 | 111 | # Get created bodies 112 | body = part.get_bodies()[0] 113 | 114 | # Formatting data 115 | list_profiles_up = [args[i]['profile_UP'] for i in range(len(args)-1)] 116 | list_profiles_down = [args[i]['profile_DOWN'] for i in range(len(args)-1)] 117 | spline_extrados = list() 118 | spline_intrados = list() 119 | list_z = [args[i]['r'] for i in range(len(args)-1)] 120 | for i, n, j in zip(list_profiles_up, list_profiles_down, list_z): 121 | 122 | # Creating plane 123 | plane = part.plane('Offset from plane', 'XY', j * 1000) 124 | 125 | # Adding sketch on "plane" 126 | sketch = body.add_sketch(plane) 127 | 128 | # Adding 2D spline to "sketch" 129 | spline = sketch.spline2D([[p[0] * 1000, p[1] * 1000] for p in i]) 130 | spline_extrados.append(spline) 131 | 132 | # Adding sketch on "plane" 133 | sketch2 = body.add_sketch(plane) 134 | 135 | # Adding 2D spline to "sketch2" 136 | spline2 = sketch2.spline2D([[i[0][0]*1000, i[0][1]*1000]]+[[p[0] * 1000, p[1] * 1000] for p in n]+[[i[-1][0]*1000, i[-1][1]*1000]]) 137 | spline_intrados.append(spline2) 138 | 139 | # Creating leading edge spline 140 | spline_delante = part.spline([[args[i]['profile_UP'][0][0]*1000, args[i]['profile_UP'][0][1]*1000, args[i]['r']*1000] for i in range(len(args)-1)]) 141 | 142 | # Creating trailing edge spline 143 | spline_detas = part.spline([[args[i]['profile_UP'][-1][0]*1000, args[i]['profile_UP'][-1][1]*1000, args[i]['r']*1000] for i in range(len(args)-1)]) 144 | fill = list() 145 | 146 | for i in range(len(spline_intrados)-1): 147 | objs = list() 148 | objs.append(spline_delante) 149 | objs.append(spline_intrados[i]) 150 | objs.append(spline_detas) 151 | objs.append(spline_intrados[i+1]) 152 | # Creating "fill" 153 | fill.append(part.fill(objs)) 154 | objs = list() 155 | objs.append(spline_delante) 156 | objs.append(spline_extrados[i]) 157 | objs.append(spline_detas) 158 | objs.append(spline_extrados[i + 1]) 159 | # Creating "fill" 160 | fill.append(part.fill(objs)) 161 | 162 | part.update() 163 | 164 | # Joining all the created surfaces 165 | join = part.join(fill) 166 | part.update() 167 | 168 | # Exporting model with "stl" format, test.stl 169 | part.export_data(os.path.abspath('')+r'\test','stl') 170 | ```` 171 | 172 | # Implemented operations 173 | 174 | - ## Mechanical Design 175 | - ### Part Design 176 | - #### Add body 177 | ````python 178 | from Rice.application import Application 179 | 180 | # Initializing connection with CATIA 181 | app = Application() 182 | 183 | # Getting "parts" created. Once CATIA connection is enabled a part is created 184 | # automatically. 185 | parts = app.get_parts() 186 | part = parts[0] 187 | 188 | # Adding "Body" to "part". 189 | part.add_body() 190 | # Getting created "bodies" 191 | bodies = part.get_bodies() 192 | ```` 193 | - #### Pad 194 | ````python 195 | from Rice.application import Application 196 | 197 | # Initializing connection with CATIA 198 | app = Application() 199 | 200 | # Getting "parts" created. Once CATIA connection is enabled a part is created 201 | # automatically. 202 | parts = app.get_parts() 203 | part = parts[0] 204 | 205 | # Getting "bodies". PartBody body is automatically created. 206 | body, = part.get_bodies() 207 | 208 | # Add a "sketch" on "XY" plane. 209 | sketch = body.add_sketch('XY') 210 | 211 | # Add a close path to sketch. 212 | sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 213 | 214 | # Creating a "pad" 50 mm height from "sketch". 215 | body.pad(sketch, 50) 216 | ```` 217 | - #### Pocket 218 | ````python 219 | from Rice.application import Application 220 | 221 | # Initializing connection with CATIA 222 | app = Application() 223 | 224 | # Getting "parts" created. Once CATIA connection is enabled a part is created 225 | # automatically. 226 | parts = app.get_parts() 227 | part = parts[0] 228 | 229 | # Getting "bodies". PartBody body is automatically created. 230 | body, = part.get_bodies() 231 | 232 | # Add a "sketch" on "XY" plane. 233 | sketch = body.add_sketch('XY') 234 | 235 | # Add a close path to sketch. 236 | sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 237 | 238 | # Creating a "pad" 50 mm height from "sketch". 239 | pad = body.pad(sketch, 50) 240 | 241 | # Creating a "sketch" on the upper face of the "pad". 242 | sketch2 = body.add_sketch(pad['up']) 243 | 244 | # Adding a circle with centre (25mm,25mm) and radius 10 mm. 245 | sketch2.circle([25,25], 10) 246 | 247 | # Creating a pocket from "sketch2". 248 | body.pocket(sketch2,10) 249 | ```` 250 | - #### Sketch 251 | - ##### 2D Line 252 | ````python 253 | from Rice.application import Application 254 | 255 | # Initializing connection with CATIA 256 | app = Application() 257 | 258 | # Getting "parts" created. Once CATIA connection is enabled a part is created 259 | # automatically. 260 | parts = app.get_parts() 261 | part = parts[0] 262 | 263 | # Getting "bodies". PartBody body is automatically created. 264 | body, = part.get_bodies() 265 | 266 | # Add a "sketch" on "XY" plane. 267 | sketch = body.add_sketch('XY') 268 | 269 | # Creating 2D line, (0,0) start point and (10,10) end point. 270 | sketch.line2D([0,0],[10,10]) 271 | ```` 272 | - ##### Arc 273 | ````python 274 | from Rice.application import Application 275 | 276 | # Initializing connection with CATIA 277 | app = Application() 278 | 279 | # Getting "parts" created. Once CATIA connection is enabled a part is created 280 | # automatically. 281 | parts = app.get_parts() 282 | part = parts[0] 283 | 284 | # Getting "bodies". PartBody body is automatically created. 285 | body, = part.get_bodies() 286 | 287 | # Add a "sketch" on "XY" plane. 288 | sketch = body.add_sketch('XY') 289 | 290 | # Creating an arc with (0,0) centre, 20 mm radius and from 0 to 270 degrees. 291 | sketch.arc([0,0],20, 0, 270) 292 | ```` 293 | - ##### Circle 294 | ````python 295 | from Rice.application import Application 296 | 297 | # Initializing connection with CATIA 298 | app = Application() 299 | 300 | # Getting "parts" created. Once CATIA connection is enabled a part is created 301 | # automatically. 302 | parts = app.get_parts() 303 | part = parts[0] 304 | 305 | # Getting "bodies". PartBody body is automatically created. 306 | body, = part.get_bodies() 307 | 308 | # Add a "sketch" on "XY" plane. 309 | sketch = body.add_sketch('XY') 310 | 311 | # Creating a (0,0) center and 20mm radius circle 312 | sketch.circle([0,0],20) 313 | ```` 314 | - ##### Close path 315 | ````python 316 | from Rice.application import Application 317 | 318 | # Initializing connection with CATIA 319 | app = Application() 320 | 321 | # Getting "parts" created. Once CATIA connection is enabled a part is created 322 | # automatically. 323 | parts = app.get_parts() 324 | part = parts[0] 325 | 326 | # Getting "bodies". PartBody body is automatically created. 327 | body, = part.get_bodies() 328 | 329 | # Add a "sketch" on "XY" plane. 330 | sketch = body.add_sketch('XY') 331 | 332 | # Creating a close path with a list of points. 333 | sketch.close_path([[0,0],[10,0],[15,7.5],[15,15],[0,15]]) 334 | ```` 335 | - ##### 2D spline 336 | ````python 337 | from Rice.application import Application 338 | 339 | # Initializing connection with CATIA 340 | app = Application() 341 | 342 | # Getting "parts" created. Once CATIA connection is enabled a part is created 343 | # automatically. 344 | parts = app.get_parts() 345 | part = parts[0] 346 | 347 | # Getting "bodies". PartBody body is automatically created. 348 | body, = part.get_bodies() 349 | 350 | # Add a "sketch" on "XY" plane. 351 | sketch = body.add_sketch('XY') 352 | 353 | # Add a spline 2D through a list of points. 354 | sketch.spline2D([[0,0],[10,0],[15,7.5],[15,15],[0,15]]) 355 | ```` 356 | - ##### Arc by points 357 | ````python 358 | from Rice.application import Application 359 | 360 | # Initializing connection with CATIA 361 | app = Application() 362 | 363 | # Getting "parts" created. Once CATIA connection is enabled a part is created 364 | # automatically. 365 | parts = app.get_parts() 366 | part = parts[0] 367 | 368 | # Getting "bodies". PartBody body is automatically created. 369 | body, = part.get_bodies() 370 | 371 | # Add a "sketch" on "XY" plane. 372 | sketch = body.add_sketch('XY') 373 | 374 | sketch.arc_by_points([0,0],[10,0],20, 0) 375 | ```` 376 | - ##### Constraints 377 | ````python 378 | from Rice.application import Application 379 | 380 | # Initializing connection with CATIA 381 | app = Application() 382 | 383 | # Getting "parts" created. Once CATIA connection is enabled a part is created 384 | # automatically. 385 | parts = app.get_parts() 386 | part = parts[0] 387 | 388 | # Getting "bodies". PartBody body is automatically created. 389 | body, = part.get_bodies() 390 | 391 | # Add a "sketch" on "XY" plane. 392 | sketch = body.add_sketch('XY') 393 | 394 | # Generating close path 395 | lines = sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 396 | 397 | # Adding a Length constraint to the first line of "lines". 398 | const = sketch.set_constraint(5, lines[0]) 399 | 400 | # Adding an Angle constraint between the first and the second line of "lines". 401 | const2 = sketch.set_constraint(6, lines[0], lines[1]) 402 | ```` 403 | - ## Shape 404 | - ### Generative Shape Design 405 | - #### Fill 406 | ````python 407 | from Rice.application import Application 408 | 409 | # Initializing connection with CATIA 410 | app = Application() 411 | 412 | # Getting "parts" created. Once CATIA connection is enabled a part is created 413 | # automatically. 414 | parts = app.get_parts() 415 | part = parts[0] 416 | 417 | # Getting "bodies". PartBody body is automatically created. 418 | body, = part.get_bodies() 419 | 420 | # Add a "sketch" on "XY" plane. 421 | sketch = body.add_sketch('XY') 422 | 423 | # Creating spline 2D on "sketch" 424 | sketch.spline2D([[0, 15], [5, 10], [10, 5], [20, 15]]) 425 | 426 | # Creating 3D lines. 427 | line1 = part.line3D([0, 15, 0], [0, 15, 15]) 428 | line2 = part.line3D([20, 15, 0], [20, 15, 15]) 429 | line3 = part.line3D([0, 15, 15], [20, 15, 15]) 430 | 431 | # Join with a surface "line1", "sketch", "line2" and "line3". 432 | part.fill([line1, sketch, line2, line3]) 433 | ```` 434 | - #### Join 435 | ````python 436 | from Rice.application import Application 437 | 438 | # Initializing connection with CATIA 439 | app = Application() 440 | 441 | # Getting "parts" created. Once CATIA connection is enabled a part is created 442 | # automatically. 443 | parts = app.get_parts() 444 | part = parts[0] 445 | 446 | # Getting "bodies". PartBody body is automatically created. 447 | body, = part.get_bodies() 448 | 449 | # Add a "sketch" on "XY" plane. 450 | sketch = body.add_sketch('XY') 451 | 452 | # Creating spline 2D on "sketch" 453 | sketch.spline2D([[0, 15], [5, 10], [10, 5], [20, 15]]) 454 | 455 | # Creating 3D lines. 456 | line1 = part.line3D([0, 15, 0], [0, 15, 15]) 457 | line2 = part.line3D([20, 15, 0], [20, 15, 15]) 458 | line3 = part.line3D([0, 15, 15], [20, 15, 15]) 459 | 460 | # Join with a surface "line1", "sketch", "line2" and "line3". 461 | fill1 = part.fill([line1, sketch, line2, line3]) 462 | 463 | # Creating sketch on 'XY' plane 464 | sketch2 = body.add_sketch('xy') 465 | 466 | # Creating spline 2D on "sketch2" 467 | sketch2.spline2D([[0, 15], [5, 20], [10, 25], [20, 15]]) 468 | 469 | # Join with a surface "line1", "sketch2", "line2" and "line3". 470 | fill2 = part.fill([line1, sketch2, line2, line3]) 471 | 472 | # Joining surface "fill1" and "fill2". 473 | part.join([fill1, fill2]) 474 | ```` 475 | - ## Common 476 | - ### Create plane 477 | - #### Offset from plane 478 | ````python 479 | from Rice.application import Application 480 | 481 | # Initializing connection with CATIA 482 | app = Application() 483 | 484 | # Getting "parts" created. Once CATIA connection is enabled a part is created 485 | # automatically. 486 | parts = app.get_parts() 487 | part = parts[0] 488 | 489 | # Getting "bodies". PartBody body is automatically created. 490 | body, = part.get_bodies() 491 | 492 | # Creating 20 mm offset plane from 'XY' plane. 493 | plane = part.plane('Offset from plane', 'xy', 20) 494 | ```` 495 | - TO-DO 496 | - #### 3D line 497 | - ##### Line Point to Point 498 | ````python 499 | from Rice.application import Application 500 | 501 | # Initializing connection with CATIA 502 | app = Application() 503 | 504 | # Getting "parts" created. Once CATIA connection is enabled a part is created 505 | # automatically. 506 | parts = app.get_parts() 507 | part = parts[0] 508 | 509 | # Getting "bodies". PartBody body is automatically created. 510 | body, = part.get_bodies() 511 | 512 | # Creating 3D line. 513 | part.line3D([0,0,0], [10,20,50]) 514 | ```` 515 | - TO-DO 516 | - #### 3D point 517 | - ##### Point from cords 518 | ````python 519 | from Rice.application import Application 520 | 521 | # Initializing connection with CATIA 522 | app = Application() 523 | 524 | # Getting "parts" created. Once CATIA connection is enabled a part is created 525 | # automatically. 526 | parts = app.get_parts() 527 | part = parts[0] 528 | 529 | # Getting "bodies". PartBody body is automatically created. 530 | body, = part.get_bodies() 531 | 532 | # Creating 3D point. 533 | part.point3D([0,0,0]) 534 | ```` 535 | - TO-DO 536 | - #### 3D Spline 537 | ````python 538 | from Rice.application import Application 539 | 540 | # Initializing connection with CATIA 541 | app = Application() 542 | 543 | # Getting "parts" created. Once CATIA connection is enabled a part is created 544 | # automatically. 545 | parts = app.get_parts() 546 | part = parts[0] 547 | 548 | # Getting "bodies". PartBody body is automatically created. 549 | body, = part.get_bodies() 550 | 551 | # Creating 3D spline. 552 | part.spline([[0,0,0], [5,5,7], [10,5,15]]) 553 | ```` 554 | - #### Create parameter 555 | ````python 556 | from Rice.application import Application 557 | 558 | # Initializing connection with CATIA 559 | app = Application() 560 | 561 | # Getting "parts" created. Once CATIA connection is enabled a part is created 562 | # automatically. 563 | parts = app.get_parts() 564 | part = parts[0] 565 | 566 | # Getting "bodies". PartBody body is automatically created. 567 | body, = part.get_bodies() 568 | 569 | # Creating a real parameter called "Parameter1" with 50m initial value 570 | param = part.create_param('real', "Parameter1", 50) 571 | ```` 572 | - #### Create relation 573 | - ##### Formula 574 | ````python 575 | from Rice.application import Application 576 | 577 | # Initializing connection with CATIA 578 | app = Application() 579 | 580 | # Getting "parts" created. Once CATIA connection is enabled a part is created 581 | # automatically. 582 | parts = app.get_parts() 583 | part = parts[0] 584 | 585 | # Getting "bodies". PartBody body is automatically created. 586 | body, = part.get_bodies() 587 | 588 | # Creating 20 mm offset plane from 'XY' plane. 589 | plane = part.plane('Offset from plane', 'xy', 20) 590 | 591 | # Creating a real parameter called "Parameter1" with 0.03m initial value 592 | param = part.create_param('real', "Parameter1", 0.03) 593 | 594 | # Setting up a formula to set plane offset equal to two times the "Parameter1" value. 595 | part.create_formula('formula1', plane.offset(), '{}*2'.format(param.name)) 596 | ```` 597 | - TO-DO 598 | - #### Save 599 | ````python 600 | from Rice.application import Application 601 | import os 602 | 603 | # Initializing connection with Catia 604 | app = Application() 605 | 606 | # Get created parts 607 | parts = app.get_parts() 608 | part = parts[0] 609 | 610 | # Get created bodies 611 | body = part.get_bodies()[0] 612 | 613 | # Add a sketch on XY plane 614 | sketch = body.add_sketch('xy') 615 | 616 | # Add a close path to sketch 617 | sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 618 | 619 | # Generating "Pad" operation with "sketch" and 50 mm height 620 | pad = body.pad(sketch, 50) 621 | 622 | # Save part, name.CatPART 623 | part.save(os.path.join(os.path.abspath(''),'name')) 624 | ```` 625 | - #### Export data 626 | ````python 627 | from Rice.application import Application 628 | import os 629 | 630 | # Initializing connection with Catia 631 | app = Application() 632 | 633 | # Get created parts 634 | parts = app.get_parts() 635 | part = parts[0] 636 | 637 | # Get created bodies 638 | body = part.get_bodies()[0] 639 | 640 | # Add a sketch on XY plane 641 | sketch = body.add_sketch('xy') 642 | 643 | # Add a close path to sketch 644 | sketch.close_path([[0,0],[50,0],[50,50],[0,50]]) 645 | 646 | # Generating "Pad" operation with "sketch" and 50 mm height 647 | pad = body.pad(sketch, 50) 648 | 649 | # Save part as "stl" format, name.stl 650 | part.export_data(os.path.join(os.path.abspath(''),'name'),"stl") 651 | ```` --------------------------------------------------------------------------------