Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape, CAD, maker project and design.

**First time visiting? Here are some places to start:**

- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

# How do I scale skText in-situ from featurescript?

pmd
Member, Developers Posts:

**20**PRO
Having read all the previous answers to this question and tried various combinations I still cannot work how to scale skText in-situ. The roman numeral clock example was too complex for me to adapt and the other simpler methods do not work for me.

I want to write a function I can call from other FS code to place a small text label on a face at the midpoint of an edge.

Here is current non-working attempt:

https://cad.onshape.com/documents/721f4e2f8e5ff4af15e22b4b/w/cd43c547742fcde4e54191cd/e/220678bf1a811075f41f4ca7

It scales the text ok using scaleUniformly but also ends up moving the origin of the text to the wrong Z value.

Is there a way to scale in X and Y and leave Z alone? I am guessing I need to create a special matrix somehow...

I want to write a function I can call from other FS code to place a small text label on a face at the midpoint of an edge.

Here is current non-working attempt:

https://cad.onshape.com/documents/721f4e2f8e5ff4af15e22b4b/w/cd43c547742fcde4e54191cd/e/220678bf1a811075f41f4ca7

It scales the text ok using scaleUniformly but also ends up moving the origin of the text to the wrong Z value.

Is there a way to scale in X and Y and leave Z alone? I am guessing I need to create a special matrix somehow...

Tagged:

0

## Comments

1,110I think your best bet here is to use the 'transform' feature (the function that the button in the toolbar is tied to) rather than 'opTransform':

https://cad.onshape.com/FsDoc/library.html#transform-Context-Id-map

If you'd rather do it yourself, this is analogous to using the following transform into opTransform:

Transforms are applied right-to-left; see documentation:

https://cad.onshape.com/FsDoc/library.html#Transform

You can think of this as:

20PROOne thing which is confusing is the right-to-left reading of the transform multiplication expressions into English and the fact that order matters a lot. It makes trial and error testing more difficult...

1,110It's definitely tripped me up before too, I usually return to that page of documentation whenever I'm working on Transforms.

As for the mathematical motivation behind this:

An analog of what you're doing when transforming a part is 'moving every point of the part by the transform', so let's just think in terms of one point. It's somewhat standard in linear algebra to represent position vectors (points) as 3x1 column vectors. Transforms are represented by 3x3 matrices†. So, if I want to multiply the position and the matrix, I have to do (matrix * position), because (position * matrix) is not a valid matrix multiplication. Now, if you think of your transform as a series of these multiplications, you'll see that you have to do the operation as follows:

(doThisLast * doThisSecond * doThisFirst * position)

so, the transform you're interested in is:

(doThisLast * doThisSecond * doThisFirst)

Of course, you can happily turn this all on its head by representing the position vector as a row vector, and taking the transpose of the transforms:

(positionAsRow * doThisFirst' * doThisSecond' * doThisThird')

where ' means transpose.

But at some point the math gods decided column vectors are better. Probably because they take up less horizontal space when you're solving equations on a sheet of paper...

† A note of clarification from a coworker: FeatureScript Transforms are actually represented as the combination of a 3x3 matrix and an affine translation:

https://cad.onshape.com/FsDoc/library.html#Transform

but the ordering motivation holds

1,110I made a mistake, we actually have a `scaleUniformly(scale is number, point is Vector)` method. Sorry for making everything more confusing than it needed to be.

https://cad.onshape.com/FsDoc/library.html#scaleUniformly-number-Vector

7PRO"firstCorner" : vector( xPosition, yPosition),

"secondCorner" : vector(xPosition+1*inch, yPosition + textHeight)

Substitute the desired variable or value for xPosition, yPosition, and textHeight. Note that skText always starts from the most negative corner and works its way right (even when the reverse flag is true), and it will automatically scale the width of the text box to match the specified height. You still need to use transform if you want to rotate the text or anything fancy like that.

Example:

var textStringToSketch = "Hello World";

var xPosition = 1*inch;

var yPosition = 3*inch;

var fontHeight = .25 * inch;

1,110Looks like some of us internally, myself included, were confused about the correct way to do this. We'll be sure to document it for the upcoming release. Thanks for the input.