If you've initialized it as self.gcode then you'd think that it would be some decoration of that. You could try self.gcode.width.toFixed(2) or self.gcode.model.width.toFixed(2). Perhaps you could attempt to log self.gcode and see what that puts (temporarily) in the octoprint.log which might give you some insight into what you're working with.
You are mixing up frontend and backend here. GCODE viewer is frontend, no logging to octoprint.log, only to the browser's JS console.
model is a variable provided to the method in the gcode viewer view model from the actual gcode viewer through a callback - it's not bound in any way to the view model so you can't access it from other view models. I fear what you are looking to do is currently not possible with basic approaches and you'll have to see if you can query the data directly from the (global) GCODE stuff. GCODE.renderer.debugGetModel might do it, but as you can clearly see on the method name it's not necessarily meant to be used in production.
Why do you desperately need that data from the gcode viewer instead of taking it from the analysis data? What are you trying to achieve? It might be solvable through a different approach than what you currently are trying to do.
Hello,
Thank you for your reply. I am just looking for this value (height) of the model to print.
Can I recover this value from the analysis?
I would like for my project, display in the sidebar the current height of the layer and the total height (ex: 10.2 mm / 12 mm), for the current no problem, I get it with currentheight but I do not know where to find the total height
Yes, if it has run. Which is more likely though than the user having opened the GCODE viewer tab (which is needed in order for it to even load the model).
Take a look at the FilesViewModel which has all files in self.listHelper which in turn is an ItemListHelper. When a new file is selected, your frontend code could use the filename to look up the file's data in the list helper via getItem and if there is analysis data use that. Take a look here for how the frontend uses the list data to render model information in the list view.
As indicated above, there doesn't necessarily have to be analysis data though - analysis is run after an upload but can't run parallel to an ongoing print job, so if the user starts the print right after upload there will be no data.
Alternatively, as I said, look into using the GCODE viewer directly, but keep in mind that it only parses and renders data if the user actually switches to the tab at least once and - if the file is large - also confirms to do so.