Why the text is mirrored and upside down?

Why the text is mirrored and upside down?

Anonymous
Not applicable
795 Views
2 Replies
Message 1 of 3

Why the text is mirrored and upside down?

Anonymous
Not applicable

I am trying to create object and then emboss a number on it.  For the text, I  create a sketch  on  the global XZ construction plane. After the extrusion it shows that text is mirrored and rotated. It looks like the sketch is created on the opposite side of the XZ construction plane. 

How to create a sketch in proper orientation? How to control  orientation of a sketch? 

 

object with extruded textobject with extruded text

 

produced by this code

 

 
#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def _create_poly_XZ():
    a = 0.8
    b = a/2
    poly = [
        [a, -b, 0],
        [a+b, 0, 0],
        [a, a-b, 0],
        [-a, a-b, 0],
        [-a-b, 0, 0],
        [-a, -b, 0]
    ]
    return poly

def _create_poly_YZ():
    a = 0.8
    b = a/2
    d = 0.2
    poly = [
        [-b-d-d, -d,  0],
        [ 0,    d+b,  0],
        [b+d+d,  -d,  0]
    ]
    return poly

def _draw_poly(sketch, poly):
    sketch_lines = sketch.sketchCurves.sketchLines
    n_points = len(poly)
    for i in range(n_points - 1):
        p0 = poly[i]
        p1 = poly[i + 1]
        sketch_lines.addByTwoPoints(adsk.core.Point3D.create(p0[0], p0[1], p0[2]),
                                    adsk.core.Point3D.create(p1[0], p1[1], p1[2]))
    p0 = poly[-1]
    p1 = poly[0]

    sketch_lines.addByTwoPoints(adsk.core.Point3D.create(p0[0], p0[1], p0[2]),
                                adsk.core.Point3D.create(p1[0], p1[1], p1[2]))

def extrude_polygon_up_down(new_comp, poly, constr_plane, up, down):

    # Create a new sketch.
    sketches = new_comp.sketches
    sketch0 = sketches.add(constr_plane)

    _draw_poly(sketch0, poly)

    prof = sketch0.profiles.item(0)

    # extrude
    extrudes = new_comp.features.extrudeFeatures
    extrude_input = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

    ddef_up = adsk.core.ValueInput.createByReal(up)
    ddef_down = adsk.core.ValueInput.createByReal(down)

    distance_up = adsk.fusion.DistanceExtentDefinition.create(ddef_up)
    distance_down = adsk.fusion.DistanceExtentDefinition.create(ddef_down)
    extrude_input.setTwoSidesExtent(distance_up, distance_down)
    obj = extrudes.add(extrude_input)

    obj_collect = adsk.core.ObjectCollection.create()

    if obj.bodies.count == 1:  # single body
        body = obj.bodies.item(0)
        obj_collect.add(body)

    else:  # multiple bodies or empty
        for i in range(obj.bodies.count):
            body = obj.bodies.item(i)
            obj_collect.add(body)

    return obj_collect


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        root_comp = design.rootComponent
        allOccs = design.rootComponent.occurrences
        newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
        new_comp = newOcc.component

        xy_plane = root_comp.xYConstructionPlane
        yz_plane = root_comp.yZConstructionPlane
        xz_plane = root_comp.xZConstructionPlane

        poly_xz = _create_poly_XZ()
        cwxz_objs = extrude_polygon_up_down(new_comp, poly_xz, xz_plane, 1, 0)

        poly_yz = _create_poly_YZ()
        cwyz_objs = extrude_polygon_up_down(new_comp, poly_yz, yz_plane, 1.6, 1.6)

        combineFeatures = new_comp.features.combineFeatures
        combineFeatureInput = combineFeatures.createInput(cwxz_objs.item(0), cwyz_objs)
        combineFeatureInput.operation = adsk.fusion.FeatureOperations.IntersectFeatureOperation
        combineFeatureInput.isKeepToolBodies = False
        combineFeatureInput.isNewComponent = False
        combineFeatures.add(combineFeatureInput)

        # Create a new sketch.
        sketches = new_comp.sketches
        sketch = sketches.add(xz_plane)
        # Get sketch texts
        sketchTexts = sketch.sketchTexts

        # Create sketch text input
        point = adsk.core.Point3D.create(0.0, 0.0, 0.0)
        # formattedText, height, position

        sketchTextInput = sketchTexts.createInput("123.", 0.75, point)
        # Set sketch text style
        sketchTextInput.textStyle = adsk.fusion.TextStyles.TextStyleBold
        sketchTextInput.angle = 0
        sketchTextInput.fontName = "OCR A Extended"

        sketchTexts.add(sketchTextInput)

        # prof = sketch.profiles.item(0)
        prof = sketch.sketchTexts.item(0)

        # extrude
        extrudes = new_comp.features.extrudeFeatures
        extrude_input = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

        ddef_up = adsk.core.ValueInput.createByReal(0.5)
        ddef_down = adsk.core.ValueInput.createByReal(0.2)

        distance_up = adsk.fusion.DistanceExtentDefinition.create(ddef_up)
        distance_down = adsk.fusion.DistanceExtentDefinition.create(ddef_down)
        extrude_input.setTwoSidesExtent(distance_up, distance_down)

        # Create the extrusion.
        extrudes = new_comp.features.extrudeFeatures
        extrude_input.setTwoSidesExtent(distance_up, distance_down)
        obj = extrudes.add(extrude_input)

        # combineFeatures = new_comp.features.combineFeatures
        # combineFeatureInput = combineFeatures.createInput(cwxz_objs.item(0), text)
        # combineFeatureInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
        # combineFeatureInput.isKeepToolBodies = False
        # combineFeatureInput.isNewComponent = False
        # combineFeatures.add(combineFeatureInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
796 Views
2 Replies
Replies (2)
Message 2 of 3

lionel.courgnaud
Enthusiast
Enthusiast

hello,

 

did you finally find your answer ? I have the same question about text orientation. 

 

thanks

 

0 Likes
Message 3 of 3

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

On the XZ plane the "front" face is toward Y+.  So when you write text on it the "rigth" is toward X+ and "up" becomes Z-.

Having said that, to get the letters in the right positions some changes are need in the code (assuming the letters will be on the right-hand side of the body and extruded 2mm to the front and 5mm to the back):

 

1. swap extrusion directions on the XZ component:

# cwxz_objs = extrude_polygon_up_down(new_comp, poly_xz, xz_plane, 1, 0)
cwxz_objs = extrude_polygon_up_down(new_comp, poly_xz, xz_plane, 0, 1)

2. negate Y coordinates on poligon on plane YZ, so that plane face will be facing toward Y+:

#    poly = [
#        [-b-d-d, -d,  0],
#        [ 0,    d+b,  0],
#        [b+d+d,  -d,  0]
#    ]
    poly = [
        [-b-d-d,   d,  0],
        [ 0,    -d-b,  0],
        [b+d+d,    d,  0]
    ]

3. swap letters's distance extrusions like so:

# ddef_up = adsk.core.ValueInput.createByReal(0.5)
# ddef_down = adsk.core.ValueInput.createByReal(0.2)
ddef_up = adsk.core.ValueInput.createByReal(0.2)
ddef_down = adsk.core.ValueInput.createByReal(0.5)

 

And you'll get it in the right direction:

wtallerdemadera_3-1660489419236.png

 

 

Hope this help you.

 

Regards,

Jorge

0 Likes