/// <summary> /// 移动部件并复制部件 /// </summary> /// <param name="compObj"></param> /// <param name="endPt"></param> /// <param name="mat"></param> /// <returns></returns> public static NXOpen.Assemblies.Component MoveCompCopyPart(NXOpen.Assemblies.Component compObj, Vector3d endPt, Matrix4 mat) { Part workPart = theSession.Parts.Work; Matrix4 invers = mat.GetInversMatrix(); invers.ApplyVec(ref endPt); NXOpen.Positioning.ComponentPositioner componentPositioner1; componentPositioner1 = workPart.ComponentAssembly.Positioner; //组件定位 componentPositioner1.ClearNetwork(); //删除定位器 NXOpen.Assemblies.Arrangement arrangement1 = (NXOpen.Assemblies.Arrangement)workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"); //布局 componentPositioner1.PrimaryArrangement = arrangement1; //主要布局 componentPositioner1.BeginMoveComponent(); //开始移动组件 bool allowInterpartPositioning1; allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning; //首选项的部件间的定位 NXOpen.Positioning.Network network1; network1 = componentPositioner1.EstablishNetwork(); //建立 NXOpen.Positioning.ComponentNetwork componentNetwork1 = (NXOpen.Positioning.ComponentNetwork)network1; componentNetwork1.MoveObjectsState = true; //移动对象状态 NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null; componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component; //显示组件 componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing; //现有安排模式 componentNetwork1.RemoveAllConstraints(); //删除约束 NXOpen.NXObject[] movableObjects1 = new NXOpen.NXObject[1]; movableObjects1[0] = compObj; NXOpen.Assemblies.Component[] components1 = new NXOpen.Assemblies.Component[1]; components1[0] = compObj; NXOpen.Assemblies.Component[] newComponents1 = workPart.ComponentAssembly.CopyComponents(components1); componentNetwork1.SetMovingGroup(newComponents1); //设置移动组件 componentNetwork1.Solve(); //解除约束 bool loaded1; loaded1 = componentNetwork1.IsReferencedGeometryLoaded(); //参考几何加载 componentNetwork1.BeginDrag(); //操作即将开始 NXOpen.Vector3d translation1 = new NXOpen.Vector3d(endPt.X, endPt.Y, endPt.Z); componentNetwork1.DragByTranslation(translation1); //移动 componentNetwork1.EndDrag(); //操作结束 componentNetwork1.ResetDisplay(); //返回到模型上 componentNetwork1.ApplyToModel(); //应该到当前模型 componentNetwork1.Solve(); //解除约束 componentPositioner1.ClearNetwork(); //清空 int nErrs1; nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1); //更新 componentPositioner1.ClearNetwork(); componentPositioner1.DeleteNonPersistentConstraints(); componentPositioner1.EndMoveComponent(); NXOpen.Assemblies.Arrangement nullNXOpen_Assemblies_Arrangement = null; componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement; return(newComponents1[0]); }
/// <summary> /// 移动部件 /// </summary> /// <param name="compObj"></param> /// <param name="endPt"></param> /// <param name="mat"></param> /// <returns></returns> public static void MoveCompPartForCsys(Matrix4 mat, params NXOpen.Assemblies.Component[] compObj) { Part workPart = theSession.Parts.Work; Point3d absPt = new Point3d(); mat.ApplyPos(ref absPt); Vector3d translation = new Vector3d(absPt.X, absPt.Y, absPt.Z); NXOpen.Positioning.ComponentPositioner componentPositioner1; componentPositioner1 = workPart.ComponentAssembly.Positioner; //组件定位 componentPositioner1.ClearNetwork(); //删除定位器 NXOpen.Assemblies.Arrangement arrangement1 = (NXOpen.Assemblies.Arrangement)workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"); //布局 componentPositioner1.PrimaryArrangement = arrangement1; //主要布局 componentPositioner1.BeginMoveComponent(); //开始移动组件 bool allowInterpartPositioning1; allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning; //首选项的部件间的定位 NXOpen.Positioning.Network network1; network1 = componentPositioner1.EstablishNetwork(); //建立 NXOpen.Positioning.ComponentNetwork componentNetwork1 = (NXOpen.Positioning.ComponentNetwork)network1; componentNetwork1.MoveObjectsState = true; //移动对象状态 NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null; componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component; //显示组件 componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing; //现有安排模式 componentNetwork1.RemoveAllConstraints(); //删除约束 componentNetwork1.SetMovingGroup(compObj); //设置移动组件 componentNetwork1.Solve(); //解除约束 bool loaded1; loaded1 = componentNetwork1.IsReferencedGeometryLoaded(); //参考几何加载 componentNetwork1.BeginDrag(); //操作即将开始 componentNetwork1.DragByTransform(translation, mat.GetMatrix3()); //移动 componentNetwork1.EndDrag(); //操作结束 componentNetwork1.ResetDisplay(); //返回到模型上 componentNetwork1.ApplyToModel(); //应该到当前模型 componentNetwork1.Solve(); //解除约束 componentPositioner1.ClearNetwork(); //清空 int nErrs1; nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1); //更新 componentPositioner1.ClearNetwork(); componentPositioner1.DeleteNonPersistentConstraints(); componentPositioner1.EndMoveComponent(); NXOpen.Assemblies.Arrangement nullNXOpen_Assemblies_Arrangement = null; componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement; }