Exemplo n.º 1
0
        }  //Main form closing

        private void assemble()
        {
            try
            {
                path = var_es._Doc.FullFileName.Remove(var_es._Doc.FullFileName.Length - 4);

                //создаём новый AssemblyDocument
                assemb_doc = (AssemblyDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), false);
                AssemblyComponentDefinition assemb_doc_Comp = assemb_doc.ComponentDefinition;

                //сохраняем созданий AssemblyDocument
                assemb_doc.SaveAs(path + @"/Shaft.iam", true);

                //Создаём матрицу
                TransientGeometry TG     = var_es.InventorApp.TransientGeometry;
                Matrix            matrix = TG.CreateMatrix();

                //привязываем наш AssemblyDocument в браузере к AssemblyDocument, который открыл пользователь
                var_es.part_doc = (PartDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);
                PartComponentDefinition doc_def = var_es.part_doc.ComponentDefinition;
            }
            catch (Exception e3)
            {
                MessageBox.Show(e3.ToString());
            }
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //// Sample
        ////
        //// Use: Copy & Replace assembly references (1st Level refs only)
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void ReplaceReference()
        {
            AssemblyDocument            oAsmDoc = (AssemblyDocument)_InvApplication.ActiveDocument;
            AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition;

            Document oNewRefDoc = default(Document);
            string   filename   = null;


            foreach (FileDescriptor oFileDesc in oAsmDoc.File.ReferencedFileDescriptors)
            {
                oNewRefDoc = oFileDesc.ReferencedFile.AvailableDocuments(1);

                filename = "C:\\Temp\\Copy-" + oNewRefDoc.DisplayName;

                oNewRefDoc.SaveAs(filename, true);

                oFileDesc.ReplaceReference(filename);
            }

            filename = "C:\\Temp\\Copy-" + oAsmDoc.DisplayName;
            oAsmDoc.SaveAs(filename, true);

            oAsmDoc.Close(true);
        }
Exemplo n.º 3
0
    public void Assembly()
    {
        Inventor.Application InventorApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
        AssemblyDocument     assemblyDoc         = InventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, "", true) as AssemblyDocument;

        assDefinition = assemblyDoc.ComponentDefinition;
        Inventor.Matrix matrix = InventorApplication.TransientGeometry.CreateMatrix();
        matrix.SetTranslation(InventorApplication.TransientGeometry.CreateVector(0, 0, 0));
        string[] pathName = new string[10];
        pathName[0] = @"C:\BearingDetails\Внешнее кольцо подшипника.ipt";
        pathName[1] = @"C:\BearingDetails\Внутреннее кольцо подшипника.ipt";
        pathName[2] = @"C:\BearingDetails\Первый ряд шариков.ipt";
        pathName[3] = @"C:\BearingDetails\Второй ряд шариков.ipt";
        pathName[4] = @"C:\BearingDetails\Сепаратор1.ipt";
        pathName[5] = @"C:\BearingDetails\Сепаратор2.ipt";
        for (int i = 0; i < 6; i++)
        {
            assDefinition.Occurrences.Add(pathName[i], matrix);
        }
        Rotate();
        for (int i = 1; i < 4; i++)
        {
            Tangent(i, 2, 3, 7);
        }
        Tangent(1, 5, 3, 1);
        Tangent(3, 5, 3, 5);
        Tangent(5, 5, 3, 9);
        //Tangent(1, 6, 4, 1);
        //Tangent(3, 6, 4, 5);
        //Tangent(5, 6, 4, 9);
        //for (int i = 2; i < 5; i++)
        //    Tangent(i, 2, 4, 1);
        assemblyDoc.SaveAs(@"C:\BearingDetails\Сборка_подшипника.iam", false);
    }
