private void SetModel() { pfcls.IpfcModelDescriptor descModel; Session.ChangeDirectory(Environment.CurrentDirectory); descModel = (new pfcls.CCpfcModelDescriptor()).CreateFromFileName(_modelPath); StartingDocument = Session.RetrieveModel(descModel); }
public static void StartRender() { Console.WriteLine("Starting rendering..."); try { StartingDocument = GetActiveDocument(); File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " got document \n"); if (StartingDocument != null) { // do the rendering pfcls.IpfcSolid solid = (pfcls.IpfcSolid)StartingDocument; pfcls.IpfcFamilyMember familyMember = (pfcls.IpfcFamilyMember)solid; string cleanDocName = string.Concat(StartingDocument.FullName?.Split(Path.GetInvalidFileNameChars())); var dir = _imagesFolder; if (dir == null) { try { dir = Path.GetDirectoryName(StartingDocument.Origin); } catch { dir = ""; } } string activeDocumentFolder = Path.Combine(dir, cleanDocName + "_renders"); Console.WriteLine("Images will be in \"" + activeDocumentFolder + "\""); if (Directory.Exists(activeDocumentFolder) == false) { Directory.CreateDirectory(activeDocumentFolder); } double widthImg = 19.2; double heightImg = 10.8; string imageExtension = ".png"; pfcls.IpfcRasterImageExportInstructions instructions = (pfcls.IpfcRasterImageExportInstructions) new pfcls.CCpfcBitmapImageExportInstructions().Create(widthImg, heightImg); instructions.DotsPerInch = pfcls.EpfcDotsPerInch.EpfcRASTERDPI_300; instructions.ImageDepth = pfcls.EpfcRasterDepth.EpfcRASTERDEPTH_24; Console.WriteLine("Getting instances..."); File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " Getting instances... \n"); pfcls.CpfcFamilyTableRows familyTableRows = familyMember.ListRows(); var total = familyTableRows.Count; float count = 0; File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " start render all \n"); foreach (pfcls.IpfcFamilyTableRow familyTableRow in familyTableRows) { string instanceName = familyTableRow.InstanceName; Console.Write("instanceName = " + instanceName); string pathForImg = Path.Combine(activeDocumentFolder, instanceName + imageExtension); pfcls.IpfcModel instanceModel = familyTableRow.CreateInstance(); instanceModel.Display(); Window = Session.GetModelWindow(instanceModel); Window.ExportRasterImage(pathForImg, instructions); count++; Console.WriteLine(" \t - " + (count / total).ToString("0.00%") + " \t ({0}/{1})", count, total); } Console.WriteLine("Done"); } else { Console.WriteLine("\nCould not get active document."); File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " Could not get active document \n"); } // return to view of starting document if (StartingDocument != null) { StartingDocument.Display(); } } catch (Exception ex) { File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + ex + " \n"); Console.WriteLine(ex.ToString()); } finally { Cleanup(); } }