【问题标题】:Document ExportImage command creates image file with different extensionsDocument ExportImage 命令创建具有不同扩展名的图像文件
【发布时间】:2020-05-11 03:02:43
【问题描述】:

当我尝试通过 API 从 Revit 中的视图创建图像时,出现了一种奇怪的行为。由于某种原因,目标文件有时是“png”,有时是“jpg”(对于不同的 View3D)。作为一种解决方法,我检查文件是否存在并替换扩展名,但我认为这不是一个好的解决方案。这个想法来自

https://thebuildingcoder.typepad.com/blog/2013/08/setting-a-default-3d-view-orientation.html

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    UIDocument uidoc = commandData.Application.ActiveUIDocument;
    Document doc = uidoc.Document;

    var tempFileName = Path.ChangeExtension(Path.GetRandomFileName(), "png");

    string tempImageFile;

    try
    {
        tempImageFile = Path.Combine(Path.GetTempPath(), tempFileName);
    }
    catch (IOException)
    {
        return Result.Failed;
    }

    var opt = new ImageExportOptions
    {
        ZoomType = ZoomFitType.Zoom,
        FilePath = tempImageFile,
        FitDirection = FitDirectionType.Horizontal,
        HLRandWFViewsFileType = ImageFileType.PNG,
        ImageResolution = ImageResolution.DPI_300,
    };

    doc.ExportImage(opt);
Debug.WriteLine(File.Exists(tempImageFile) ? "File exists." : "File does not exist.");

    return Result.Succeeded;

}

}

重现步骤:

  1. 创建外部命令(实现 IExternalCommand 接口)
  2. 使用上面提供的 Execute 方法实现
  3. 打开 Revit 2020 示例模型 (rac_basic_sample_project.rvt)
  4. 选择 3D 视图->选择透视图(或厨房)
  5. 执行外部命令
  6. 检查 doc.ExportImage(opt) 命令的结果

AR:结果文件具有“jpg”扩展名而不是“png”

ER:文件应该是“png”。

PS。如果您选择 3D Views->{3D} 文件扩展名为“png”

Look at screens

【问题讨论】:

  • 实际生成的图片文件格式是什么?谁说文件格式必须是其中一种?如果两个视图生成不同的文件格式,并且扩展名与生成的文件格式匹配,那么问题出在哪里?文件扩展名是否与生成的文件格式匹配?
  • Jeremy,ImageExportOptions 的 HLRandWFViewsFileType = ImageFileType.PNG 参数似乎被忽略了。因此,在导出之前无法知道带有扩展名的结果文件名。
  • 这并不能回答我的任何问题。你能回复他们吗?
  • 对不起杰里米,让我来回答你的问题。我检查了文件格式,发现它在一种情况下是 jpeg 在另一个 png 中,它对应于文件扩展名。我上面描述的唯一问题,谢谢。
  • 所以唯一的问题是您想事先知道您将收到什么文件扩展名。对吗?

标签: revit-api revit


【解决方案1】:

请分享complete minimal reproducible case for the development team to analyse。理想情况下,它应该只需单击一下即可演示有问题的行为。谢谢!

【讨论】:

  • 杰里米,我添加了重现的步骤。请让我知道是否需要任何其他信息。
  • 谢谢,我去看看!
猜你喜欢
  • 2018-12-12
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 2015-05-31
  • 2019-11-05
  • 2014-07-01
  • 1970-01-01
  • 2015-11-15
相关资源
最近更新 更多