Exemplo n.º 4
0
        public void ReplaceReferences(AssemblyDocument targetAssembly, TupleList <string, string> namePair, string folderPath)
        {
            OccurrenceList newOccs               = new OccurrenceList(targetAssembly);
            string         pathString            = folderPath;
            List <string>  patternComponentsList = new List <string>();

            for (int i = 0; i < newOccs.Items.Count; i++)
            {
                if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject)
                {
                    for (int f = 0; f < namePair.Count; f++)
                    {
                        if (namePair[f].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName)
                        {
                            if (patternComponentsList.Contains(namePair[f].Item1))
                            {
                                newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2);
                            }

                            else
                            {
                                if (!System.IO.File.Exists(namePair[f].Item2))
                                {
                                    PartDocument partDoc = (PartDocument)PersistenceManager.InventorApplication.Documents.Open(namePair[f].Item1, false);
                                    partDoc.SaveAs(namePair[f].Item2, true);
                                    partDoc.Close(true);
                                    newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2);
                                }
                                patternComponentsList.Add(namePair[f].Item1);
                            }
                        }
                    }
                }

                else if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    for (int n = 0; n < namePair.Count; n++)
                    {
                        if (namePair[n].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName)
                        {
                            AssemblyDocument subAssembly = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(newOccs.Items[i].ReferencedFileDescriptor.FullFileName, false);
                            ReplaceReferences(subAssembly, namePair, pathString);
                            string newFilePath = namePair[n].Item2;
                            subAssembly.SaveAs(namePair[n].Item2, true);
                            subAssembly.Close(true);
                            newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[n].Item2);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        //public static class TranslatorAddins
        //{
        //    public const string SAT	= "89162634-02B6-11D5-8E80-0010B541CD80";
        //    public const string STEP = "90AF7F40-0C01-11D5-8E83-0010B541CD80";
        //    public const string IGES = "90AF7F44-0C01-11D5-8E83-0010B541CD80";
        //    public const string CATIAV5ProductExport = "8A88FC01-0C32-4B3E-BE12-DDC8DF6FFF18";
        //    public const string DWG	= "C24E3AC2-122E-11D5-8E91-0010B541CD80";
        //    public const string DXF	= "C24E3AC4-122E-11D5-8E91-0010B541CD80";
        //    public const string STLImport = "81CA7D27-2DBE-4058-8188-9136F85FC859";
        //    public const string DWF	= "0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4";
        //    public const string PDF	= "0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4";
        //    public const string DWFx	= "0AC6FD97-2F4D-42CE-8BE0-8AEA580399E4";
        //    public const string CATIAV5PartExport = "2FEE4AE5-36D3-4392-89C7-58A9CD14D305";
        //    public const string RVT	= "2058EF4F-37A3-4B57-A322-B4E79E7D53E4";
        //    public const string TUFF = "3260333F-3B0D-4812-9274-E94E14A77A16";
        //    public const string ParasolidText = "8F9D3571-3CB8-42F7-8AFF-2DB2779C8465";
        //    public const string Fusion	= "C6B37B88-3CFA-4521-9873-E087B8626C44";
        //    public const string FCADTransServer = "BE52A5E7-58D8-4E3C-A887-06A4C8F29568";
        //    public const string AutodeskIDFTranslator = "6C5BBC04-5D6F-4353-94B1-060CD6554444";
        //    public const string SolidWorks = "402BE503-725D-41CB-B746-D557AB83BAF1";
        //    public const string ProENGINEERGranite = "66CB2667-73AD-401C-A531-64EC701825A1";
        //    public const string NX = "93D506C4-8355-4E28-9C4E-C2B5F1EDC6AE";
        //    public const string SMT	= "B4ECC5EB-9507-46E5-87FB-EBB9479CE1DF";
        //    public const string OBJImport = " C420F7E4-98FD-4A57-BC1E-04D1D683EFDF";
        //    public const string SVF	= "C200B99B-B7DD-4114-A5E9-6557AB5ED8EC";
        //    public const string ParasolidBinary = " A8F8F8E5-BBAB-4F74-8B1B-AC011251F8AC";
        //    public const string ProENGINEERandCreoParametric = "46D96B7A-CF8A-49C9-8703-2F40CFBDF547";
        //    public const string ContentCenterItemTranslator = "A547F528-D239-475F-8FC6-8F97C4DB6746";
        //    public const string SolidEdge = " E2548DAF-D56B-4809-82B9-5F670E6D518B";
        //    public const string ProENGINEERNeutral = "8CEC09E3-D638-4E8F-A6E1-0D1E1A5FC8E3";
        //    public const string CATIAV4Import	= "C6ACD948-E1C5-4B5B-ADEE-3ED968F8CB1A";
        //    public const string Rhino = "2CB23BF0-E2AC-4B32-B0A1-1CC292AF6623";
        //    public const string CATIAV5Import	= "8D1717FA-EB24-473C-8B0F-0F810C4FC5A8";
        //    public const string AutodeskDWFMarkupManager = "55EBD0FA-EF60-4028-A350-502CA148B499";
        //    public const string JT	= "16625A0E-F58C-4488-A969-E7EC4F99CACD";
        //    public const string Alias	= "DC5CD10A-F6D1-4CA3-A6E3-42A6D646B03E";
        //    public const string OBJExport = " F539FB09-FC01-4260-A429-1818B14D6BAC";
        //    public const string STLExport = "533E9A98-FC3B-11D4-8E7E-0010B541CD80";
        //}

        //public AssemblyDocument Import(string fullAssemblyPath)
        //{
        //    LogTrace("Starting Import");
        //    ApplicationAddIns addins = inventorApplication.ApplicationAddIns;
        //    //foreach (ApplicationAddIn addin in addins)
        //    //{
        //    //    if  (addin is )
        //    //}
        //    //If TypeOf addin Is TranslatorAddIn Then
        //    //    LogTrace(addin.DisplayName & Chr(9) & addin.ClassIdString)
        //    //End If
        //    //Next
        //    TranslatorAddIn transAddin = (TranslatorAddIn)addins.ItemById["{" + TranslatorAddins.STEP + "}"];
        //    LogTrace("Get Stp Addin");
        //    TransientObjects transObjects = inventorApplication.TransientObjects;
        //    transAddin.Activate();

        //    LogTrace("Stp Addin Activated");

        //    //Prepare the 1st parameter for Open(), the file name
        //    DataMedium file = transObjects.CreateDataMedium();
        //    file.FileName = fullAssemblyPath;

        //    LogTrace("DataMedium created");

        //    //Prepare the 2nd parameter for Open(), the open type, for convenience set it as drag&drop
        //    TranslationContext context = transObjects.CreateTranslationContext();
        //    context.Type = IOMechanismEnum.kFileBrowseIOMechanism;

        //    LogTrace("TranslationContext created");

        //    //Prepare the 3rd parameter for Open(), the import options
        //    NameValueMap options = transObjects.CreateNameValueMap();

        //    Boolean hasOpt = transAddin.HasOpenOptions[file, context, options];
        //    options.Value["AssociativeImport"] = false;
        //    options.Value["EmbedInDocument "] = false;
        //    options.Value["SaveLocationIndex "] = 0;
        //    options.Value["TessellationDetailIndex"] = 1;

        //    for (int i = 1; i <= options.Count; ++i)
        //    {
        //        string name = options.Name[i];
        //        string value = (string)options.Value[name];
        //        LogTrace(name + " " + value);
        //    }

        //    object sourceObject;
        //    transAddin.Open(file, context, options, out sourceObject);

        //    AssemblyDocument doc = (AssemblyDocument)sourceObject;

        //    return doc;
        //}


        public AssemblyDocument AnyCADImport(string fullAssemblyPath)
        {
            var em = inventorApplication.ErrorManager;

            LogTrace("AnyCADImport called");
            inventorApplication.SaveOptions.TranslatorReportLocation = ReportLocationEnum.kNoReport;
            AssemblyDocument doc = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject);

            LogTrace("New Assembly created");
            AssemblyComponentDefinition        compDef         = doc.ComponentDefinition;
            ImportedGenericComponentDefinition importedCompDef = (ImportedGenericComponentDefinition)compDef.ImportedComponents.CreateDefinition(fullAssemblyPath);

            importedCompDef.ReferenceModel = true;

            string saveFilesLocation = System.IO.Path.GetDirectoryName(fullAssemblyPath) + "\\";

            LogTrace("Imported Files Location = " + saveFilesLocation);
            importedCompDef.SaveFilesLocation = saveFilesLocation;
            ImportedComponent importedComp = compDef.ImportedComponents.Add((ImportedComponentDefinition)importedCompDef);

            try
            {
                LogTrace("Before Update");
                doc.Update2();
                LogTrace("After Update");
                LogTrace("Before Save");

                LogTrace($"Checking ErrorManager before save");
                LogTrace($"HasErrors = {em.HasErrors}");
                LogTrace($"HasWarnings = {em.HasWarnings}");
                LogTrace($"AllMessages = {em.AllMessages}");

                doc.SaveAs(System.IO.Path.Combine(saveFilesLocation, "output.iam"), false);
                LogTrace("After Save");

                LogTrace("Assembly Path = " + doc.FullFileName);

                LogTrace($"Checking ErrorManager after save");
                LogTrace($"HasErrors = {em.HasErrors}");
                LogTrace($"HasWarnings = {em.HasWarnings}");
                LogTrace($"AllMessages = {em.AllMessages}");
            }
            catch (Exception ex)
            {
                LogTrace("Error: " + ex.Message);
            }
            LogTrace("Successfully Imported");
            return(doc);
        }
