public override Value Evaluate(FSharpList <Value> args) { int ms = (int)((Value.Number)args[0]).Item; Thread.Sleep(ms); return(Value.NewDummy("pause")); }
public override Value Evaluate(FSharpList <Value> args) { var view = (View)((Value.Container)args[0]).Item; var fullPath = ((Value.String)args[1]).Item; string pathName = fullPath; string extension = null; var fileType = ImageFileType.PNG; if (Path.HasExtension(fullPath)) { extension = Path.GetExtension(fullPath).ToLower(); switch (extension) { case ".jpg": fileType = ImageFileType.JPEGLossless; break; case ".png": fileType = ImageFileType.PNG; break; case ".bmp": fileType = ImageFileType.BMP; break; case ".tga": fileType = ImageFileType.TARGA; break; case ".tif": fileType = ImageFileType.TIFF; break; } pathName = Path.Combine( Path.GetDirectoryName(fullPath), Path.GetFileNameWithoutExtension(fullPath)); } var options = new ImageExportOptions { ExportRange = ExportRange.SetOfViews, FilePath = pathName, HLRandWFViewsFileType = fileType, ImageResolution = ImageResolution.DPI_72, ZoomType = ZoomFitType.Zoom, ShadowViewsFileType = fileType }; options.SetViewsAndSheets(new List <ElementId> { view.Id }); dynRevitSettings.Doc.Document.ExportImage(options); //revit only has a method to save image to disk. //hack - rename saved file to match specified file name //File.Move(string.Format("{0} - {1} - {2}.png", pathName, view.ViewType, view.ViewName), pathName + ".png"); //hack - make sure to change the read image below if other file types are supported //Image image = Image.FromFile(pathName + (extension ?? ".png")); return(Value.NewDummy("wrote image file")); //NewContainer(image); }
protected override Expression compileBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { var arg = arguments.First().Value.compile( symbols, letEntries, initializedIds, conditionalIds); //idle :: (() -> A) -> A //Evaluates the given function in the Revit Idle thread. var idle = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( args => { var f = (args[0] as Value.Function).Item; if (dynSettings.Controller.DynamoViewModel.RunInDebug) { return(f.Invoke(FSharpList <Value> .Empty)); } return(IdlePromise <Value> .ExecuteOnIdle( () => f.Invoke(FSharpList <Value> .Empty))); })); //startTransaction :: () -> () //Starts a Dynamo Transaction. var startTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (_node.Controller.RunCancelled) { throw new CancelEvaluationException(false); } if (!dynSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.InIdleThread = true; dynRevitSettings.Controller.InitTransaction(); } return(Value.NewDummy("started transaction")); })); //endTransaction :: () -> () //Ends a Dynamo Transaction. var endTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (!dynRevitSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.EndTransaction(); dynRevitSettings.Controller.InIdleThread = false; dynSettings.Controller.DynamoViewModel.OnRequestLayoutUpdate(this, EventArgs.Empty); _node.ValidateConnections(); } else { _node.setDirty(false); } return(Value.NewDummy("ended transaction")); })); /* (define (idleArg) * (startTransaction) * (let ((a <arg>)) * (endTransaction) * a)) */ var idleArg = Expression.NewFun( FSharpList <FScheme.Parameter> .Empty, Expression.NewBegin( Utils.SequenceToFSharpList(new List <Expression> { Expression.NewList_E( Utils.SequenceToFSharpList( new List <Expression> { startTransaction })), Expression.NewLet( Utils.SequenceToFSharpList( new List <string> { "__result" }), Utils.SequenceToFSharpList( new List <Expression> { arg }), Expression.NewBegin( Utils.SequenceToFSharpList( new List <Expression> { Expression.NewList_E( Utils.SequenceToFSharpList( new List <Expression> { endTransaction })), Expression.NewId("__result") }))) }))); // (idle idleArg) return(Expression.NewList_E( Utils.SequenceToFSharpList(new List <Expression> { idle, idleArg }))); }