rtches
March 11, 2023, 7:42am
1
Is this code supposed to generate a table in 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
dezmo
March 11, 2023, 8:40am
2
Most likely because there is no save method applied after the changes on that particular Layout document. (Otherwise I did not checked the ccde)
The #save method saves the Layout::Document to a file at the given path.
rtches
March 11, 2023, 12:04pm
3
Thanks @dezmo .
It was partially the problem. The problem was also that the file was opened.
So I have to test if file is opened and force user to close it. After that, place 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"
(Reminder use shorter code lines for clarity.)
1 Like