Beispiel #1
0
        /// <summary>
        /// Exports the BXDF and BXDA files.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Exporter_DoWork(object sender, DoWorkEventArgs e)
        {
            if (FilePathTextBox.Text.Length == 0 || FileNameTextBox.Text.Length == 0 || FileNameTextBox.Text.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
            {
                e.Result = "Invalid Export Parameters.";
                return;
            }

            FieldDefinition fieldDefinition = new FieldDefinition(FileNameTextBox.Text);
            SurfaceExporter exporter        = new SurfaceExporter();

            ComponentOccurrencesEnumerator componentOccurrences = ((AssemblyDocument)Program.INVENTOR_APPLICATION.ActiveDocument).ComponentDefinition.Occurrences.AllLeafOccurrences;

            for (int i = 0; i < componentOccurrences.Count; i++)
            {
                progressWindow.Invoke(new Action(() =>
                {
                    progressWindow.ProcessInfoLabel.Text    = "Exporting: " + (Math.Round((i / (float)componentOccurrences.Count) * 100.0f, 2)).ToString() + "%";
                    progressWindow.ProcessProgressBar.Value = i;
                }));

                if (componentOccurrences[i + 1].Visible)
                {
                    exporter.Reset();
                    exporter.Export(componentOccurrences[i + 1], false, true); // Index starts at 1?

                    BXDAMesh output = exporter.GetOutput();

                    FieldNode outputNode = new FieldNode(componentOccurrences[i + 1].Name,
                                                         CollisionObjectsView.Nodes.Find(componentOccurrences[i + 1].Name, true).Length > 0 ?
                                                         FieldNodeCollisionType.MESH : FieldNodeCollisionType.NONE);

                    outputNode.AddSubMeshes(output);

                    fieldDefinition.AddChild(outputNode);
                }
            }

            BXDFProperties.WriteProperties(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxdf", fieldDefinition);

            fieldDefinition.CreateMesh();
            fieldDefinition.GetMeshOutput().WriteToFile(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxda");

            FieldDefinition_Base copyDefinition = BXDFProperties.ReadProperties(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxdf");

            e.Result = "Export Successful!";
        }