Is this code supposed to generate a table in the layout?
If I open the file I don’t see a table…
def openLayoutDoc() @layoutfilename = UI.openpanel("Open Layout File", "c:/", "LAYOUT Files|*.layout||") myarray = @layoutfilename.split('.') UI.messagebox("Not a layout file, please open a layout file and try again") unless myarray.at(-1).to_s.downcase == "layout" end openLayoutDoc() bounds = Geom::Bounds2d.new(1, 1, 4, 4) rows = 4 columns = 4 table = Layout::Table.new(bounds, rows, columns) doc = Layout::Document.open(@layoutfilename.to_s) doc.add_entity(table, doc.layers.first, doc.pages.first) anchor_type = Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT start_point = Geom::Point2d.new(1, 1) text = Layout::FormattedText.new("Hello LayOut", start_point, anchor_type) table[1, 1].data = text
Most likely, no save method is applied after changes to that particular design document. (Otherwise I didn’t check the ccde)
The #save method saves the Layout::Document to a file at the given path.
It was partly the problem. The problem was also that the file was opened.
So I have to test if the file is open and force the user to close it. After that, lay the table and save the document.
You don’t need these…
myarray = @layoutfilename.split('.') ... unless myarray.at(-1).to_s.downcase == "layout"
Just use something like…
msg = 'Not a layout file, please open a layout file and try again.' UI.messagebox(msg) unless File.extname(@layoutfilename) == ".layout"
(Remember to use shorter lines of code for clarity.)