Esempio n. 1
0
        public void NXRootFile(Session nxSession, NewNXfile fileDir)
        {
            NXOpen.FileNew nxRootCompFile = nxSession.Parts.FileNew();
            fileDir.NXfile(nxRootCompFile, fileDir.rootDir());
            NXOpen.NXObject nXObject_RootComp = nxRootCompFile.Commit();
            nxRootCompFile.MakeDisplayedPart = true;
            Part nxRootAssem = nxSession.Parts.Work;

            nxRootCompFile.Destroy();
        }
Esempio n. 2
0
        public void ToNXFile(Session nxSession)
        {
            NXOpen.Part nxSubAssem;
            var         newFile = new NewNXfile();
            var         fileDir = new NewNXfile();

            for (int i = 0; i < compCount; i++)
            {
                nxRootAssem = nxSession.Parts.Work;
                if (compName[i] == "Default SubAssembly")
                {
                    continue;
                }
                NXOpen.FileNew compFile = nxSession.Parts.FileNew();
                newFile.NXfile(compFile, fileDir.subassemdir(compName[i]));
                compFile.MakeDisplayedPart = false;
                NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
                createNewComponentBuilder1 = nxRootAssem.AssemblyManager.CreateNewComponentBuilder();
                createNewComponentBuilder1.NewComponentName = compName[i];
                createNewComponentBuilder1.ReferenceSet     = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;
                createNewComponentBuilder1.ReferenceSetName = "Entire Part";
                createNewComponentBuilder1.NewFile          = compFile;
                NXOpen.NXObject nXObject_SubAssem = createNewComponentBuilder1.Commit();
                createNewComponentBuilder1.Destroy();
                nxSubAssem = (NXOpen.Part)nxSession.Parts.FindObject(compName[i]);
                NXObject[] nxGeom = new NXObject[partCount];
                for (int j = 0; j < partCount; j++)
                {
                    NXOpen.BasePart       basePart1;
                    NXOpen.PartLoadStatus partLoadStatus, partLoadStatus2;
                    basePart1 = nxSession.Parts.OpenBase(fileDir.partdir(partFileName[j]), out partLoadStatus);
                    partLoadStatus.Dispose();
                    basepoint1      = new NXOpen.Point3d(0.0, 0.0, 0.0);
                    orientation1    = new NXOpen.Matrix3x3();
                    orientation1.Xx = 1.0;
                    orientation1.Xy = 0.0;
                    orientation1.Xz = 0.0;
                    orientation1.Yx = 0.0;
                    orientation1.Yy = 1.0;
                    orientation1.Yz = 0.0;
                    orientation1.Zx = 0.0;
                    orientation1.Zy = 0.0;
                    orientation1.Zz = 1.0;
                    NXOpen.Assemblies.Component component1;
                    component1 = nxRootAssem.ComponentAssembly.AddComponent(fileDir.partdir(partFileName[j]), "MODEL", "A1-1", basepoint1, orientation1, -1, out partLoadStatus2, true);
                    partLoadStatus2.Dispose();
                    NXOpen.Assemblies.Component[] origComponents1 = new NXOpen.Assemblies.Component[1];
                    origComponents1[0] = component1;
                    NXOpen.Assemblies.Component   component2 = (NXOpen.Assemblies.Component)nXObject_SubAssem;
                    NXOpen.Assemblies.Component[] newComponents1;
                    NXOpen.ErrorList errorList1;
                    nxSubAssem.ComponentAssembly.RestructureComponents(origComponents1, component2, true, out newComponents1, out errorList1);
                    errorList1.Dispose();
                    nxGeom[i] = origComponents1[0];
                    string reef = nxGeom[i].OwningComponent.DisplayName;
                    Console.WriteLine("*************************" + reef);
                }
                /*Working Information with Hardcoded information;*/
                ComponentPositioner[]         tempcomponentPositioner1 = new ComponentPositioner[2];
                ComponentConstraint[]         tempcomponentConstraint1 = new ComponentConstraint[2];
                ComponentPositioner[]         componentPositioner1     = new ComponentPositioner[2];
                ComponentPositioner[]         componentPositioner2     = new ComponentPositioner[2];
                ComponentConstraint[]         componentConstraint1     = new ComponentConstraint[2];
                ComponentConstraint[]         componentConstraint2     = new ComponentConstraint[2];
                NXOpen.Assemblies.Component[] component01 = new Component[2];
                NXOpen.Assemblies.Component[] component02 = new Component[2];
                for (int m = 0; m < 2; m++)
                {
                    component01[m] = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[m] + " 1");
                    //NXOpen.Assemblies.Component component02 = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[0] + " 1");
                }

                /*
                 * tempcomponentPositioner1[0] = nxSubAssem.ComponentAssembly.Positioner;
                 * tempcomponentPositioner1[0].BeginAssemblyConstraints();
                 * Constraint tempconstraint1;
                 * tempconstraint1 = tempcomponentPositioner1[0].CreateConstraint(true);
                 * tempcomponentConstraint1[0] = (NXOpen.Positioning.ComponentConstraint)tempconstraint1;
                 * tempcomponentConstraint1[0].ConstraintType = NXOpen.Positioning.Constraint.Type.Concentric;
                 * Edge edge1 = (NXOpen.Edge)component01[0].FindObject(EdgeNames[0]);
                 * ConstraintReference ConsRef1 = tempcomponentConstraint1[0].CreateConstraintReference(component01[0],edge1,false,false,false);
                 * Edge edge2 = (NXOpen.Edge)component01[1].FindObject(EdgeNames[1]);
                 * ConstraintReference ConsRef2 = tempcomponentConstraint1[0].CreateConstraintReference(component01[1], edge2, false, false, false);
                 */


                for (int k = 0; k < 2; k++)
                {
                    if (constNamesTemp[k].Contains("Coaxial"))
                    {
                        componentPositioner1[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner1[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner1[k].CreateConstraint(true);
                        componentConstraint1[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint1[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.ContraAlign;
                        componentConstraint1[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Fit;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference1;
                        constraintReference1 = componentConstraint1[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        //Face face3 = (NXOpen.Face)component01[1].FindObject(ConstNames2[1]);
                        NXOpen.Positioning.ConstraintReference constraintReference2;
                        constraintReference2 = componentConstraint1[k].CreateConstraintReference(component01[1], face2, false, false, false);
                    }
                    else
                    {
                        componentPositioner2[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner2[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner2[k].CreateConstraint(true);
                        componentConstraint2[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint2[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.InferAlign;
                        componentConstraint2[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Touch;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference3;
                        constraintReference3 = componentConstraint2[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference4;
                        constraintReference4 = componentConstraint2[k].CreateConstraintReference(component01[1], face2, false, false, false);
                        constraintReference4.SetFixHint(true);
                    }
                }
                break;
            }
            PartSaveStatus fileSave;

            fileSave = nxRootAssem.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
        }