How to get model or project name in sketchup api



I’m new in sketchup, I want to export my model using Sketchup api, and I want to export it with the project name. How I can do that?
I’ve searched and found a solution like this ,

      modelPath = Sketchup.active_model.path
      filename = File.basename(modelPath, '.*')
      outpath = File.join(Constants::OBJ_EXPORT_DIRECTORY_PATH, filename+'.obj')

but the problem in this case is if the file is not saved yet Sketchup.active_model.path will return null, so I have to think something else.


You can make your code revert to “Untitled” if the file isn’t saved. You could also force the user to save prior to exporting.


Thanks a lot , is there a concept like project name in Sketchup ?
For example in Revit there is a Document.Title which always exists .


There is a field for name in Model Info but I can’t remember ever seen it used. Even for saved files it’s usually just an empty string. I’d use file name and fall back on “Untitled” when it can’t be used.


It is automatically filled in when you ‘Save As…’ a component, so the component library should be filled with it…


I’ve never thought of how this field must correspond to the component name field. That’s good to know!