Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

handle text orientation ?

9 REPLIES 9
Reply
Message 1 of 10
lionel.courgnaud
375 Views, 9 Replies

handle text orientation ?

Hello,

 

is there a way to handle text orientation when I create a new text in a sketch ?

My script draws a sketch curve and uses it as path, but sometimes the text is under the line, sometimes it’s on the line. Sometime the text is left to right, sometime right to left. 

 

I missed something but I can’t find it 🙂

 

any help ?

thanks

9 REPLIES 9
Message 2 of 10

Hi @lionel.courgnaud ,

 

When you say sometimes, it is that you get different results with the exact same script?

Or it is that you get different results when you use different sketch, sketch planes o sketch lines?

 

Could you share the script you are using?

 

Regards,

Jorge

Message 3 of 10
sharas_s
in reply to: lionel.courgnaud

I had similar similar issue when I had to add text to some sketches.

Text orientation by default depends on line/curve start point and end point. If line starts from left and ends on the right side (X_start < X_end), text will appear above the line. 

What I did to fix this problem, after adding text, I extract center point of the text (using text bounding box coordinates) and check if it is above the line or not. If not, do vertical and/or horizontal flipping on the text. 

Message 4 of 10

Hello,

 

I have different results with the same script but different sketches.

I think that all is about sketch orientation, but I can't find the right way to fix it.

I noticed that if I draw the paths (on the same sketch) with different start/end points, the text is always oriented in the same way.

 

Capture d’écran 2022-08-15 à 10.56.50.png

 

My script creates planes with many different orientations. Based on sketches drew earlier.

     constructLib.add(design.findAttributes(attacheKey,'c1')[0].parent)
        constructLib.add(design.findAttributes(attacheKey,'c2')[0].parent)
        constructLib.add(design.findAttributes(attacheKey,'c4')[0].parent)
        constructLib.add(design.findAttributes(attacheKey,'c3')[0].parent)
        
        #plan
        planeInput : adsk.fusion.ConstructionPlaneInput = planes.createInput()
        planeInput.setByTwoEdges(constructLib.item(0), constructLib.item(3))
        constructPlan = planes.add(planeInput)

 #scketch
        newSketch : adsk.fusion.Sketch = rootComp.sketches.add(constructPlan)

 

the base sketchthe base sketchthe texts I'm trying to add. "2" is in the right orientation, "9." is inverted.the texts I'm trying to add. "2" is in the right orientation, "9." is inverted.

 

 

