create text area and align text - do with API like in UI

create text area and align text - do with API like in UI

info83PHN
Advocate Advocate
633 Views
2 Replies
Message 1 of 3

create text area and align text - do with API like in UI

info83PHN
Advocate
Advocate

When working in the UI, I can add text to a Sketch, by dragging the text area.

Text in the text area can then be aligned center ( horizontally ) and aligned 'middle' ( vertically ).

This is very useful to center the text content on another item or rectangle.

 

In the API, I can create a box, create a circle, but the text seems to only have a starting point ( the bottom left point of the auto-sizing text area, depending on it's text content )

Is there a way to replicate the UI method of creating a specific size text box ?

 

# draw box1
        uPointA = adsk.core.Point3D.create(uNextBoxX, uNextBoxY, 0)
        uPointB = adsk.core.Point3D.create(uNextBoxX+uBoxW, uNextBoxY-uBoxH, 0)
        sketch.sketchCurves.sketchLines.addTwoPointRectangle(uPointA, uPointB)

# draw circle1
        circles = sketch.sketchCurves.sketchCircles
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(uNextBoxX+uCircleX, uNextBoxY-uCircleY, 0), uCircleDiam*0.5)

# Create sketch text input starting point
        uFont = "Segoe UI Semilight"
        point = adsk.core.Point3D.create(uNextBoxX, uNextBoxY, 0)
        sketchTexts = sketch.sketchTexts
        sketchTextInput = sketchTexts.createInput("SAMPLE CODE", uTxHeight, point)
        sketchTextInput.fontName = uFont
        sketchText = sketchTexts.add(sketchTextInput)
0 Likes
Accepted solutions (1)
634 Views
2 Replies
Replies (2)
Message 2 of 3

tykapl.breuil
Advocate
Advocate
Accepted solution

You can use the setAsMultiline method as seen in the text sample :

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-a611130a-a957-11e5-ac5a-f8b156d7cd97

Since you define both diagonal points, you have access to the center point and can use that to position your sketch. And, using this method, you can define the alignements.

Message 3 of 3

info83PHN
Advocate
Advocate

Thanks a LOT - this is EXACTLY what I was looking for.