移动组件
移动组件
小猛Hit 发表于8个月前
移动组件
  • 发表于 8个月前
  • 阅读 2
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: 用NXOPEN去实现组件的移动需要用到positioner和network,相对比较关键的问题就是求由位置A变换到位置B的变换矩阵,下文中的CalTrans方法是用UFUN计算的变换矩阵。
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using NXOpen; 
using NXOpen.UF; 

namespace DragComp 
{ 
    public class Drag 
    { 
        private  UFSession theUfSession = UFSession.GetUFSession(); 
        private  Session theSession = Session.GetSession(); 
        public double[] currentMtx44 = new double[16]; 
        private NXOpen.Positioning.ComponentNetwork netWork; 
        private NXOpen.Positioning.ComponentPositioner positioner; 
        public Drag(Part workPart,double[] current) 
        { 
            this.positioner = workPart.ComponentAssembly.Positioner; 
            this.netWork = (NXOpen.Positioning.ComponentNetwork)this.positioner.EstablishNetwork(); 
            currentMtx44 = current; 
        } 

        /// <summary> 
        /// Transes the comps. 
        /// </summary> 
        /// <param name="component">The component.</param> 
        /// <param name="trans">The trans.</param> 
        public void Move(NXOpen.Assemblies.Component component, double[] position) 
        { 
            Array.Resize(ref position, 16); 
            double[] trans = CalTrans(position); 

            Matrix3x3 matrix = new Matrix3x3(); 
            matrix.Xx = trans[0];matrix.Xy = trans[4];matrix.Xz = trans[8]; 
            matrix.Yx = trans[1]; matrix.Yy = trans[5]; matrix.Yz = trans[9]; 
            matrix.Zx = trans[2]; matrix.Zy = trans[6]; matrix.Zz = trans[10]; 
            Vector3d vector = new Vector3d(trans[3], trans[7], trans[11]); 

            if ( netWork == null) 
            { 
                 positioner = Session.GetSession().Parts.Work.ComponentAssembly.Positioner; 
                 netWork = (NXOpen.Positioning.ComponentNetwork) positioner.EstablishNetwork(); 
            } 

             netWork.SetMovingGroup(new NXOpen.Assemblies.Component[] { component }); 
             netWork.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.InUsed; 
             netWork.RemoveAllConstraints(); 
             netWork.BeginDrag(); 
             positioner.BeginMoveComponent(); 
             netWork.MoveObjectsState = true; 
             netWork.DragByTransform(vector, matrix); 
             positioner.EndMoveComponent(); 
             netWork.EndDrag(); 
            //更新 
            currentMtx44 = position; 
        } 

        private double[] CalTrans(double[] position) 
        { 
            double[] trans = new double[16]; 
            double[] invertCurrentMtx44 = new double[16]; 
            theUfSession.Mtx4.Invert(currentMtx44, invertCurrentMtx44); 
            theUfSession.Mtx4.Multiply(invertCurrentMtx44, position, trans); 
            double[] translation = new double[3]; 
            theUfSession.Mtx4.AskTranslation(trans, translation); 
            double[] rotation = new double[9]; 
            theUfSession.Mtx4.AskRotation(trans, rotation); 
            theUfSession.Mtx3.Transpose(rotation, rotation); 
            theUfSession.Mtx4.Initialize(1, translation, rotation, trans); 
            return trans; 
        } 

    } 
}

 

共有 人打赏支持
粉丝 0
博文 5
码字总数 1184
×
小猛Hit
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: