//CATPart 파일들을 저장할 filepath와 part를 인자로 줘서 그곳에 변환한 파일을 저장하게 함 //현재는 그냥 Part를 줬지만 itemNum을 이용하여 Assem변수에서 Part를 가져와서 할수도 있음.
        //오버로딩 함수 : CATPart파일들을 저장할 filepath들만 인자로 줘서 그곳에 변환하여 저장하게 하는 함수 : Backup ver5_06을 참조
        //오버로딩 함수 : CATPart파일들을 저장할 filepath를 임의로 다 저장해놓은 상태에서 변환을 하는 함수 : Backup ver5_06을 참조
        public void TranslatePartsT2C(string filepath, int itemNum, TransCAD.Part part)
        {
            //일단 itemNum은 사용하지 않음
            //savespartname은 예전에 사용했던 변수임

            saveaspartname = new string[1]; //실제로 사용되는지는 모르겠다.
            Task[] TasksPartTranslation = new Task[1];

            TransCAD.IPart currentpart = part;

            Console.WriteLine("Name of part [ " + currentpart.Name + " ]");
            Part PartManager = new Part();

            PartManager.InitializeTransCAD((int)2);
            if (ReferenceManager == null)
            {
                ReferenceManager = new Reference(PartManager);
            }
            TasksPartTranslation[0] = Task.Factory.StartNew(() =>
            {
                PartManager.InitializeCATIA(" ", (int)1);
                PartManager.TranslateT2C(currentpart);     //1개에 대한 Part post 번역 실행
                Console.WriteLine("Name of part [ " + currentpart.Name + " ] was Translated!");
                saveaspartname[0] = filepath;
                PartManager.SaveCATPartFile(saveaspartname[0]);
                Console.WriteLine("Name of part [ " + currentpart.Name + " ] was saved as " + saveaspartname[0]);
                PartManager.UninitializeCATIA();
            });
            TasksPartTranslation[0].Wait();
            Part.partNum++;
        }
Пример #2
0
 public void UninitializeTransCAD()
 {
     tApp      = null;
     tDocs     = null;
     tPartDoc  = null;
     tPart     = null;
     tAssemDoc = null;
     tFeatures = null;
 }
Пример #3
0
        public void loadAssemblyInfo(NXOpen.Part assemblyFilePart)
        {
            //Get root component which is top level assembly component
            rootComponent = assemblyFilePart.ComponentAssembly.RootComponent;

            //Get components and constraints in (root)assembly
            nxComponents = rootComponent.GetChildren();

            //Get constraint information
            nxPositioner  = assemblyFilePart.ComponentAssembly.Positioner;
            nxConstraints = nxPositioner.Constraints.ToArray();

            numComponents = nxComponents.Length;

            tcad_PartList         = new TransCAD.Part[numComponents];
            componentPositions    = new Point3d[numComponents];
            componentOrientations = new Matrix3x3[numComponents];
            nxCompNames           = new string[numComponents];

            for (int i = 0; i < numComponents; i++)
            {
                NXOpen.Assemblies.Component nxComponent = nxComponents[i];

                //save name of NX Part into string array
                nxCompNames[i] = nxComponent.DisplayName;

                //Get position and orientation of each part and save them into componentPositions, componentOrientations
                Point3d   componentPosition;
                Matrix3x3 componentOrientation;
                nxComponent.GetPosition(out componentPosition, out componentOrientation);
                componentPositions[i]    = componentPosition;
                componentOrientations[i] = componentOrientation;

                //Get file directory of each part in assembly
                NXOpen.Part nxPart = null;
                nxPart = (Part)nxComponent.Prototype;
                string xmlPartDir = Path.ChangeExtension(nxPart.FullPath, ".xml"); //chaneg extension from .prt to .xml

                //Load transCAD xml part file corresponding to each NX part using file name, the transCAD xml should be in same folder with same name except extension(.prt -> .xml)
                TransCAD.Part tcad_Part = tComp.CreatePart(nxComponent.DisplayName);
                tcad_Part = tComp.ImportPartFromXML(xmlPartDir, tcad_Part);
                //save transCAD part data into array "tcad_PartList"
                tcad_PartList[i] = tcad_Part;

                //Place each part in TransCAD
                double extraDisplacement = i * 100; //To see whether constraints are applied or not, intentionally, place part with extra displacement which is different from original NX part
                tComp.SetPartPlacement(tcad_Part, componentPosition.X, componentPosition.Y + extraDisplacement, componentPosition.Z - extraDisplacement,
                                       componentOrientation.Zx, componentOrientation.Zy, componentOrientation.Zz,
                                       componentOrientation.Xx, componentOrientation.Xy, componentOrientation.Xz);
                tComp.AddPart(tcad_Part);
            }
            tAssem.AddComponent(tComp);
            tAssemDoc.Update();
        }
