public bool Run() { foreach (var step in mSpecification.Steps) { if (mSpecification.Steps.IndexOf(step) >= MaxUnlicensedSteps && !mRoot.IsLicensed) { var msg = string.Format("Only {0} steps in demo mode", MaxUnlicensedSteps); mCallback.Log(LogLevel.Information, msg); return(false); } if (!step.CanRun) { return(false); } try { using (new AutoWaitCursor()) { if (!step.Run()) { return(false); } } } catch (Exception ex) { mCallback.Log(LogLevel.Critical, ex.Message); return(false); } } return(true); }
public override void Write(string value) { mCallback.Log(LogLevel.Information, value); }
private bool DoRun() { var doc = Window.ActiveWindow.Document; var part = doc.MainPart; var desBody = part.Bodies.Single(); var body = desBody.Shape; var bodyCopy = body.Copy(); var origVolume = bodyCopy.Volume; // calculating tight bounding box is *very* expensive and we were getting timeouts, // so just use approx bounding box which is good enough var bbox = bodyCopy.GetBoundingBox(Matrix.Identity); var maxPt = bbox.MaxCorner; var minPt = bbox.MinCorner; var height = maxPt.Z - minPt.Z; var width = maxPt.X - minPt.X; var length = maxPt.Y - minPt.Y; var majorDim = Math.Max(width, length); var lengthFactor = doc.Units.Length.ConversionFactor; var volumeFactor = Math.Pow(lengthFactor, 3d); // plane at bottom of bottle with normal pointing up var zAxis = Direction.Create(0d, 0d, maxPt.Z - minPt.Z); var botFrame = Frame.Create(minPt, zAxis); var botPlane = Plane.Create(botFrame); var fileName = Path.GetFileNameWithoutExtension(doc.Path); mCallback.Log(LogLevel.Information, "Processing: " + fileName); var now = DateTime.Now; var msgStart = now.ToLongDateString() + " " + now.ToLongTimeString(); mCallback.Log(LogLevel.Information, " " + msgStart); var msgVolume = string.Format(" Volume = {0} {1}^3", origVolume * volumeFactor, doc.Units.Length.Symbol); mCallback.Log(LogLevel.Information, msgVolume); var sb = new StringBuilder(); for (var i = 1; i <= Sections.Value; i++) { var sectHeight = i * height / (double)Sections.Value; using (var sectBox = CreateBlock(Plane.PlaneXY, majorDim, majorDim, sectHeight)) { bodyCopy.Subtract(new[] { sectBox }); } var volume = bodyCopy.Volume; var sectVolume = origVolume - volume; var msg = string.Format(" [{0}] --> {1} {3} --> {2} {3}^3", i, sectHeight * lengthFactor, sectVolume * volumeFactor, doc.Units.Length.Symbol); mCallback.Log(LogLevel.Information, msg); var output = string.Format("{0},{1},{2}", i, sectHeight * lengthFactor, sectVolume * volumeFactor); sb.AppendLine(output); } var outFilePath = Path.Combine(OutputDirectory.Text, fileName); outFilePath = Path.ChangeExtension(outFilePath, ".csv"); File.WriteAllText(outFilePath, sb.ToString()); return(true); }