Exemplo n.º 6
0
        internal void MakeInvCopy(string templateAssemblyPath,
                                  string targetDirectory,
                                  OccurrenceList occurrenceList,
                                  UniqueModuleEvaluator uniqueModuleEvaluator)
        {
            // TODO Test for the existance of folders and assemblies.
            TemplateAssemblyPath = templateAssemblyPath;
            UniqueModules        = uniqueModuleEvaluator;


            //Get the folder name that will be used to store the files associated with this Module.
            string folderName = GetModuleFolderPath();

            //Need to get number of the parent occ, top level name as foldername
            ModulePath = System.IO.Path.Combine(targetDirectory, folderName);

            string topFileFullName = occurrenceList.TargetAssembly.FullDocumentName;
            string topFileNameOnly = System.IO.Path.GetFileName(topFileFullName);

            ModuleAssemblyPath = System.IO.Path.Combine(ModulePath, topFileNameOnly);

            //If this file already exists in the current location, for now we are
            //going to just skip the file creation, and assume it was previously done
            //correctly.  Probably need to give the user the option to redo and
            //overwrite files if they want to.
            if (!System.IO.File.Exists(ModuleAssemblyPath))
            {
                FilePathPair = new TupleList <string, string>();

                for (int i = 0; i < occurrenceList.Items.Count; i++)
                {
                    string targetOccPath   = occurrenceList.Items[i].ReferencedFileDescriptor.FullFileName;
                    string newCopyName     = System.IO.Path.GetFileName(targetOccPath);
                    string newFullCopyName = System.IO.Path.Combine(ModulePath, newCopyName);
                    FilePathPair.Add(targetOccPath, newFullCopyName);
                }

                //Check if an earlier module already made the folder, if not, create it.
                if (!System.IO.Directory.Exists(ModulePath))
                {
                    //This property is needed later when placing occurrences of the assembly this Module instance
                    //refers to.  If FirstTime is false, we will want to have a slightly different strategry for constraint
                    //placement.  If FirstTime is true, all constraints are important and we need not relax them.  If
                    //FirstTime is false, then we need tolerance in the constraints because of double precision.  When
                    //FirstTime is false, we really just want to position the occurrence correctly, not drive its
                    //geometry.

                    if (FirstTime == null)
                    {
                        FirstTime = true;
                    }

                    System.IO.Directory.CreateDirectory(ModulePath);
                    ReplaceReferences(occurrenceList.TargetAssembly, FilePathPair, ModulePath);
                    AssemblyDocument oAssDoc = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(TemplateAssemblyPath, false);
                    oAssDoc.SaveAs(ModuleAssemblyPath, true);
                    oAssDoc.Close(true);


                    //Need to copy presentation files if there are any.  For now this is only going to work with the top assembly.
                    string   templateDirectory = System.IO.Path.GetDirectoryName(TemplateAssemblyPath);
                    string[] presentationFiles = System.IO.Directory.GetFiles(templateDirectory, "*.ipn");
                    //If we want the ability to have subassemblies with .ipn files or multiple ones, this will have to be changed
                    //to iterate over all the .ipn files.
                    if (presentationFiles.Length != 0)
                    {
                        string newCopyPresName     = System.IO.Path.GetFileName(presentationFiles[0]);
                        string newFullCopyPresName = System.IO.Path.Combine(ModulePath, newCopyPresName);
                        PresentationDocument          presentationDocument = (PresentationDocument)PersistenceManager.InventorApplication.Documents.Open(presentationFiles[0], false);
                        DocumentDescriptorsEnumerator presFileDescriptors  = presentationDocument.ReferencedDocumentDescriptors;
                        foreach (DocumentDescriptor refPresDocDescriptor in presFileDescriptors)
                        {
                            if (refPresDocDescriptor.FullDocumentName == TemplateAssemblyPath)
                            {
                                refPresDocDescriptor.ReferencedFileDescriptor.ReplaceReference(ModuleAssemblyPath);
                                presentationDocument.SaveAs(newFullCopyPresName, true);
                                presentationDocument.Close(true);
                            }
                        }
                    }
                }

                else
                {
                    FirstTime = false;
                }
            }
        }
