/// <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!"; }
/// <summary> /// Suppresses a pattern by the given name /// </summary> /// <param name="pattern"></param> /// <param name="status"></param> /// <exception cref="Exception"></exception> public void SuppressPattern(string pattern, bool status) { OccurrencePattern occPattern = null; try { occPattern = _adoc._adef.OccurrencePatterns[pattern]; } catch { throw new Exception("Could not find pattern " + pattern); } int count = occPattern.OccurrencePatternElements.Count; for (int i = 1; i <= count; i++) { OccurrencePatternElement occelement = occPattern.OccurrencePatternElements[i]; ComponentOccurrencesEnumerator occenum = occelement.Occurrences; foreach (ComponentOccurrence occ in occenum) { if (status) { occ.BOMStructure = BOMStructureEnum.kReferenceBOMStructure; occ.Suppress(); } else { occ.Unsuppress(); occ.BOMStructure = BOMStructureEnum.kDefaultBOMStructure; } } //next } }
internal void PlaceModule() { ComponentOccurrence topOccurrence; if (AssemblyOccurrenceObject.Binder.GetObjectFromTrace <ComponentOccurrence>(out topOccurrence)) { topOccurrence.Adaptive = true; PersistenceManager.ActiveAssemblyDoc.Update2(true); topOccurrence.Adaptive = false; if (topOccurrence.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { var doc = (AssemblyDocument)topOccurrence.Definition.Document; doc.Save2(); } else if (topOccurrence.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject) { var doc = (PartDocument)topOccurrence.Definition.Document; doc.Save2(); } } else { AssemblyComponentDefinition assemblyCompDef = PersistenceManager.ActiveAssemblyDoc.ComponentDefinition; topOccurrence = assemblyCompDef.Occurrences.Add(ModuleAssemblyPath, TransformationMatrix); ComponentOccurrencesEnumerator topOccSubs = topOccurrence.SubOccurrences; int topOccSubsCount = topOccSubs.Count; ComponentOccurrence layoutOcc = null; ComponentOccurrence frameOcc = null; for (int i = 0; i < topOccSubsCount; i++) { ComponentOccurrence currentSub = topOccSubs[i + 1]; //This is by convention. Possible better alternative is to have this be //explicitly set in the user interface. if (currentSub.Name == "Template Layout:1") { layoutOcc = currentSub; LayoutComponentDefinition = (PartComponentDefinition)layoutOcc.Definition; } //What did I do this for? I think for old flea flicker parameter updating. if (currentSub.Name == "Frame0001:1") { frameOcc = currentSub; FrameComponentDefinition = (AssemblyComponentDefinition)frameOcc.Definition; } else { TopOccurrences.Add(currentSub); } } int workPointCount = LayoutComponentDefinition.WorkPoints.Count; for (int j = 0; j < workPointCount; j++) //TODO Need to put logic in that test a layout file for derivedparametertables collection.Count != 0 //then do the copy of the layout file, get the layout file and swap out the document descriptor IN APPRENTICE. { WorkPoint currentWP; currentWP = LayoutComponentDefinition.WorkPoints[j + 1]; TargetWorkPoints.Add(currentWP); object currentWPProxyObject; WorkPointProxy currentWPProxy; layoutOcc.CreateGeometryProxy(currentWP, out currentWPProxyObject); currentWPProxy = (WorkPointProxy)currentWPProxyObject; TargetWorkPointProxies.Add(currentWPProxy); } //TODO Fix this to be more intellegent. What if assembly had two planes (rooms etc.). WorkPlane targetWorkPlane; if (LayoutComponentDefinition.WorkPlanes.Count > 3) { targetWorkPlane = (WorkPlane)LayoutComponentDefinition.WorkPlanes[4]; object wPlaneProxyObject; layoutOcc.CreateGeometryProxy(targetWorkPlane, out wPlaneProxyObject); TargetWorkPlaneProxy = (WorkPlaneProxy)wPlaneProxyObject; targetWorkPlane.Visible = false; } //Workplane constraints needed or not? //Make sure the target assembly's layout is adaptive. layoutOcc.Adaptive = true; PersistenceManager.ActiveAssemblyDoc.ComponentDefinition.Constraints.AddMateConstraint(TargetWorkPlaneProxy, LayoutWorkPlaneProxy, 0); if (FirstTime == true) { for (int f = 0; f < PointObjects.Count; f++) { //TODO this is uncertain. It changes from test to test, need to get better handle on the indexing of points. PersistenceManager.ActiveAssemblyDoc .ComponentDefinition .Constraints .AddMateConstraint(TargetWorkPointProxies[f + 1], LayoutWorkPointProxies[f], 0); } topOccurrence.Adaptive = true; PersistenceManager.ActiveAssemblyDoc.Update2(true); topOccurrence.Adaptive = false; //layoutOcc.Visible = false; } else { for (int f = 0; f < PointObjects.Count; f++) { //TODO this is uncertain. It changes from test to test, need to get better handle on the indexing of points. MateConstraint mateConstraint = PersistenceManager.ActiveAssemblyDoc .ComponentDefinition .Constraints .AddMateConstraint(TargetWorkPointProxies[f + 1], LayoutWorkPointProxies[f], 0); if (f > 0) { //These mate constraints will fail out in space because of double accuracy issues unless they are relaxed some. mateConstraint.ConstraintLimits.MaximumEnabled = true; mateConstraint.ConstraintLimits.Maximum.Expression = ".5 in"; } } //layoutOcc.Visible = false; } AssemblyOccurrenceObject.Binder.SetObjectForTrace <ComponentOccurrence>(topOccurrence, ModuleUtilities.ReferenceKeysSorter); if (topOccurrence.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { var doc = (AssemblyDocument)topOccurrence.Definition.Document; doc.Save2(); } else if (topOccurrence.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject) { var doc = (PartDocument)topOccurrence.Definition.Document; doc.Save2(); } } }