The width of dynamic component is not identical with LenX in the dynamic attributes

I set the Lenx to 42.932cm in dynamic attributes with ruby, but the actual length is 67.2981cm. Does anyone know what happened to this?

You can open Sketchup and import the skp file of the attachment to test it.

width_test.skp (13.3 KB)

the hongxuan_stub_cube has no lenz, rather it’s been forced to have a value, Forced values can create scaling issues,

deleting this value will fix the scale

this is the default values of the “cube” which should be a square

1 Like

Thanks, after I deleted the attribute, the outer component worked correctly.

But I wonder why the inner cube will infect the outer component. And even if I use a cube( x x instead of a square, and restrain the width, height and depth to by DC, the outer component still has the same problem. And I really need to place this constrained cube in the component, do I have another way to get it to work?

The square is a DC that can be used as a material swatch, if the size is made to retain a constant value, or form some meaningless operation it forces the parent to become unique, another definition, this in turn rescale any attached material, as per @TIG observations and probably the first user of this method, I don’t see the need for a cube

If you extruded (push pull) the square into a cube then bind its lenz, then it should not be a scaling issue

The example you posted was a 2D square given a lenZ value, a third dimension which it did not have.
cube instead of a square.skp (64.2 KB)

1 Like

Could you help to check the newer component? This component contains a cube, which is extruded (push pull) the square into a cube then bind its lenz, but the outer component still has scale problem.
width_test2.skp (9.8 KB)

Also, I have another component, which contains a square with width and height but zero depth. This square has constraints of width, height and depth to, but for this outer component, it has no scaling problem.
width_test4.skp (9.0 KB)

width_test2, the cube is a square, with its position outside the parent

if you delete the lenZ formula. you see the greyed original value of 0

this seems a hard one to fix, probably due to the copies

I need the original parent(s) as well, can private message to me in this regards if privacy required.

Most likely, use an uncorrupted file, delete this so called cube and insert a new real one in a non-scaled DC

1 Like

I uploaded a skp file that contails two components, one has no scaling issue and the other has the issue. I also give the attributes of the components. Could someone tell the difference between two components and why one of them has the scaling issue?

compare.skp (68.0 KB)

I think it’s the nominal_len bug. This is one of those “Why can’t Trimble fix this!” issues. There is also a _last _len attribute visible with the SketchUp Attribute viewer. I have found that combinations of grouping and scaling can throw off these three different len values in different ways. It seems that deleting the nominal_len attributes fixes this. I feel as though it’s a patch on a patch , or a Monkey patch @DanRathbun? There are a few ruby scripts in the link that can be executed on a selection to fix it by deleting the nominal_len values. Not a great answer but hopefully a work around for you…

1 Like

Thanks. But I’ve tried deleting _lenx_nominal attribute before, no luck :slight_smile:

1 Like

Just to try and get everyone on the same page, killernova created the situation using ruby, which he may wish to share, the DC contains a de-scaler DC to solve the issue with materials, I believe his code actually produces a situation like this

scaler causes problem.skp (18.5 KB)

where by entering and changing the size, a mismatch occurs that is not resolved with nominal values. This is because of the scale DC, an effect where the scale is changed at a rate proportionally to change and the default cannot be removed

rather than change the geometry this way, I believe the solution lies in just changing Lenx of the DC,

I think @DanRathbun, if willing, can resolve this issue with the code

1 Like

I extracted some codes from my codebase, which is how I set the attributes.

class DynamicAttribute
      DICT_NAME = "dynamic_attributes"
      INTERNAL_NAME = "_name"

      def initialize(definition)
        @definition = definition
        # ignore the find method, just to find the definition's instance
        @instance = ComponentHelper.find_original_instance_by_definition(definition)

      def set!(name, value, with_unit: false, in_instance: false)
        original_name = name
        label = "_#{name.downcase}_label"
        @definition.set_attribute(DICT_NAME, label, original_name)
        if value.start_with?("=")
          name = "_#{name.downcase}_formula"
          unit_name = "_#{name.downcase}_formulaunits"

         @definition.set_attribute(DICT_NAME, name, value[1..-1])
         @definition.set_attribute(DICT_NAME, unit_name, DYNAMIC_ATTRIBUTES_UNIT) if with_unit
          if original_name.match?(/^[XYZ]?Copies$/) || value.include?('copy') || in_instance
            @instance.set_attribute(DICT_NAME, name, value[1..-1])
            @instance.set_attribute(DICT_NAME, unit_name,DYNAMIC_ATTRIBUTES_UNIT) if with_unit
         @definition.set_attribute(DICT_NAME, name.downcase, value)
        # redraw will be called in another method.
        # @definition.instances.each do |instance|
        #   $dc_observers.get_latest_class.redraw_with_undo(instance)
        # end
1 Like