在Netlogo中使用导出视图时编辑文件名 [英] Editing file name when using export-view in Netlogo

查看:161
本文介绍了在Netlogo中使用导出视图时编辑文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用export-view保存我的模型的图像.我在界面上做了一个按钮,用于从Netlogo导出图像(JPG,PNG或PDF).

I want to use export-view to save an image of my model. I have made a button in the interface to export image (JPG, PNG, or PDF) from the Netlogo.

这是我当前在导出视图按钮中的代码

this is my current code in the export-view button

file-open user-new-file
export-view (word "view1.jpg")
set view-number view-number + 1

当前,文件打开命令有助于在保存之前显示弹出式输入窗口.运行时错误为"FILE-OPEN预期输入为字符串,但改为TRUE/FALSE false".我仍然可以保存文件,但是此弹出窗口有时会出现

Currently, file-open command helps in showing a pop-up input window before saving. There is a runtime error of "FILE-OPEN expected input to be a string but got the TRUE/FALSE false instead". I can still save the file but this pop's up from time to time

首先尝试我可以连续保存文件.现在,它每次仅保存一个名为view1的文件.新代码有什么问题吗?

At first try the I can save the files successively. Now, it only saves one file named view1 everytime. Is there something wrong with new code?

推荐答案

看看NetLogo词典中的user-new-file原语.这样就可以获取用户输入,然后可以使用word原语以与现在相同的方式进行保存.

Have a look at the user-new-file primitive in the NetLogo dictionary. That allows you to get the user input and then you can use the word primitive to save in the same way that you are doing it now.

完整代码的简称为:

to testme1
  export-view user-new-file
end

要全面了解正在发生的事情,请使用更长的版本:

To get a full idea of what's going on, here's a longer version:

to testme2
  let fn user-new-file
  print fn
  set fn word fn ".png"
  print fn
  if file-exists? fn [file-delete fn]
  file-open fn
  export-view fn
  file-close
end

所以实际发生的是user-new-file返回用户输入的字符串.您可以直接在export-view中使用该字符串,也可以对其进行一些操作然后再使用.我尚不清楚您为什么会收到该特定错误,但是您拥有的代码正在创建/打开一个名称与尝试导出的名称不同的文件.

So what actually happens is the user-new-file returns a string for whatever the user enters. You can use that string directly with the export-view, or you can manipulate it a bit and then use it. I'm not completely clear why you are getting that particular error, but the code you have is creating/opening a file with a different name than the name you try and export to.

例如,在我的testme2代码中,我假设用户未键入此扩展名并附加了'png'扩展名.在实际的应用程序中,您可以查看最后3个字符并仅在需要时添加扩展名.我的较长代码还会删除该名称的任何现有文件-我认为png视图不需要此,因为我认为NetLogo会简单地覆盖,但是导出到csv会在末尾添加行.

For example, in my testme2 code, I appended the 'png' extension on the assumption that the user did not type this. In a real application, you could look at the last 3 characters and add the extension only if required for example. My longer code also deletes any existing file of that name - I don't think this is required for png views as I think NetLogo simply overwrites, but exporting to csv would add lines at the end.

这篇关于在Netlogo中使用导出视图时编辑文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