public void SetDocumentReferenceVisibility(SolidworksDocument workingDocument, string name, bool visible, string featureType)
        {
            if (workingDocument.IsAssemblyDoc)
            {
                workingDocument.ClearSelection();

                var children = workingDocument.Children().Where(c => c.SolidworksDocument.Name == name);

                foreach (var c in children)
                {
                    workingDocument.Select(c.Name, FeatureTypes.Component);

                    if (workingDocument.SelectedCount() == 1)
                    {
                        if (visible)
                        {
                            workingDocument.ShowSelected();
                        }
                        else
                        {
                            workingDocument.HideSelected();
                        }
                    }

                    workingDocument.ClearSelection();
                }
            }
        }
        public void SetVisiblity(SolidworksDocument document, string name, bool visibilty, string featureType)
        {
            document.ClearSelection();

            try
            {
                switch (featureType)
                {
                case FeatureTypes.Component:
                    document.Select(name, FeatureTypes.Component);
                    break;
                }

                if (document.SelectedCount() != 1)
                {
                    throw new Exception($"Could not find {name} in {document.Name}");
                }

                if (visibilty)
                {
                    document.ShowSelected();
                }
                else
                {
                    document.HideSelected();
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
        public string GetDimValue(SolidworksDocument workingDocument, string name, string configuration)
        {
            var dim = workingDocument.GetSolidworksDimension(name);

            if (dim == null)
            {
                LogManager.Add($"Could not find dimension {name} in {workingDocument.Name}");
                return("");
            }

            double value = dim.GetValue(string.IsNullOrEmpty(configuration) ? ConfigurationOptions.ThisConfiguration
                                                                            : ConfigurationOptions.SpecifyConfiguration,
                                        configuration);
            double convertedValue;

            switch (dim.Type)
            {
            case DimensionTypes.Linear:
                convertedValue = UnitManager.UnitsFromSolidworks(value);
                break;

            case DimensionTypes.Angular:
                convertedValue = UnitManager.ConvertRadians(value);
                break;

            case DimensionTypes.Integer:
            default:
                convertedValue = value;
                break;
            }

            return(convertedValue.ToString());
        }
Exemplo n.º 4
0
        public ProcessRunBlockSolidworks(Excel.Worksheet worksheet, SolidworksDocument topDocument = null) : base(worksheet)
        {
            if (!SolidworksApplication.Attached)
            {
                SolidworksApplication.Attach();
            }

            _methods = new SolidworksMethods();
        }
 public void ShowConfiguration(SolidworksDocument document, string configurationName)
 {
     if (document.ConfigurationExists(configurationName))
     {
         document.ShowConfiguration(configurationName);
     }
     else
     {
         LogManager.Add($"{configurationName} does not exist in document {document.Name}");
     }
 }
        public string GetEquation(SolidworksDocument workingDocument, string name)
        {
            var equation = workingDocument.Equations.GetEquation(name);

            if (equation == null)
            {
                LogManager.Add($"Could not find equation {name} in {workingDocument.Name}");
            }

            return(equation == null ? "" : equation.Value.ToString());
        }
 public void SetProperty(SolidworksDocument document, string propertyName, string value)
 {
     try
     {
         document.ActiveConfiguration.Properties.SetValue(propertyName, value);
     }
     catch (Exception ex)
     {
         LogManager.Add(ex.Message);
     }
 }
        public void Suppression(SolidworksDocument document, string name, string value, SuppresionType suppresionType)
        {
            var status = value.ToUpper() == "S";

            document.ClearSelection();

            try
            {
                switch (suppresionType)
                {
                case SuppresionType.Component:
                    document.Select(name, FeatureTypes.Component);
                    break;

                case SuppresionType.Constraint:
                    document.Select(name, FeatureTypes.Mate);
                    break;

                case SuppresionType.Feature:
                    document.Select(name, FeatureTypes.BodyFeature);
                    break;

                case SuppresionType.Pattern:
                    document.Select(name, FeatureTypes.ComponentPattern);
                    break;

                case SuppresionType.Folder:
                    document.Select(name, FeatureTypes.Folder);
                    break;
                }

                if (document.SelectedCount() != 1)
                {
                    throw new Exception($"Could not find {name} in {document.Name}");
                }

                if (status)
                {
                    document.SuppressSelected();
                }
                else
                {
                    document.UnsuppressSelected();
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
        public string GetProperty(SolidworksDocument document, string propertyName)
        {
            var value = "";

            try
            {
                value = document.ActiveConfiguration.Properties.GetValue(propertyName);
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }

            return(value);
        }
        public void SetComponentConfiguration(SolidworksDocument document, string componentName, string configurationName)
        {
            document.ClearSelection();

            document.Select(componentName, FeatureTypes.Component);

            if (document.SelectedCount() != 1)
            {
                LogManager.Add($"Could not find {componentName} in {document.Name}");
                return;
            }

            var comp = document.GetSelectedComponent();

            if (comp != null)
            {
                comp.ReferencedConfiguration = configurationName;
            }
        }
Exemplo n.º 11
0
        private void UpdateWorkingDocument()
        {
            _workingDocument = SolidworksApplication.ActiveDocument;

            if (InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate()
                {
                    this.Text = _workingDocument?.FileName;
                }));
            }
            else
            {
                this.Text = _workingDocument?.FileName;
            }

            Dimensions.Clear();
            Features.Clear();
        }
Exemplo n.º 12
0
        private void Recurse(SolidworksDocument document, List <Tuple <string, string> > paths)
        {
            foreach (var c in document.Children(true))
            {
                var path = c.SolidworksDocument.FullFileName;

                var refPath = paths.FirstOrDefault(x => x.Item1.ToUpper() == path.ToUpper());

                if (refPath == null)
                {
                    continue;
                }

                document.ClearSelection();

                c.Select();

                var adoc = document._doc as AssemblyDoc;

                if (adoc == null)
                {
                    continue;
                }

                adoc.ReplaceComponents(refPath.Item2, c.ReferencedConfiguration, false, true);

                if (c.SolidworksDocument.IsAssemblyDoc)
                {
                    SolidworksApplication.ActivateDocument(c.SolidworksDocument.FileName);

                    var doc = SolidworksApplication.ActiveDocument;

                    Recurse(doc, paths);

                    doc.Close();
                }
            }
        }
        public void SetDimValue(SolidworksDocument workingDocument, string name, string configuration, double value)
        {
            var dim = workingDocument.GetSolidworksDimension(name);

            if (dim == null)
            {
                LogManager.Add($"Could not find dimension {name} in {workingDocument.Name}");
                return;
            }

            double convertedValue;

            switch (dim.Type)
            {
            case DimensionTypes.Linear:
                convertedValue = UnitManager.UnitsToSolidworks(value);
                break;

            case DimensionTypes.Angular:
                convertedValue = UnitManager.ConvertDegrees(value);
                break;

            case DimensionTypes.Integer:
            default:
                convertedValue = value;
                break;
            }

            var success = dim.SetValue(convertedValue, string.IsNullOrEmpty(configuration) ? ConfigurationOptions.ThisConfiguration
                                                                                           : ConfigurationOptions.SpecifyConfiguration,
                                       configuration);

            if (!success)
            {
                LogManager.Add($"Could not set dim {name} in {workingDocument.Name}");
            }
        }
        public void SetWeldmentMemberConfiguration(SolidworksDocument document, string featurename, string configurationName)
        {
            document.ClearSelection();

            document.Select(featurename, FeatureTypes.BodyFeature);

            if (document.SelectedCount() != 1)
            {
                LogManager.Add($"Could not find {featurename} in {document.Name}");
                return;
            }

            var feature = document.GetSelectedFeature();

            if (feature.TypeName.ToUpper() == FeatureSubTypes.WeldMemberFeat.ToUpper())
            {
                feature.SetWeldmentConfiguration(configurationName);
            }
            else
            {
                LogManager.Add($"Feature {featurename} in {document.Name} is not a weldment member");
                return;
            }
        }
Exemplo n.º 15
0
        public void References(SolidworksDocument document, List <Tuple <string, string> > paths)
        {
            _topDocument = document;

            Recurse(document, paths);
        }
 public void SetEquation(SolidworksDocument workingDocument, string name, double value)
 {
     workingDocument.Equations.SetEquation(name, value);
 }
Exemplo n.º 17
0
        public List <string> Run(bool startMethod, string rangeName = "", string subRangeName = "", string subRangeValue = "")
        {
            Excel.Range startCell = null;

            if (string.IsNullOrEmpty(rangeName))
            {
                startCell = _worksheet.Range[_worksheet.Name + "Type"];
            }
            else
            {
                startCell = _worksheet.Range[rangeName];
            }

            if (!string.IsNullOrEmpty(subRangeName))
            {
                var subRangeCell = _worksheet.Range[subRangeName];
                subRangeCell.Value = subRangeValue;
            }

            if (startCell == null)
            {
                throw new Exception("Could not find start range");
            }


            var typeCol   = startCell.Column;
            var nameCol   = typeCol + 1;
            var parentCol = nameCol + 1;
            var value     = parentCol + 1;
            var value2    = value + 1;
            var i         = startCell.Row + 1;

            while (!string.IsNullOrEmpty(GetString(i, typeCol)))
            {
                var command = GetString(i, typeCol).ToUpper();

                if (command == Commands.Comment)
                {
                    i++;
                    continue;
                }

                var workingDocumentName = GetString(i, parentCol);

                if (command != Commands.Sub)
                {
                    if (string.IsNullOrEmpty(workingDocumentName))
                    {
                        if (_topDocument == null)
                        {
                            _topDocument = SolidworksApplication.ActiveDocument;
                        }
                        else
                        {
                            if (SolidworksApplication.ActiveDocument.Name != _topDocument.Name)
                            {
                                SolidworksApplication.ActiveDocument.Close();
                            }

                            SolidworksApplication.ActivateDocument(_topDocument.Name);
                        }

                        _workingDocument = _topDocument;
                    }
                    else
                    {
                        if (_workingDocument == null)
                        {
                            _workingDocument = SolidworksApplication.ActivateDocument(workingDocumentName);

                            if (_workingDocument == null)
                            {
                                throw new Exception($"Could not find document {workingDocumentName}");
                            }
                        }
                        else
                        {
                            if (_workingDocument.Name != workingDocumentName)
                            {
                                if (_workingDocument.Name != _topDocument.Name)
                                {
                                    _workingDocument.Close();
                                }

                                _workingDocument = SolidworksApplication.ActivateDocument(workingDocumentName);
                            }

                            if (_workingDocument == null)
                            {
                                throw new Exception($"Could not find document {workingDocumentName}");
                            }
                        }
                    }
                }

                switch (command)
                {
                case Commands.TopLevelName:
                    var topLevelName = GetString(i, nameCol);

                    if (SolidworksApplication.ActiveDocument.Name != topLevelName)
                    {
                        throw new Exception("Top level name does not match active model");
                    }
                    else
                    {
                        _topDocument = SolidworksApplication.ActiveDocument;
                    }
                    break;

                case Commands.Dimension:
                    _methods.SetDimValue(_workingDocument, GetString(i, nameCol), "", GetDouble(i, value));
                    break;

                case Commands.Equation:
                    _methods.SetEquation(_workingDocument, GetString(i, nameCol), GetDouble(i, value));
                    break;

                case Commands.SetProperty:
                    _methods.SetProperty(_workingDocument, GetString(i, nameCol), GetString(i, value));
                    break;

                case Commands.GetProperty:
                    var propertyValue = _methods.GetProperty(_workingDocument, GetString(i, nameCol));
                    SetValue(i, value, propertyValue);
                    break;

                case Commands.ComponentActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Component);
                    break;

                case Commands.ConstraintActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Constraint);
                    break;

                case Commands.PatternActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Pattern);
                    break;

                case Commands.FeatureActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Feature);
                    break;

                case Commands.ShowConfiguration:
                    _methods.ShowConfiguration(_workingDocument, GetString(i, nameCol));
                    break;

                case Commands.SetComponentConfiguration:
                    _methods.SetComponentConfiguration(_workingDocument, GetString(i, nameCol), GetString(i, value));
                    break;

                case Commands.SetWeldmentConfiguration:
                    _methods.SetWeldmentMemberConfiguration(_workingDocument, GetString(i, nameCol), GetString(i, value));
                    break;

                case Commands.ComponentVisiblity:
                    _methods.SetVisiblity(_workingDocument, GetString(i, nameCol), GetBoolean(i, value), FeatureTypes.Component);
                    break;

                case Commands.DocumentReferenceVisiblity:
                    _methods.SetDocumentReferenceVisibility(_workingDocument, GetString(i, nameCol), GetBoolean(i, value), FeatureTypes.Component);
                    break;

                case Commands.DeleteComponent:
                    // _methods.Delete(_workingDocument, GetString(i, nameCol));
                    break;

                case Commands.DeleteReferencedDocuments:
                    // _methods.DeleteReferenced(_workingDocument, GetString(i, nameCol));
                    break;

                case Commands.Stop:
                    throw new Exception("Program Stopped");

                case Commands.UpdateDocument:
                    _workingDocument.ForceRebuildAll();
                    break;

                case Commands.Sub:
                    ProcessRunBlockSolidworks runBlock = null;
                    var subName       = GetString(i, nameCol);
                    var parameterName = GetString(i, parentCol);
                    var parameter     = GetString(i, value);

                    var workSheetName = "";

                    if (subName.Contains("!"))
                    {
                        var subSplit = subName.Split('!');

                        workSheetName = subSplit[0];
                        subName       = subSplit[1];

                        runBlock = new ProcessRunBlockSolidworks(Globals.ThisAddIn.Application.ActiveWorkbook.GetWorksheets().FirstOrDefault(x => x.Name == workSheetName), _topDocument);
                    }
                    else
                    {
                        runBlock = new ProcessRunBlockSolidworks(_worksheet, _topDocument);
                    }

                    runBlock.Run(false, subName, parameterName, parameter);
                    break;

                case Commands.If:
                    ValidateIf(i, typeCol);

                    var booleanValue = GetBoolean(i, value);

                    if (!booleanValue)
                    {
                        i = GetEndIfRow(i, typeCol);
                    }
                    break;

                case Commands.Repeat:
                    ValidateRepeat(i, typeCol);
                    repeatStart = i;
                    repeatEnd   = GetEndRepeatRow(i, typeCol);
                    repeatCount = GetInt(i, value);
                    repeatIndex = 1;
                    SetValue(i, value2, repeatIndex.ToString());
                    inRepeat = true;
                    break;
                }

                i++;

                if (inRepeat)
                {
                    if (i == repeatEnd)
                    {
                        if (repeatIndex == repeatCount)
                        {
                            i           = repeatEnd + 1;
                            repeatStart = 0;
                            repeatEnd   = 0;
                            repeatCount = 0;
                            repeatIndex = 0;
                            inRepeat    = false;
                        }
                        else
                        {
                            i = repeatStart + 1;
                            repeatIndex++;
                            SetValue(repeatStart, value2, repeatIndex.ToString());
                        }
                    }
                }
            }

            if (startMethod)
            {
                if (_topDocument != null && SolidworksApplication.ActiveDocument.Name != _topDocument.Name)
                {
                    SolidworksApplication.ActiveDocument.Save();

                    SolidworksApplication.ActiveDocument.Close();
                }

                SolidworksApplication.ActiveDocument.ForceRebuildAll();

                SolidworksApplication.ActiveDocument.Save();
            }

            return(_methods.Logs);
        }