Display the value of a dynamic component in 2D text

Thanks for the fact that the text appears depending on the size of the object, this is already the right way, I will try to understand more in your file.

1 Like

Yes, absolutely right, you just need to figure out how to do it. I think with some kind of formula you need to display values from attributes in a 2D external view

There is another possibility that I became aware of while using Dave Penny’s Flat Text plugin (from Extension Warehouse) to draw flat text for me inside my own plugin (not yet published).

That has a Ruby API which you might be able to combine into your DC. It’s available only in the Pro version of Flat Text. It isn’t expensive (~$15) and there’s a free trial for a week or two.

I’m not a skilled Ruby programmer, and have only a limited experience of creating DCs.

But I think I have read that it is possible to combine Ruby and a DC, which after all is only itself based on a Ruby extension.

But it’s beyond my experience to know how to do it.

Yes, I just talked with Dave Penny, he suggested me to write to the forum.

Dezmo, thanks to your file, my colleague and I used the hide / unhide system and, as a result, implemented one field with writing letters and symbols, and the second automatically calculates the area of a rectangle.
When scaling an object, all numbers do not change their dimensions and place. Only 2 points did not win: “0” is not displayed, the formula considers that it is not. Replaced with “O”. And the sign “-” also does not want to be determined - it was replaced by “_”.

Please post any issues you think are bugs or those that need improvement to topic:

it is not an error but rather the wrong formula to use,

value(0)=0, value(.)=0, value(-}=0, value(a)=0…

use the find() instead, note you add the value times by the number of digits to search to the end to avoid the error then compare the result with the string length.
The example is for 0, 1, 2, and point, the 0 is a special example whereas the others can be copied. made unique and changed to make the other digits, a task that can be done by you, changing the header of the new component to an appropriate name, and inserting the digital value in the “lookup” attribute.
find and copy.skp (92.2 KB)

1 Like

You could alter dezmo concept to allow for use of decimal points and other symbols, letters by removing the “value” function, then for cases that naturally evaluate like the decimal point, use the find method.
Kind of make use of both concepts

Capture

label with dot.skp (630.4 KB)

1 Like

Super, thanks for the tip, find () is really more suitable for this task. See what I got thanks to you!)
PS: The only thing is that I can’t enter the number “1.” when dot is at the end it is not shown, but “1.1” works all 3 characters. You also can’t start with the number “01”

The problem is in passing the input as text and stopping it from being evaluated, the concatenate formula to add the strings helps, so if we put a wrapper around the input

concatenate(“(”,input,“)”) then allow for the bracket in our results?

if using “same as the label with dot” version of dezmo solution (which is in essence the solution you are using then please give him the solution tick)

first check that text is the input:-

Now use the Bracket delimiters or some of your own to protect the text

Then you need to change the results to suit, or you may even like the wrapper delimiters to be part of your project

Cheers and good to see the progress you are making

3 Likes

Thank you, this option with brackets () gives the correct display of the entered text. But there is a minus, these brackets appeared in the text field, but they are not visible (since I have not drawn this element). In general, I can solve the alignment problem by moving the position itself, but not very technically, because if there were parentheses, they would be displayed.

I don’t mind, because my good part of knowledge is based on your “old” posts in the fórum… :wink:

2 Likes

You can decrease the number of digits copied by 2, then limit the scope using MID again

neater:

I do not know how you do it and where did you get such good knowledge, but it worked! Brilliant, thanks!))

Hoping for some clarification- my application is much simpler- I just want to enter a value in the Options dialog and have it change the 3D text. I’ve spent quite a bit of time disassembling and looking at the dezmo example, and I can see where the value is stored, and I can manipulate it in the ‘Attributes’ dialog, but I can’t see how the value is ‘connected’ to the 3D text- how the value of the 3D text is set by a value in the attributes of the DC. From other examples, it seems 3D text is just geometry, so it seems this shouldn’t be possible, and yet the 3D text is changing.

Thanks in advance for any guidance or clarification.

It (dezmo’s example) doesn’t actually change a 3D text field.

