How to change the table cell height

Hi there,

I am working on an extension that will generate a layout for a 3D model. I want to create a table with some data on the layout page and sometimes the data(string) might be big and not fit in the table cell. For one of the columns, the table cell height gets adjusted(without me doing anything) but for another column, the table cell height is not adjusting. I looked for any API/Style but couldn’t find anything to achieve this behavior.

This is how I am creating the table

    def self.create_table(layout_page, data, doc)
      font_size = LAYOUT_CONFIG[:font_size]

      rows = data.length + 1
      columns = 2

      # Define the table properties
      table_width = 80.mm
      table_height = (10 * rows).mm

      bounds = Geom::Bounds2d.new(0.08, 0.08, table_width, table_height)

      table = Layout::Table.new(bounds, rows, columns)
      doc.add_entity(table, template_layer(doc), layout_page)

      products_name_header_text = Layout::FormattedText.new("Name", Geom::Point2d.new(0, 0), Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)
      style = products_name_header_text.style
      style.font_size = font_size
      style.text_bold = true
      products_name_header_text.style = style
      table[0, 0].data = products_name_header_text

      h_a_erp_header_text = Layout::FormattedText.new("H/A ERP", Geom::Point2d.new(0, 0), Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)
      style = h_a_erp_header_text.style
      style.font_size = font_size
      style.text_bold = true
      h_a_erp_header_text.style = style
      table[0, 1].data = h_a_erp_header_text

      data.each_with_index do |product, index|
        product_name_text = Layout::FormattedText.new(product[:name].to_s, Geom::Point2d.new(0, 0), Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)
        style = product_name_text.style
        style.font_size = font_size
        product_name_text.style = style
        table[index + 1, 0].data = product_name_text

        erp_codes = product[:h_a_erp].map { |p| p[:code] }.compact
        erp_codes_string = erp_codes.join(", \n").to_s

        if (!erp_codes_string.empty?)
          product_h_a_erp_text = Layout::FormattedText.new(erp_codes_string, Geom::Point2d.new(0, 0), Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)
          style = product_h_a_erp_text.style
          style.font_size = font_size
          product_h_a_erp_text.style = style
          table[index + 1, 1].data = product_h_a_erp_text
        end
      end
    end

And here is the layout page that is being generated with the above code. Note the first column is adjusting but not the second column.
test.layout (3.7 MB)

Q: Is there any way to adjust the table cell height according to the sting being passed to that cell?

P.S: I know I can just open the layout file and click on the red arrow and expand the table cell height but I am looking for a way to do this programmatically if it is possible.

It looks as though you need to set the height upon the row as a whole.

2 Likes