this is the text scripts (I think it's a bit complicated to read because the project as many dependencies)

        #################### FIRST TEXT

        timelineendId+=1

        StartPt : adsk.fusion.SketchPoint = shared_modules.FarestPoint(newSketch, PtProj1, LineProj0.startSketchPoint, LineProj0.endSketchPoint)                                       
        EndPt : adsk.fusion.SketchPoint = shared_modules.FarestPoint(newSketch, PtProj1, LineProj3.startSketchPoint, LineProj3.endSketchPoint) 

        #text           
        lineCroix1 = shared_modules.LineFrom2SkPoint(newSketch, PtProj1.geometry, StartPt.geometry, True)
        newSketch.geometricConstraints.addMidPoint(newSketch.sketchPoints.add(adsk.core.Point3D.create(0,0,0)),lineCroix1)

        fullname = shared_modules.PieceNum(str(p1))

        # #sketch Text
        texts = newSketch.sketchTexts
        textInput = texts.createInput2(fullname, textSize)
        textInput.setAsAlongPath(lineCroix1, False, adsk.core.HorizontalAlignments.CenterHorizontalAlignment, 0)
        textInput.isHorizontalFlip = False
        textInput.isVerticalFlip = False
        textInput.fontName = 'Arial'
        myText = texts.add(textInput)

        ####################### NEXT TEXT

        #text           
        lineCroix1 = shared_modules.LineFrom2SkPoint(newSketch, PtProj1.geometry, EndPt.geometry, True)
        newSketch.geometricConstraints.addMidPoint(newSketch.sketchPoints.add(adsk.core.Point3D.create(0,0,0)),lineCroix1)

        fullname = shared_modules.PieceNum(str(p2))

        # #sketch Text
        texts = newSketch.sketchTexts
        textInput = texts.createInput2(fullname, textSize)
        textInput.setAsAlongPath(lineCroix1, False, adsk.core.HorizontalAlignments.CenterHorizontalAlignment, 0)
        textInput.isHorizontalFlip = False
        textInput.isVerticalFlip = False
        textInput.fontName = 'Arial'
        myText = texts.add(textInput)

 

If I could predict the different orientations cases, I'll modify the text options, but I don't know how I can do this predictions 🙂

 

Thanks for your help !

 

 

Message 5 of 10
lionel.courgnaud
in reply to: sharas_s

Hello,

 

I tried with different paths (made by hand), and the result is not as conclusive as that.

 

same text options, different paths.same text options, different paths.

 

Message 6 of 10

Hi All,

 

The text orientation depends on the sketch orientation, not on the start/end points of the line/path.

You can check the sketch orientation with sketch.xDirection and sketch.yDirection attributes (please note that "x" and "y" directions mean the 2 perpendicular vectors used to build the sketch plane, and not the actual x and y axes of the model)

 

I'll try to explain it with an example. I'm attaching a model with 6 faces.  Each face has 4 lines, 2 parallels to the axis and 2 diagonals.  Then I use every line to write the "abc" text (all of them with the same definition: centered, above the path, not flips).

 

Then I ran this script to get the x and y directions of every sketch:

def getSketchsOrientation():
    for sk in root.sketches:
        app.log(f'{sk.name} {sk.xDirection.asArray()} {sk.yDirection.asArray()}')

The result is the following:

xyInternal (-1.0, 0.0, 0.0) (0.0, -1.0, 0.0)

xzInternal (-1.0, 0.0, 0.0) (0.0, 0.0, 1.0)

yzInternal (0.0, 1.0, 0.0) (0.0, 0.0, 1.0)

xyExternal (1.0, 0.0, 0.0) (0.0, -1.0, 0.0)

yzExternal (0.0, -1.0, 0.0) (0.0, 0.0, 1.0)

xzExternal (1.0, 0.0, 0.0) (0.0, 0.0, 1.0)

 

The first coordinate defines the orientation through the "right-hand" side and the second to the "up" orientation.

As an example for yzExternal sketch: the right-hand-side is towards Y- (0.0, -1.0, 0.0) and up is towards Z+ (0.0, 0.0, 1.0). {these are the real X, Y, Z design coordinates}

So, then, you can check the texts orientation in the model for yzExternal sketch:

wtallerdemadera_0-1660581261372.png

 

You can see that for the lines which start's and end's point have a difference in real-Y the text is written left to right first (towards Y-) and the up or down following the path; in the case of the vertical lines, whose real-Y coordinate is the same, the text is written vertical towars Z+. (use the help of the viewCube on right-top corner to confirm the orientation; on it the line color axis are drawn from center point towards the positive dimension)

 

I checked all texts in the 6 sketch planes in the model, and all texts are consistent in the orientation.

 

@lionel.courgnaud : could you check this with the sketch in you model?

 

Hope this help everyone to understand it better.

 

Regards,

Jorge

Message 7 of 10

Hey,

 

I'm back 🙂 Thanks for all the details. I'm going to try all this.

I'll let you know.

 

 

Message 8 of 10

Hello,

 

I tried to understand, but obviously I haven't succeeded yet.

What does xDirection and yDirection mean in the model/sketch context ?

When I print the x/yDirection of my sketches I have some values as :

sketch name : Sketch Text_009-002

xDirection (0.1453744695660143,-0.9893767045965859,0.0)

yDirection (-0.5404983350256396,-0.07941834327674484,0.8375883694188266)

 

I don't know how to use this data in my code. I think I have to track negative values to flip or not my text.

Any clue for me ? 🙂

 

thanks a lot

Message 9 of 10

Hi @lionel.courgnaud ,

 

Every sketch is defined to be located on the XYZ space as a flat plane.  Two components are used to identified its placement.

1) Position: which you can, lets say, move +1 on the X axis, -2 on the Y axis and 0 on the Z axis.  This component is stored in sketck.origen attribute.

2) Orientation: it means you can rotate the plane in any direction of the X, Y or Z axis or a combination of them.  The way to represent this orientation is using two vectors than are NOT parallel to each other.  This two vectors are stored in sketch.xDirection and sketch.yDirection.

The Z orientation is not included as an sketch attribute, since it is always perpendicular to xDirection and yDirection; you can calculate it with xDirection.crossProduct(yDirection) (Vector3D reference).

 

Note: this is a little bit about linear algebra, which you can google it.

Hope this is clear now regarding what xDirection and yDirection mean.

 

Now lets use the information you send to try to clarify better what they mean:

a) Draw a line from (0,0,0) on xDirection (point to (0.1453744695660143,-0.9893767045965859,0.0))

b) Draw a second line from (0.0.0) on yDirection (point to (-0.5404983350256396,-0.07941834327674484,0.8375883694188266))

c) Define a plane using the above lines, with the command Construct > Plane Through Two Edges.  You will get a plane which is parallel to the plane in your model, like so:

wtallerdemadera_0-1662320144243.png

d) Then create a sketch on that plane and draw a triangle, and draw a text on each line of it.

You will get something like this:

wtallerdemadera_1-1662320425302.png

 

Since line a) if pointing meanly towards -Y and than line b) is pointing meanly towards +Z you get the texts orientations as shown in the above image.

That "main" magnitude (yellow highlighted) of each vector (including its sign) defines the text direction.

 

Until here, I tried to explain how the text orientation is defined by Fusion360.

 

To apply this to your diagram, it will depends where you look from to your model in order to read the text in the correct orientation.  If you look from any place located in the +Z direction you will read it correctly.  Otherwise it will be flipped vertical and/or horizontal, and then you need to flip it in your sketch to get it in the right direction.

 

It is quite hard to explain this way, but I hope this could help a little bit.

 

Regards,
Jorge

Message 10 of 10

wow ! thanks for your time.

I'll check all this asap.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report