Exemplo n.º 7
0
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            LogTrace("Initialiting");
            PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);

            LogTrace("Part template opened");
            TransientGeometry       oTG         = inventorApplication.TransientGeometry;
            PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition;
            UserParameters          oParams     = oPartComDef.Parameters.UserParameters;

            XmlDocument xmlDoc     = new XmlDocument();
            string      currentDir = System.IO.Directory.GetCurrentDirectory();
            string      projectDir = Directory.GetParent(currentDir).Parent.FullName;

            LogTrace("Reading XML input file from " + projectDir);
            xmlDoc.Load(System.IO.Path.Combine(projectDir, "react-test-output.xml"));
            //xmlDoc.Load("react-test-output.xml");
            //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml");
            XmlNodeList FloorList      = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor");
            XmlNodeList FloorPointList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point");
            XmlNodeList ComponentName  = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/ComponentName");
            XmlNodeList PointX         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/X");
            XmlNodeList PointY         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Y");
            XmlNodeList PointZ         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Z");



            for (int i = 0; i < FloorList.Count; i++)
            {
                //oParams.AddByExpression("ComponentName" + i, ComponentName[i].InnerText, UnitsTypeEnum.kUnitlessUnits);


                int numPoint = FloorPointList.Count / FloorList.Count;

                Point2d[]     oPoints  = new Point2d[numPoint];
                SketchPoint[] osPoints = new SketchPoint[numPoint];

                for (int j = 0; j < numPoint; j++)
                {
                    oParams.AddByExpression("PointX" + j, PointX[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);
                    oParams.AddByExpression("PointY" + j, PointY[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);
                    oParams.AddByExpression("PointZ" + j, PointZ[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);

                    oPoints[j] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("PointX" + j, UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("PointY" + j, UnitsTypeEnum.kMillimeterLengthUnits));
                }

                SketchLine[] oLines  = new SketchLine[numPoint];
                PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[2]);
                osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]);
                osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]);
                osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]);
                osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]);

                oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]);
                oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[2]);
                oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[3]);
                oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint);

                oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0//
                oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[2], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1//

                Profile           oProfile    = oSketch.Profiles.AddForSolid();
                ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);
                oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "8", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
                ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef);

                string PartPath = projectDir + "/results/" + ComponentName[i].InnerText + i + ".ipt";
                //string PartPath = ComponentName[i].InnerText + i + ".ipt";
                oPartDoc.SaveAs(PartPath, false);

                oExtrude.Delete();
            }

            oPartDoc.Close(false);

            AssemblyDocument            oAssyDoc      = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true);
            AssemblyComponentDefinition oAssyComDef   = oAssyDoc.ComponentDefinition;
            ComponentOccurrences        oAssyCompOccs = oAssyComDef.Occurrences;
            Matrix oPos  = oTG.CreateMatrix();
            int    oStep = 0;
            int    icomp;
            int    numite = FloorPointList.Count / FloorList.Count;

            for (icomp = 0; icomp <= numite; icomp++)
            {
                oStep = oStep + 150;
                oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false);
                string PartPath = projectDir + "/results/" + ComponentName[icomp].InnerText + icomp + ".ipt";
                //string PartPath = ComponentName[icomp].InnerText + icomp + ".ipt";
                ComponentOccurrence oOcc = oAssyCompOccs.Add(PartPath, oPos);
            }

            oAssyDoc.SaveAs(projectDir + "/results/result.iam", false);
            //oAssyDoc.SaveAs("result.iam", false);
            oAssyDoc.Close();
            ZipFile.CreateFromDirectory(projectDir + "/results", projectDir + "/forgeResult.zip");
        }
