当我尝试通过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;
}
}
复制步骤:
AR:结果文件的扩展名为“ jpg”,而不是“ png”
ER:文件应为“ png”。
PS。如果选择3D视图-> {3D}文件的扩展名为“ png”
请共享complete minimal reproducible case for the development team to analyse。最佳情况下,只需单击一下即可证明问题行为。谢谢!