| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | __title__ = "BasicShapes.Shapes" |
| | __author__ = "Werner Mayer" |
| | __url__ = "https://www.freecad.org" |
| | __doc__ = "Basic shapes" |
| |
|
| |
|
| | import FreeCAD |
| | import Part |
| |
|
| |
|
| | def makeTube(outerRadius, innerRadius, height): |
| | outer_cylinder = Part.makeCylinder(outerRadius, height) |
| | shape = outer_cylinder |
| | if innerRadius > 0 and innerRadius < outerRadius: |
| | inner_cylinder = Part.makeCylinder(innerRadius, height) |
| | shape = outer_cylinder.cut(inner_cylinder) |
| | return shape |
| |
|
| |
|
| | class TubeFeature: |
| | def __init__(self, obj): |
| | obj.Proxy = self |
| | obj.addProperty( |
| | "App::PropertyLength", "OuterRadius", "Tube", "Outer radius", locked=True |
| | ).OuterRadius = 5.0 |
| | obj.addProperty( |
| | "App::PropertyLength", "InnerRadius", "Tube", "Inner radius", locked=True |
| | ).InnerRadius = 2.0 |
| | obj.addProperty( |
| | "App::PropertyLength", "Height", "Tube", "Height of the tube", locked=True |
| | ).Height = 10.0 |
| | obj.addExtension("Part::AttachExtensionPython") |
| |
|
| | def execute(self, fp): |
| | if fp.InnerRadius >= fp.OuterRadius: |
| | raise ValueError("Inner radius must be smaller than outer radius") |
| | fp.Shape = makeTube(fp.OuterRadius, fp.InnerRadius, fp.Height) |
| |
|
| |
|
| | def addTube(doc, name="Tube"): |
| | """addTube(document, [name]): adds a tube object""" |
| |
|
| | obj = doc.addObject("Part::FeaturePython", name) |
| | TubeFeature(obj) |
| | if FreeCAD.GuiUp: |
| | from . import ViewProviderShapes |
| |
|
| | ViewProviderShapes.ViewProviderTube(obj.ViewObject) |
| | return obj |
| |
|