Message 1 of 3
Why the text is mirrored and upside down?

Not applicable
12-28-2019
01:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 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()))