Пример #4
0
        ////

        //// TransCAD 관련 함수
        public bool InitializeTransCAD(int mode)
        {
            try
            {
                tApp = (TransCAD.Application)Marshal.GetActiveObject("TransCAD.Application");
            }
            catch
            {
                tApp = (TransCAD.Application)Activator.CreateInstance(Type.GetTypeFromProgID("TransCAD.Application"));
            }

            if (tApp == null)
            {
                return(false);
            }

            tDocs = tApp.Documents;

            if (mode == 0)  //pre일때 사용 PartDocument 추가
            {
                tPartDoc = tDocs.AddPartDocument();
            }
            else if (mode == 1) //post일때 사용 이미 열려있는 것을 Active
            {
                tPartDoc = (TransCAD.PartDocument)tApp.ActiveDocument;
            }
            else if (mode == 2) //Assembly document에서 part 번역을 위한 initialization
            {
                tAssemDoc         = (TransCAD.AssemDocument)tApp.ActiveDocument;
                isSubAssemblyPart = true;
                return(true);
            }



            tApp.Visible = true;

            tPart     = tPartDoc.Part;
            tFeatures = tPart.Features;

            if (ReferenceManager == null)
            {
                ReferenceManager = new Reference(this);
            }

            //tAssemDoc.Update();

            return(true);
        }