Exemplo n.º 8
0
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            //LogTrace("Processing " + doc.FullFileName);

            //try
            //{
            //    if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            //    {
            //        using (new HeartBeat())
            //        {
            //            // TODO: handle the Inventor part here
            //        }
            //    }
            //    else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly.
            //    {
            //        using (new HeartBeat())
            //        {
            //            // TODO: handle the Inventor assembly here
            //        }
            //    }
            //}
            //catch (Exception e)
            //{
            //    LogError("Processing failed. " + e.ToString());
            //}
            LogTrace("Initialiting");
            PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);

            LogTrace("Part template opened");
            TransientGeometry       oTG         = inventorApplication.TransientGeometry;
            PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition;
            UserParameters          oParams     = oPartComDef.Parameters.UserParameters;

            oParams.AddByExpression("width", "50", UnitsTypeEnum.kMillimeterLengthUnits);
            oParams.AddByExpression("height", "10", UnitsTypeEnum.kMillimeterLengthUnits);
            oParams.AddByExpression("length", "10", UnitsTypeEnum.kMillimeterLengthUnits);
            LogTrace("Standard parameters created");


            Point2d[] oPoints = new Point2d[4];


            oPoints[0] = oTG.CreatePoint2d(0, 0);
            oPoints[1] = oTG.CreatePoint2d(0, oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits));
            oPoints[2] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), 0);
            oPoints[3] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits));
            LogTrace("Inventor points created");
            LogTrace("Initiating sketch creation...");
            PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[1]);

            SketchPoint[] osPoints = new SketchPoint[4];
            SketchLine[]  oLines   = new SketchLine[4];

            osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]);
            osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]);
            osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]);
            osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]);

            oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]);
            oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[3]);
            oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[2]);
            oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint);
            LogTrace("Sketch created, adding dimensions");
            oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0//
            oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[3], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1//
            LogTrace("Dimensions added to the sketch, changing standard values for User parameter values");

            var inventorMParams = oPartComDef.Parameters.ModelParameters;

            foreach (ModelParameter mParam in inventorMParams)
            {
                if (mParam.Name.Contains("d0"))
                {
                    mParam.Expression = "width";
                }
                else if (mParam.Name.Contains("d1"))
                {
                    mParam.Expression = "height";
                }
            }

            LogTrace("Dimensions with user parameter values created, starting extrude operation");

            //oSketch.DimensionConstraints.AddTwoPointDistance(oPoints[0], oPoints[1], DimensionOrientationEnum.kAlignedDim, "width", true);
            Profile oProfile = oSketch.Profiles.AddForSolid();

            ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "length", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

            ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef);

            //oExtrude.FeatureDimensions[1].Parameter.Name = "length";
            LogTrace("Extrude operation finished");
            XmlDocument xmlDoc     = new XmlDocument();
            string      currentDir = System.IO.Directory.GetCurrentDirectory();
            string      projectDir = Directory.GetParent(currentDir).Parent.FullName;

            LogTrace("Reading XML input file from " + projectDir);
            xmlDoc.Load(System.IO.Path.Combine(projectDir, "React-BIM-output.xml"));
            //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml");
            XmlNodeList memberNodeList     = xmlDoc.GetElementsByTagName("Member");
            XmlNodeList partNumberNodeList = xmlDoc.GetElementsByTagName("PartNumber");
            XmlNodeList widthNodeList      = xmlDoc.GetElementsByTagName("width");
            XmlNodeList heightNodeList     = xmlDoc.GetElementsByTagName("height");
            XmlNodeList lengthNodeList     = xmlDoc.GetElementsByTagName("length");

            LogTrace("XML tag values imported");
            LogTrace("Creating iPart");
            iPartFactory oFactory = oPartComDef.CreateFactory();
            Worksheet    oWS      = oFactory.ExcelWorkSheet;
            Workbook     oWB      = (Workbook)oWS.Parent;

            LogTrace("Generating Excel file for iPart");
            oWS.Cells[1, 1] = "Member<defaultRow>1</defaultRow><filename></filename>";
            oWS.Cells[1, 2] = "Part Number [Project]";
            oWS.Cells[1, 3] = "width";
            oWS.Cells[1, 4] = "height";
            oWS.Cells[1, 5] = "length";

            for (int i = 0; i < memberNodeList.Count; i++)
            {
                oWS.Cells[(i + 2), 1] = memberNodeList[i].InnerText;
                oWS.Cells[(i + 2), 2] = partNumberNodeList[i].InnerText;
                oWS.Cells[(i + 2), 3] = widthNodeList[i].InnerText;
                oWS.Cells[(i + 2), 4] = heightNodeList[i].InnerText;
                oWS.Cells[(i + 2), 5] = lengthNodeList[i].InnerText;
            }



            oWB.Save();
            oWB.Close();
            LogTrace("Excel created");
            oPartDoc.Update();
            string iPartPath = projectDir + "/results/bimipart.ipt";
            int    iNumRows  = oFactory.TableRows.Count;

            LogTrace("Saving iPart to " + iPartPath);
            oPartDoc.SaveAs(iPartPath, false);

            LogTrace("Opening new assembly template");
            AssemblyDocument            oAssyDoc      = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true);
            AssemblyComponentDefinition oAssyComDef   = oAssyDoc.ComponentDefinition;
            ComponentOccurrences        oAssyCompOccs = oAssyComDef.Occurrences;

            LogTrace("Creating Matrix");
            Matrix oPos  = oTG.CreateMatrix();
            int    oStep = 0;
            int    iRow;

            LogTrace("Placing iPart members to assembly");
            for (iRow = 1; iRow <= iNumRows; iRow++)
            {
                oStep = oStep + 150;

                oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false);
                ComponentOccurrence oOcc = oAssyCompOccs.AddiPartMember(iPartPath, oPos, iRow);
            }
            string assyPath = projectDir + "/results/bimassy.iam";

            LogTrace("Saving Assembly file to " + assyPath);
            oAssyDoc.SaveAs(assyPath, false);
        }