private void objectListView1_FormatRow(object sender, BrightIdeasSoftware.FormatRowEventArgs e) { PartToImport part = (PartToImport)e.Model; if (!System.IO.File.Exists(symFolder + part.name + ".sym")) { e.Item.ForeColor = Color.Gray; } }
private void PopulateListBox() { PartsToImport.Clear(); foreach (ISelection selection in selectionSet) { Autodesk.Connectivity.WebServices.File selectedFile = null; if (selection.TypeId == SelectionTypeId.File) { // our ISelection.Id is really a File.MasterId selectedFile = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(selection.Id); } else if (selection.TypeId == SelectionTypeId.FileVersion) { // our ISelection.Id is really a File.Id selectedFile = connection.WebServiceManager.DocumentService.GetFileById(selection.Id); } if (selectedFile != null) { if (selectedFile.Name.EndsWith(".ipt")) { PartToImport part = new PartToImport(); part.name = selectedFile.Name.Replace(".ipt", ""); VDF.Vault.Currency.Entities.FileIteration fileIter = new Vault.Currency.Entities.FileIteration(connection, selectedFile); part.desc = GetERPDescriptionProperty(fileIter); part.thickness = radInterface.GetThicknessFromSym(symFolder + part.name + ".sym"); part.materialType = radInterface.GetMaterialTypeFromSym(symFolder + part.name + ".sym"); part.qty = 0; PartsToImport.Add(part); selectedFiles.Add(selectedFile); } } } if (PartsToImport.Count > 0) { objectListView1.SetObjects(PartsToImport); } }
private void objectListView1_DoubleClick(object sender, EventArgs e) { string selectedItemName = ((PartToImport)objectListView1.SelectedItem.RowObject).name; PartToImport partToModify = PartsToImport.FirstOrDefault(sel => sel.name == selectedItemName); string errorMessage = ""; if (!ConvertFile(partToModify.name, ref errorMessage)) { statusStrip.Text = "Error in converting File"; } int tItemIndex = objectListView1.TopItemIndex; objectListView1.RefreshObjects(PartsToImport); objectListView1.Refresh(); objectListView1.SetObjects(PartsToImport); objectListView1.TopItemIndex = tItemIndex; //objectListView1.SelectedItem.Focused = true; }
private void btnAddToProject_Click(object sender, EventArgs e) { radInterface.SaveProject(); System.IO.Stream stream = null; PartToImport part = new PartToImport(); RadanProject rPrj = new RadanProject(); string path = Properties.Settings.Default["radanProject"].ToString(); int numOfPartsImported = 0; for (int i = 0; i < PartsToImport.Count; i++) { part = PartsToImport[i]; if (part.qty != 0) { string partName = symFolder + part.name + ".sym"; double partThickness = double.Parse(part.thickness); int partQty = part.qty; try { var timeOut = TimeSpan.FromSeconds(1); stream = System.IO.File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); stream.Flush(); using (StreamReader reader = new StreamReader(stream)) { XmlSerializer prjSerializer = new XmlSerializer(typeof(RadanProject)); rPrj = (RadanProject)prjSerializer.Deserialize(reader); RadanPart prt = new RadanPart(partName, rPrj.Parts.NextID, PartsToImport[i].materialType, partThickness, "in", partQty); rPrj.Parts.NextID++; rPrj.Parts.Add(prt); stream.Close(); reader.Close(); } stream = System.IO.File.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); //stream.Flush(); using (StreamWriter Writer = new StreamWriter(stream)) { XmlSerializer prjSerializer = new XmlSerializer(typeof(RadanProject)); stream = System.IO.File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); prjSerializer.Serialize(stream, rPrj); stream.Close(); Writer.Close(); } } catch (Exception) { //Console.WriteLine("Error opening XML file"); if (stream != null) { stream.Close(); } } numOfPartsImported++; } } radInterface.LoadProject(path); toolStripStatusLabel.Text = numOfPartsImported + " items added to project"; }
private bool ConvertFile(string NameOfPartToConvert, ref string ErrorMessage) { toolStripStatusLabel.Text = ""; progressBar.Value = 0; progressBar.PerformStep(); string selectedItemIptName = NameOfPartToConvert + ".ipt"; string errorMessage = ""; string materialName = ""; string partThickness = ""; string topPattern = ""; string partName = ""; string partDescription = ""; string partUnits = "in"; Boolean overWriteConfirm = true; string openProjectName = ""; string openNestName = ""; try { openProjectName = radInterface.getOpenProjectName(ref errorMessage); string symFileName = symFolder + NameOfPartToConvert + ".sym"; if (System.IO.File.Exists(symFileName)) { DialogResult result; MessageBoxButtons buttons = MessageBoxButtons.YesNo; result = MessageBox.Show("The sym file already exists. Do you want to overwrite it?", "Confirm Overwrite", buttons); if (result == DialogResult.Yes) { overWriteConfirm = true; } else { overWriteConfirm = false; System.IO.File.SetLastWriteTimeUtc(symFileName, DateTime.UtcNow); } } if (overWriteConfirm == true) { Autodesk.Connectivity.WebServices.File webServicesFile = selectedFiles.FirstOrDefault(sel => sel.Name == selectedItemIptName); VDF.Vault.Currency.Entities.FileIteration fileIter = new Vault.Currency.Entities.FileIteration(connection, webServicesFile); PartToImport modifiedPart = new PartToImport(); string filePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fileIter.EntityName); PartToImport partToModify = PartsToImport.FirstOrDefault(sel => sel.name == NameOfPartToConvert); int index = objectListView1.IndexOf(partToModify); modifiedPart.name = PartsToImport[index].name; partDescription = GetERPDescriptionProperty(fileIter); modifiedPart.desc = partDescription; // remove old ipt from temp folder to ensure we will use the lastest version if (System.IO.File.Exists(filePath)) { System.IO.File.SetAttributes(filePath, FileAttributes.Normal); } System.IO.File.Delete(filePath); radInterface.SaveNest(ref errorMessage); openNestName = radInterface.getOpenNestName(ref errorMessage); toolStripStatusLabel.Text = "Downloading File..."; DownloadFile(fileIter, filePath); progressBar.PerformStep(); toolStripStatusLabel.Text = "Saving Radan Nest..."; if (!radInterface.SaveNest(ref errorMessage)) { ErrorMessage = errorMessage; toolStripStatusLabel.Text = errorMessage; return(false); } else { progressBar.PerformStep(); } toolStripStatusLabel.Text = "Opening 3D File..."; if (!radInterface.Open3DFileInRadan(filePath, "", ref errorMessage)) { ErrorMessage = errorMessage; toolStripStatusLabel.Text = errorMessage; return(false); } else { progressBar.PerformStep(); } toolStripStatusLabel.Text = "Unfolding 3D File..."; if (!radInterface.UnfoldActive3DFile(ref partName, ref materialName, ref partThickness, ref topPattern, ref errorMessage)) { ErrorMessage = errorMessage; toolStripStatusLabel.Text = errorMessage; return(false); } else { progressBar.PerformStep(); } toolStripStatusLabel.Text = "Saving Sym File..."; if (!radInterface.SavePart(topPattern, symFileName, ref errorMessage)) { ErrorMessage = errorMessage; toolStripStatusLabel.Text = errorMessage; return(false); } else { progressBar.PerformStep(); } toolStripStatusLabel.Text = "Setting Radan Attributes..."; if (!radInterface.InsertAttributes(symFileName, materialName, partThickness, partUnits, partDescription, ref errorMessage)) { ErrorMessage = errorMessage; toolStripStatusLabel.Text = errorMessage; return(false); } else { progressBar.PerformStep(); } toolStripStatusLabel.Text = "Done..."; double thickness = double.Parse(partThickness); if (thickness <= 0.001) { toolStripStatusLabel.Text = "Part Thickness Could Not Be Calculated, Aborting Operation"; return(false); } else { modifiedPart.thickness = thickness.ToString(); modifiedPart.materialType = materialName; progressBar.PerformStep(); } PartsToImport[index] = modifiedPart; ShellFile shellFile = ShellFile.FromFilePath(symFileName); Bitmap shellThumb = shellFile.Thumbnail.Bitmap; this.picBoxSym.Image = ResizeImage(shellThumb, 115, 115); if (openProjectName != "") { radInterface.LoadProject(openProjectName); } if (openNestName != "") { radInterface.openNest(openNestName, ref errorMessage); } } return(true); } catch (Exception) { errorMessage = "Error in converting File"; return(false); } }