Пример #5
0
        public void loadAssemblyInfo()
        {
            tAssemDoc = (TransCAD.AssemDocument)tApp.ActiveDocument;
            tAssem    = tAssemDoc.Assem;
            //Count Component Number
            compCount = tAssem.GetSize();
            compName  = new string[compCount];
            for (int i = 0; i < compCount; i++)
            {
                TransCAD.Component tComp = tAssem.GetComponent(i);
                compName[i] = tComp.get_Name();
                Console.WriteLine("Name of Component[ " + i + " ] : " + tComp.get_Name());

                //Count Part Number in Component
                partCount = tComp.GetSize();
                partname  = new string[partCount];
                if (compName[i] == "Default SubAssembly")
                {
                    continue;
                }
                tcad_PartList = new TransCAD.Part[partCount];
                partFileName  = new string[partCount];
                NXObject[] nxGeom = new NXObject[partCount];
                for (int j = 0; j < partCount; j++)
                {
                    TransCAD.Part tPart = tComp.GetPart(j);
                    partname[j]      = tPart.Name;
                    tcad_PartList[j] = tPart;
                    int    facecount = tPart.Solid.Faces.Count;
                    string facenm    = tPart.Solid.Faces[1].Name;
                    Console.WriteLine(facenm);
                    Console.WriteLine(" Name of Part[ " + j + " ] : " + tPart.Name);
                    partFileName[j] = tPart.Name;
                }
            }
        }
        //각 Constraint에서 사용하는 Master/Slave Part의 ReferenceName을 refCommand 구조체로 리턴
        private refCommand TestRefer(TransCAD.StdAssemConstraint tConstraint, CTYPE i, PreStack _stack) //constrain 받아오기
        {
            CTYPE      type   = i;
            refCommand para   = new refCommand();
            refCommand result = new refCommand();

            ReferenceClass.ref_Post m_refer = new ReferenceClass.ref_Post();
            m_refer.Set_stack_info(_stack);
            double value = 0;

            //Type Define TransCAD 7.0

            /*
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Angle;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Coaxial;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Coincidence;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Distance;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Fix;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Parallel;
             * TransCAD.StdAssemblyConstraintType.StdAssemblyConstraintType_Perpendicular;
             */


            switch (type)
            {
            case CTYPE.StdAssemblyConstraintType_Coaxial:

                TransCAD.StdAssemConstraintCoaxial coax = (TransCAD.StdAssemConstraintCoaxial)tConstraint;
                Console.WriteLine("Loading Coaxial......................................");

                _debug          = coax.Name;
                para.command    = (int)type;
                para.param      = "Axis" + ":(";
                para.MasterPart = coax.ConstrainedPart.Name;
                para.SlavePart  = coax.ReferencePart.Name;

                para.MasterPart_Ref = coax.ConstrainedEntity.ReferenceeName;
                _debug = coax.ConstrainedEntity.Name;


                ///[Edit]For test A1 TestRally 20190712
                {
                    //TransCAD.Reference tempref = coax.ConstrainedEntity;
                    //bool res = tempref.IsPlanarFace;

                    //if we get edge name we have to find surface that define axis
                    if (para.MasterPart_Ref.IndexOf('#') != -1)
                    {
                        string[]      _split = para.MasterPart_Ref.Split('#');
                        TransCAD.Part ptr    = coax.ConstrainedPart;

                        for (int s = 0; s < _split.Length; s++)
                        {
                            string             temp    = _split[s].Substring(_split[s].IndexOf(',', _split[s].IndexOf(',') + 1) + 1);
                            TransCAD.Reference tempref = ptr.SelectBrepByName(temp);
                            if (!tempref.IsPlanar)
                            {
                                para.MasterPart_Ref = _split[s];
                                break;
                            }
                            para.MasterPart_Ref = _split[s];
                        }
                    }
                }


                para.SlavePart_Ref = coax.ReferenceEntity.ReferenceeName;
                _debug             = coax.ReferenceEntity.Name;

                ///[Edit]For test A1 TestRally 20190712
                {
                    //if we get edge name we have to find surface that define axis
                    if (para.SlavePart_Ref.IndexOf('#') != -1)
                    {
                        string[] _split = para.SlavePart_Ref.Split('#');
                        //para.SlavePart_Ref = _split[1];

                        //Method 2 : Find by name of 'Sketch'
                        for (int j = 0; j < _split.Length; j++)
                        {
                            if (_split[j].IndexOf("Sketch") > 0)
                            {
                                para.SlavePart_Ref = _split[j];
                            }
                        }
                    }
                    if (para.SlavePart_Ref.IndexOf('#') != -1)
                    {
                        string[]      _split = para.SlavePart_Ref.Split('#');
                        TransCAD.Part ptr    = coax.ReferencePart;

                        for (int s = 0; s < _split.Length; s++)
                        {
                            string             temp    = _split[s].Substring(_split[s].IndexOf(',', _split[s].IndexOf(',') + 1) + 1);
                            TransCAD.Reference tempref = ptr.SelectBrepByName(temp);
                            if (!tempref.IsPlanar)
                            {
                                para.SlavePart_Ref = _split[s];
                                break;
                            }
                            para.SlavePart_Ref = _split[s];
                        }
                    }
                }



                Console.WriteLine(coax.ConstrainedEntity.ReferenceeName + ".&&." + coax.ReferenceEntity.ReferenceeName);
                break;



            case CTYPE.StdAssemblyConstraintType_Coincidence:

                TransCAD.StdAssemConstraintCoincidence coin = (TransCAD.StdAssemConstraintCoincidence)tConstraint;
                Console.WriteLine("Loading COINCIDENCE......................................");

                _debug              = coin.Name;
                para.command        = (int)type;
                para.param          = "";
                para.MasterPart     = coin.ConstrainedPart.Name;
                para.SlavePart      = coin.ReferencePart.Name;
                para.MasterPart_Ref = coin.ConstrainedEntity.ReferenceeName;
                para.SlavePart_Ref  = coin.ReferenceEntity.ReferenceeName;
                Console.WriteLine(coin.ConstrainedEntity.ReferenceeName + ".&&." + coin.ReferenceEntity.ReferenceeName);

                break;

            // Mutahar 18-10-09
            case CTYPE.StdAssemblyConstraintType_Angle:      //(Surface-Surface)
                TransCAD.StdAssemConstraintAngle ang = (TransCAD.StdAssemConstraintAngle)tConstraint;
                Console.WriteLine("Loading Angle......................................");

                _debug              = ang.Name;
                para.command        = (int)type;
                para.param          = "";
                para.MasterPart     = ang.ConstrainedPart.Name;
                para.SlavePart      = ang.ReferencePart.Name;
                para.MasterPart_Ref = ang.ConstrainedEntity.ReferenceeName;
                para.SlavePart_Ref  = ang.ReferenceEntity.ReferenceeName;
                value = ang.Angle;
                Console.WriteLine(ang.ConstrainedEntity.ReferenceeName + ".&&." + ang.ReferenceEntity.ReferenceeName);
                //Angle Value?

                break;

            case CTYPE.StdAssemblyConstraintType_Distance:      //(Surface-Surface)
                TransCAD.StdAssemConstraintDistance dist = (TransCAD.StdAssemConstraintDistance)tConstraint;
                Console.WriteLine("Loading Distance......................................");

                _debug              = dist.Name;
                para.command        = (int)type;
                para.param          = "";
                para.MasterPart     = dist.ConstrainedPart.Name;
                para.SlavePart      = dist.ReferencePart.Name;
                para.MasterPart_Ref = dist.ConstrainedEntity.ReferenceeName;
                para.SlavePart_Ref  = dist.ReferenceEntity.ReferenceeName;
                Console.WriteLine(dist.ConstrainedEntity.ReferenceeName + ".&&." + dist.ReferenceEntity.ReferenceeName);
                value = dist.Distance;
                //Offset Value?

                break;


            default:
                Console.WriteLine("Anything........");
                break;
            }
            Console.WriteLine("////////////////////////////////////////////////////////////////////////");
            result        = m_refer.ConvertRefPost(para);
            result.option = value;
            Console.WriteLine("////////////////////////////////////////////////////////////////////////");
            Console.WriteLine("ConsNum : " + result.command.ToString());
            Console.WriteLine("master : " + result.MasterPart_Ref);
            Console.WriteLine("slave : " + result.SlavePart_Ref);
            Console.WriteLine("////////////////////////////////////////////////////////////////////////");

            return(result);
        }