public void ApplyDis(Part Assem, ComponentPositioner componentPositioner1, ConstData constinfo) { Constraint constraint1 = componentPositioner1.CreateConstraint(true); ///1 ComponentConstraint compoConst = (NXOpen.Positioning.ComponentConstraint)constraint1; ///2 compoConst.ConstraintType = NXOpen.Positioning.Constraint.Type.Distance; //3 Component[] comp = new Component[2]; Edge[] edg = new Edge[2]; Face[] faces = new Face[2]; ConstraintReference[] constref = new ConstraintReference[2]; comp[0] = (NXOpen.Assemblies.Component)Assem.ComponentAssembly.RootComponent.FindObject(constinfo.ConstRef1[0]); comp[1] = (NXOpen.Assemblies.Component)Assem.ComponentAssembly.RootComponent.FindObject(constinfo.ConstRef2[0]); faces[0] = (NXOpen.Face)comp[0].FindObject(constinfo.ConstRef1[1]); faces[1] = (NXOpen.Face)comp[1].FindObject(constinfo.ConstRef2[1]); for (int i = 0; i < 2; i++) { constref[i] = compoConst.CreateConstraintReference(comp[i], faces[i], false, false, false); } compoConst.SetExpression(""); }
//------------------------------------------------------------------------------ // NX Startup // This entry point activates the application at NX startup //Will work when complete path of the dll is provided to Environment Variable //USER_STARTUP or USER_DEFAULT //------------------------------------------------------------------------------ public static int Startup() { int retValue = 0; try { theProgram = new Program(); //string partPath = @"F:\TEST.prt"; //string partPath = @"F:\CASE\ASM.prt"; string partPath = @"F:\CASE1\Case_1-1_stp.prt"; PartLoadStatus PLD; Part workPart = theSession.Parts.OpenBaseDisplay(partPath, out PLD) as Part; if (workPart != null) { ComponentAssembly assembly = workPart.ComponentAssembly; Component rootComponent = assembly.RootComponent; //try {object flange1 = assembly.FindObject("FLANGE(10K_150A_G)_K3029930#1");} //catch(Exception ex) { theUI.NXMessageBox.Show("Null", NXMessageBox.DialogType.Error, ex.Message); } theProgram.Traverse(rootComponent); Component comp1_1 = rootComponent.FindObject("COMPONENT OIL_PIPE_TYPE1_ASSY-01 2") as Component; Component comp1 = comp1_1.FindObject("COMPONENT FLANGE(10K_150A_G)_K3029930#1 1") as Component; Component comp2_1 = rootComponent.FindObject("COMPONENT OIL_PIPE_TYPE1_ASSY-01 3") as Component; Component comp2 = comp2_1.FindObject("COMPONENT FLANGE(10K_150A_N)_K3034074#1 1") as Component; Part one = comp1.Prototype as Part; Part two = comp2.Prototype as Part; DatumPlane oneXY = null; DatumPlane twoXY = null; //foreach(Component leaf in theProgram.leafList) //{ // if(leaf.DisplayName == "FLANGE(10K_150A_G)_K3029930#1") // { // //comp1 = leaf; // one = leaf.Prototype as Part; // } // if (leaf.DisplayName == "FLANGE(10K_150A_N)_K3034074#1") // { // //comp2 = leaf; // two = leaf.Prototype as Part; // } //} if (one != null && two != null) { theProgram.GetXYPlane(one, out oneXY); theProgram.GetXYPlane(two, out twoXY); oneXY = comp1.FindOccurrence(oneXY) as DatumPlane; twoXY = comp2.FindOccurrence(twoXY) as DatumPlane; } //Tag tag1 = theUfSession.Assem.AskPartOccurrence(oneXY.Tag); try { ComponentPositioner positioner1 = assembly.Positioner; positioner1.BeginAssemblyConstraints(); Constraint constraint1 = positioner1.CreateConstraint(true); ComponentConstraint componentConstraint1 = constraint1 as ComponentConstraint; componentConstraint1.ConstraintAlignment = Constraint.Alignment.ContraAlign; componentConstraint1.ConstraintType = Constraint.Type.Touch; ConstraintReference ref1 = componentConstraint1.CreateConstraintReference(comp1, oneXY, false, false, false); ConstraintReference ref2 = componentConstraint1.CreateConstraintReference(comp2, twoXY, false, false, false); //componentConstraint1.FlipAlignment(); //componentConstraint1.SetAlignmentHint(NXOpen.Positioning.Constraint.Alignment.ContraAlign); } catch (Exception E) { theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, E.Message); } } PartSaveStatus ps; bool partSaved; theSession.Parts.SaveAll(out partSaved, out ps); theUfSession.Part.CloseAll(); } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("UI Styler", NXMessageBox.DialogType.Error, ex.Message); } return(retValue); }