예제 #1
0
        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);
            }
        }
예제 #2
0
        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;
        }
예제 #3
0
        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);
            }
        }