Esempio n. 1
0
        /// <summary>
        /// Called when the apply button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            var model  = SolidWorksEnvironment.Application.ActiveModel;
            var model2 = (ModelDoc2)SolidWorksEnvironment.Application.UnsafeObject.ActiveDoc;
            ModelDocExtension     extension       = model2.Extension;
            CustomPropertyManager propertyManager = default(CustomPropertyManager);

            propertyManager = extension.get_CustomPropertyManager("");

            // Check if we have a part
            if (model == null || !model.IsPart)
            {
                return;
            }

            // Notes
            // First clear the existing note custom properties
            model.CustomProperties((properties) =>
            {
                List <CustomProperty> found = properties.FindAll(property => property.Name.Contains(CustomPropertyNote));
                foreach (CustomProperty item in found)
                {
                    propertyManager.Delete(item.Name);
                }
            });

            int j = 1;

            foreach (var child in NoteGrid.Children)
            {
                if (child.GetType() == typeof(System.Windows.Controls.TextBox))
                {
                    model.SetCustomProperty(CustomPropertyNote + " " + j.ToString(), ((System.Windows.Controls.TextBox)child).Text);
                    j++;
                }
            }

            // Feature Tolerances
            for (int i = 0; i < mFeatureTolerances.Count; i++)
            {
                FeatureToleranceObject item = mFeatureTolerances.ElementAt(i);
                string CustomPropertyName   = CustomPropertyFeatureTolerance + item.FeatureName;
                model.SetCustomProperty(CustomPropertyName, item.FeatureTolerance);
            }

            // If user does not have a material selected, clear it
            if (RawMaterialList.SelectedIndex < 0)
            {
                model.SetMaterial(null);
            }
            // Otherwise set the material to the selected one
            else
            {
                model.SetMaterial((Material)RawMaterialList.SelectedItem);
            }

            // Re-read details to confirm they are correct
            ReadDetails();
        }
Esempio n. 2
0
        /// <summary>
        /// Ask user to provide a tolerance for a given feature
        /// This will open a message box with a UI that the user can fill out
        /// </summary>
        /// <param name="feature">SolidWorks feature currently selected</param>
        private FeatureToleranceObject GetFeatureTolerance(Feature feature)
        {
            // Default tolerance is +/- 0.25mm
            string default_tolerance = "+/- 0.25mm";

            // Configure the message box to ask user if this feature is critical
            string messageBoxText = "Does the highlighted feature,\r\n" + feature.Name + ",\r\n need a specific tolerance?";
            string formTitle      = "Critical Features";

            // Use the custom FeatureCriticalMessageBox class to ask the user
            MessageBox_FeatureCritical isFeatureCritical = new MessageBox_FeatureCritical(messageBoxText, formTitle);
            DialogResult criticalFeature_result          = isFeatureCritical.ShowDialog();

            // Based on the result, either ask the user for a more specific tolerance or use the default tolerance
            if (criticalFeature_result == DialogResult.Yes)
            {
                // User has identified this feature as critical, so it may require a tighter tolerance
                string messageBoxText2 = "The default tolerance is +/- 0.25mm. Would you like to change this value for " + feature.Name + "?";
                string formTitle2      = "Critical Feature Tolerance";

                // Display Tolerance Message Box to the user and wait for tolerance selection
                MessageBox_Tolerance CriticalFeatureTolerance = new MessageBox_Tolerance(messageBoxText2, formTitle2);
                DialogResult         tolerance_result         = CriticalFeatureTolerance.ShowDialog();

                FeatureToleranceObject result = new FeatureToleranceObject()
                {
                    FeatureName      = feature.Name,
                    FeatureTolerance = CriticalFeatureTolerance.Tolerance_Value
                };

                return(result);
            }

            // User has not identified this feature as critical, so return the default tolerance
            else
            {
                FeatureToleranceObject result2 = new FeatureToleranceObject()
                {
                    FeatureName      = feature.Name,
                    FeatureTolerance = default_tolerance
                };

                return(result2);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loops through all features in a part, asking the user to
        /// specify a tolerance for a given feature by calling GetFeatureTolerance
        /// </summary>
        private void Tolerance_Check_Loop()
        {
            // Clear the old tolerances
            mFeatureTolerances.Clear();

            // Get the active model and begin SolidWorks' SelectionManager and FeatureManager objects
            var model            = (ModelDoc2)SolidWorksEnvironment.Application.UnsafeObject.ActiveDoc;
            var selectionManager = model.SelectionManager;
            var featureManager   = model.FeatureManager;

            // Get all features in the .sldprt file
            var AllFeatures = (object[])featureManager.GetFeatures(false);

            List <List <Feature> > filteredFeatures = GetFeatureDictionary(AllFeatures);

            for (int i = 0; i < filteredFeatures.Count; i++)
            {
                // Get the head feature of each feature-sketch-list
                // This list of lists contains more information than we need
                // So here, we just use the first element in each list - which corresponds to the main feature
                // (and excludes dimension-bearing sketches and any other underlying sketches)
                Feature headFeature = (filteredFeatures[i]).First();

                // Highlight the feature
                model.Extension.SelectByID2(headFeature.Name, "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                // Get the user specified or default tolerance for this feature
                FeatureToleranceObject thisFeatureTolerance = GetFeatureTolerance(headFeature);

                // Add this tolerance to the list of all tolerances
                mFeatureTolerances.Add(thisFeatureTolerance);

                // Refesh the plug-in's display of all of the tolerances
                FeatureTolerance_Display.Items.Refresh();
            }

            // Clear the selection after assigning all tolerances
            model.ClearSelection();
        }