示例#1
0
        public string GetParameter(InventorDocument workingDocument, string paramName)
        {
            var parameter = workingDocument.Parameters.FirstOrDefault(x => x.Name == paramName);

            if (parameter == null)
            {
                LogManager.Add($"Could not find parameter {paramName} in {workingDocument.Name}");
                return("Not Found");
            }

            switch (parameter.UnitType)
            {
            case UnitTypes.Length:
            case UnitTypes.Angular:
                return(UnitManager.UnitsFromInventor(parameter.Value, parameter.UnitType).ToString());

            case UnitTypes.Unitless:
                return(parameter.Value.ToString());

            case UnitTypes.Text:
                return(parameter.Value.ToString());

            default:
                return("");
            }
        }
示例#2
0
        public void SetProperty(InventorDocument document, string propertyName, string value)
        {
            var properties = GetIpropertyEnums();

            IpropertyEnum iproperty = IpropertyEnum.Custom;

            foreach (var p in properties)
            {
                if (p.GetDescription().ToUpper() == propertyName.ToUpper())
                {
                    iproperty = p;
                    break;
                }
            }

            if (document == null)
            {
                throw new Exception("Could not find document to set property on");
            }

            try
            {
                document.Properties.SetPropertyValue(iproperty, value, propertyName);
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
示例#3
0
        public void SetParameter(InventorDocument document, string paramName, string value)
        {
            var parameter = document.Parameters.FirstOrDefault(x => x.Name == paramName);

            if (parameter == null)
            {
                LogManager.Add($"Could not find parameter {paramName} in {document.Name}");
                return;
            }

            switch (parameter.UnitType)
            {
            case UnitTypes.Length:
            case UnitTypes.Angular:
                parameter.Value = UnitManager.UnitsToInventor(ConverterHelpers.ConvertDouble(value), parameter.UnitType);
                break;

            case UnitTypes.Unitless:
                parameter.Value = ConverterHelpers.ConvertInt(value);
                break;

            case UnitTypes.Text:
                parameter.Value = value;
                break;
            }
        }
示例#4
0
        public string GetProperty(InventorDocument document, string propertyName)
        {
            var properties = GetIpropertyEnums();

            IpropertyEnum iproperty = IpropertyEnum.Custom;

            foreach (var p in properties)
            {
                if (p.GetDescription().ToUpper() == propertyName.ToUpper())
                {
                    iproperty = p;
                    break;
                }
            }

            if (document == null)
            {
                throw new Exception("Could not find document to set property on");
            }

            var value = document.Properties.GetPropertyValue(iproperty, propertyName);

            if (string.IsNullOrEmpty(value))
            {
                LogManager.Add($"Could not find property {propertyName} in {document.Name}");
            }

            return(value);
        }
示例#5
0
        public void Suppression(InventorDocument document, string component, string suppressed, SuppresionType suppresionType)
        {
            var status = suppressed.ToUpper() == "S";

            try
            {
                switch (suppresionType)
                {
                case SuppresionType.Component:
                    document.GetAssemblyDocument().Components.SetComponentStatus(component, status);
                    break;

                case SuppresionType.Constraint:
                    document.GetAssemblyDocument().Constraints.SetConstraintStatus(component, status);
                    break;

                case SuppresionType.Pattern:
                    document.GetAssemblyDocument().Patterns.SuppressPattern(component, status);
                    break;

                case SuppresionType.Feature:
                    document.SetFeatureStatus(component, status);
                    break;
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
示例#6
0
 public CopyDocumentItem(InventorDocument document)
 {
     OldDocName = document.Name;
     OldPath    = document.FileName;
     NewDocName = OldDocName;
     NewPath    = OldPath;
 }
        /// <summary>
        /// Attaches to inventor and setups up the methods
        /// </summary>
        /// <param name="worksheet"></param>
        /// <param name="topDocument"></param>
        public ProcessRunBlockInventor(Excel.Worksheet worksheet, InventorDocument topDocument = null) : base(worksheet)
        {
            if (!InventorApplication.Attached)
            {
                InventorApplication.Attach();
            }

            _methods     = new InventorMethods();
            _topDocument = topDocument;
        }
示例#8
0
 public void DeleteReferenced(InventorDocument document, string component)
 {
     try
     {
         document.GetAssemblyDocument().Components.DeleteComponents(component);
     }
     catch (Exception ex)
     {
         LogManager.Add(ex.Message);
     }
 }
        private void UpdateWorkingDocument()
        {
            _workingDocument = InventorApplication.ActiveDocument;

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

            Parameters.Clear();
            Features.Clear();
        }
        /// <summary>
        /// Run application against the commands in the excel file
        /// </summary>
        /// <param name="rangeName"></param>
        /// <param name="rangeParameter"></param>
        /// <returns></returns>
        public List <string> Run(string rangeName = "", string rangeParameter = "")
        {
            // The start cell
            Excel.Range startCell = null;

            // if the range name is null get the name of the current sheet plus type
            if (string.IsNullOrEmpty(rangeName))
            {
                startCell = _worksheet.Range[_worksheet.Name + "Type"];
            }
            else
            {
                startCell = _worksheet.Range[rangeName];
            }

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

            // Column for the type of commands we are running
            var typeCol = startCell.Column;

            // Name of the document or sub we are working with
            var nameCol = typeCol + 1;

            // Parent of the document we are working
            var parentCol = nameCol + 1;

            // Value to set or get based on command
            var value = parentCol + 1;

            // Secondary value for some commands
            var value2 = value + 1;

            // Set the start orw
            var i = startCell.Row + 1;

            // loop while the command column is not null
            while (!string.IsNullOrEmpty(GetString(i, typeCol)))
            {
                // get the command we are working with
                var command = GetString(i, typeCol).ToUpper();

                // if the command is a comment continue
                if (command == Commands.Comment)
                {
                    i++;
                    continue;
                }
                // Open the document
                else if (command == Commands.OpenDocument)
                {
                    _methods.OpenDocument(GetString(i, nameCol), GetString(i, parentCol), GetString(i, value), GetString(i, value2));
                    i++;
                    continue;
                }

                // Assign the working document
                var workingDocumentName = GetString(i, parentCol);

                // working document name is null then assign the working document to the document
                if (string.IsNullOrEmpty(workingDocumentName))
                {
                    if (_topDocument == null)
                    {
                        _topDocument = InventorApplication.ActiveDocument;
                    }

                    _workingDocument = _topDocument;
                }
                // Assign the working document
                else
                {
                    // if the working document is null then assign
                    if (_workingDocument == null)
                    {
                        _workingDocument = DocumentHelper.GetDocument(workingDocumentName);

                        if (_workingDocument == null)
                        {
                            Logs.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                    // if the working document does not match working document name then assign it.
                    else
                    {
                        if (_workingDocument.Name != workingDocumentName)
                        {
                            _workingDocument = DocumentHelper.GetDocument(workingDocumentName);
                        }

                        if (_workingDocument == null)
                        {
                            Logs.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                }

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

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

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

                case Commands.GetParameter:
                    var parameterValue = _methods.GetParameter(_workingDocument, GetString(i, nameCol));
                    SetValue(i, value, parameterValue);
                    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.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.Update();
                    break;

                case Commands.Sub:
                    ProcessRunBlockInventor runBlock = null;
                    var subName       = GetString(i, nameCol);
                    var workSheetName = "";

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

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

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

                    runBlock.Run(subName, GetString(i, value));

                    Logs.AddRange(runBlock.Logs);
                    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 (_topDocument != null)
            {
                if (InventorApplication.ActiveDocument.Name != _topDocument.Name)
                {
                    InventorApplication.ActiveDocument.Save();

                    InventorApplication.ActiveDocument.Close();
                }
            }

            InventorApplication.ActiveDocument.Update();

            InventorApplication.ActiveDocument.Save();

            Logs.AddRange(_methods.Logs);

            return(Logs);
        }
示例#11
0
 /// <summary>
 /// Replace the references in the document
 /// </summary>
 /// <param name="document"></param>
 /// <param name="referenceData"></param>
 /// <param name="skip"></param>
 public static void ReplaceReferences(InventorDocument document, List <ReferenceDto> referenceData, List <string> skip = null)
 {
     Recurse(document._document.File.ReferencedFileDescriptors, referenceData);
 }