@xiongmin
2017-12-03T13:31:50.000000Z
字数 1618
阅读 344
Revit
Animation
Amazing!What a new look!
接下来我们分析一下,动画的每个关键帧肯定是一个事务,而动画就是一连串的事务,我们要做的就是把所以把所有的事物组合起来,而TransactionGroup正好能干这件事!
剩下的就是要考虑怎么在单个事务里面去改变模型状态,我们知道Revit是参数驱动模型,所以我们就可以方便的只需要在事务里面去改变参数然后驱动模型的改变。所以我们可以方便的做出旋转动画,生长动画,当然基础是你的构件是参数化构建!
下面贴出改变透明度,以及旋转动画,以及导出关键帧图片的关键代码
private void AnimateTransparency(List<Element> element, int startPercentage, int endPercentage, int iterations, string directoryPath, View view, Document currentDBDocument)
{
UIDocument uIDocument = new UIDocument(currentDBDocument);
double value = (double)(endPercentage - startPercentage) / ((double)iterations - 1.0);
int num = Convert.ToInt32(value);
using (TransactionGroup transactionGroup = new TransactionGroup(currentDBDocument, "group"))
{
transactionGroup.Start();
using (Transaction transaction = new Transaction(currentDBDocument, "Modify parameter"))
{
int num2 = 0;
while (startPercentage <= endPercentage)
{
transaction.Start();
OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
ElementId elementId = new ElementId(20);
overrideGraphicSettings.SetSurfaceTransparency(startPercentage);
foreach (Element current in element)
{
view.SetElementOverrides(current.Id, overrideGraphicSettings);
}
transaction.Commit();
uIDocument.RefreshActiveView();
ImageExportOptions expr_11E = new ImageExportOptions();
expr_11E.FilePath = directoryPath + num2.ToString();
expr_11E.FitDirection = FitDirectionType.Horizontal;
expr_11E.HLRandWFViewsFileType = ImageFileType.PNG;
expr_11E.ImageResolution = ImageResolution.DPI_600;
expr_11E.ShouldCreateWebSite = false;
ImageExportOptions imageExportOptions = expr_11E;
currentDBDocument.ExportImage(imageExportOptions);
num2++;
startPercentage += num;
}
}
transactionGroup.RollBack();
}
}