It uses the hidden DC attribute to hide all characters except the character (or number) for that particular digit. So each digit is a copy subcomponent which has within it as children, ALL of the possible characters that might need to be displayed for each digit (or “place”) in the text. This would be numbers and decimal point, perhaps a minus sign, etc. If you wanted letters then the digit/place subcomponent would need 26 or so more character subcomponents.

So the formula determines for each “place” which one of the numerous character subcomponents will be the visible one and the rest will be set hidden.

The draw back is that 3D text (even that which appears as flat 2D text) is intricate geometry which might bloat the model using this approach where most character subcomponent instances are part of the entities but hidden.


I would myself prefer an observer plugin that removes and replaces text when the DC attribute changes.

This would likely mean that each DC instance that needed unique text labels would require a unique component definition.

Probably not a drawback as the copy feature of DCs also creates unique definitions having unique entities collections.

1 Like

Thanks very much for the explanation Dan! I was close to understanding, I just didn’t notice that the numbers are all stacked, but only one is visible at a time.

You wrote:
“I would myself prefer an observer plugin that removes and replaces text when the DC attribute changes.”

I was wondering the same thing- is there a way to automate the generation of 3D text in code? Your statement seems to imply that you don’t know of any such plugin at this time- is that correct?

Since I’m a newbie, I don’t want to criticize, but the way text is treated seems very limited- in my experience with AutoCAD, attaching text to an object was very simple. And now that I’m having trouble with it, I can see that it’s absolutely essential for me.

As you inferred, my application will required every instance to be unique, which presents another learning challenge- can a new instance of a DC be created as unique automatically?

So I think I can make this method work- I may have to remove alpha characters and encode everything in 0-9 digits, but I will have at least dozens of these DC’s in a drawing, so the processor load may well become untenable.

Yes. Several extension do this.

One is TT’s 3D Text Editor. (The extension actually changes the value of a text attribute in a dictionary belonging to the extension attached to a group object. The 3D text within the group is replaced and regenerated via code using the new attribute value.)
The code is not encrypted.

That specifically gets the text value from a DC dictionary attribute and attaches an observer to watch such a DC component for a particular attribute change … no, I do not yet know of such an extension.

If it is the 2nd or higher instance, then the DC extension code will do the uniquifying automatically.

If you meant via Ruby code, there are API methods to force the uniquifying (which clones the instance’s definition in preparation for changing the definition’s entities collection.)

Yes, well I and many others came from ACAD experience also. However, SketchUp is not CAD, was never designed to be, and never will attempt to be. (It has been billed in the past as “the UNCAD”.)

SketchUp was designed to really be the modelspace only. (It did add rudimentary dimensioning and callouts [referred to as Text objects in the API and GUI,] for simple hobby docs that did not use the Pro edition.)
Paperspace annotation and dimensioning is really meant to be done in the companion LayOut application which comes only with the Pro editions. LayOut has autotext label objects (callouts) which natively can read and reflect changes in Dynamic Attributes of modelspace components. (This does not need any extension. It is a native feature. However authoring Dynamic Components in SketchUp is also a Pro only feature.)

Anyway, back in SketchUp the callouts (actual Text objects with or without leaders) have limited control via the Ruby API. Ie, currently no font size and style control. (The newer “file” C API does have font control but there is yet no parity for the “live” Ruby API.)
We usually get around this (in coding) by creating component files with a variety of settings and loading the file with the desired traits as a component, inserting instances, then exploding the instance and manipulating the object.

The examples you see discussed above are not Text objects per se, … they are groups or instances containing 3D geometry that represents text. Ie, the difference between using the 3D Text tool and the Text (callout) tool.

The benefits of using Text callouts instead are the avoidance of geometric bloat and that the value of the text can be changed without having to destroy and regenerate the objects. (They have a setter method to set or change their value.)

Hi guys. I am glad that the topic is still alive, but it also becomes sad that the problem has not been fully resolved for Sketchup.
Look what happened in the end for me, I just wrote in half of the alphabet (I don’t need to work anymore), everything works. If you sit for a while to suffer, then you can still make non-capital letters.
By the way, the model doesn’t get heavier from hidden letters.
It would be really cool if someone write a good plugin for text and dynamic data interaction.2d_text

1 Like