博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NX开发 刀路生成
阅读量:5081 次
发布时间:2019-06-12

本文共 11742 字,大约阅读时间需要 39 分钟。

此段是可以生成程序的完整代码,只有从坐标(10,10,10)到(500,500,500)一根刀轨。

motion_ptr->feed_value 的值为0时生成G00,非0时生成G01。
此代码只有直线,生成圆弧的方法类似,可参考open-api函数库里的ufd_cam_udop.c文件。
加工CAM的入口函数是udop,此入口函数和常用的UG二次开发入口函数ufusr并列,不需要在ufusr中调用,直接在ufusr所在的CPP文件中写入udop函数即可,或者将udop放在一单独的.c文件中,在ufusr所在的CPP文件中包含也可以,#include "path.c"。
编译出来的dll文件不能像普通的二次开发文件一样直接用Crtl + U 调用,必须先在ugii_env.dat文件中定义好变量,例如abs=d:\path.dll。此abc即是变量,然后使用UG的自定义加工模板调用此变量就OK了。

#include 
#include
#include
#include
#include
#include
#include
#include
extern void udop(char *param, int *status, int parm_len){ char op_name[UF_OPER_OPNAME_LEN]; UF_UDOP_id_t udop_id; UF_UDOP_purpose_t purpose; UF_OPER_id_t oper_id; UF_PATH_id_t path_id; UF_CAM_exit_id_t exit_id = (UF_CAM_exit_id_t)param; UF_initialize(); UF_UDOP_ask_udop( exit_id, &udop_id); UF_UDOP_ask_oper( udop_id, &oper_id); UF_UDOP_ask_purpose( udop_id, &purpose); UF_OPER_ask_name( oper_id, op_name); UF_OPER_ask_path( oper_id, &path_id); if( purpose == UF_UDOP_GENERATE ) { /************ To input GOTO/ motion*************/ UF_PATH_linear_motion_t motion,*motion_ptr = &motion; motion_ptr->feed_value = 0.0; motion_ptr->feed_unit = UF_PATH_FEED_UNIT_NONE; motion_ptr->type = UF_PATH_MOTION_TYPE_CUT; motion_ptr->tool_axis[0] =0.0; motion_ptr->tool_axis[1] =0.0; motion_ptr->tool_axis[2] =1.0; motion_ptr->position[0] =10.0; motion_ptr->position[1] =10.0; motion_ptr->position[2] =10.0; UF_PATH_create_linear_motion( path_id, motion_ptr); motion_ptr->position[0] =500.0; motion_ptr->position[1] =500.0; motion_ptr->position[2] =500.0; UF_PATH_create_linear_motion( path_id, motion_ptr); UF_PATH_cutcom_t cutcom_data; cutcom_data.cutcom_mode = UF_PATH_CUTCOM_ON; cutcom_data.plane_type = UF_PATH_PLANE_TYPE_XY; cutcom_data.cutcom_on_status = UF_PATH_CUTCOM_ON_BEFORE_ENGAGE; cutcom_data.cutcom_off_status = UF_PATH_CUTCOM_OFF_AFTER_RETRACT; cutcom_data.adjust_register = 2; cutcom_data.full_cutcom_output = TRUE; cutcom_data.adjust_flag = TRUE; UF_PATH_create_cutcom( path_id, &cutcom_data, NULL ); UF_PATH_end_tool_path( path_id ); } UF_terminate();}
C语言

 

以下是.NET例子

/*=============================================================================                    Copyright (c) 2009 Siemens PLM Software                     Unpublished - All rights reserved=============================================================================== =============================================================================File description: Sample NX/Open ApplicationThis is basic example of how to write a UDOP entry in CSTo use this after you build the dll as cs_udop.dll1) Put the dll in a folder - for example c:\my_udops\2) Create an system environment variable MYCORP_UDOP_2 and set it to   c:\my_udops\cs_udop.dll3) Now in NX CAM create a MILL_USER and in the UI enter MYCORP_UDOP_2   for the "CAM API Exit Name in the user interface   press either "User Parameters" or "Generate" to see the results===============================================================================*/using System;using System.Collections;using System.Collections.Generic;using System.IO;using System.Globalization;using NXOpen;using NXOpen.UF;using NXOpen.UIStyler;namespace test1{    public class Class1    {        //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        //       SESSION ATTRIBUTES        //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        // Native .NET Session        internal static NXOpen.Session Nts = Session.GetSession();        // User Function Session        internal static NXOpen.UF.UFSession Ufs = UFSession.GetUFSession();        // Native UI Session        internal static NXOpen.UI Uis = UI.GetUI();        // Native CAM Session        internal static NXOpen.CAM.CAMSession Cams = Nts.CAMSession;        // Native Remote Utilities Session        internal static NXOpen.RemoteUtilities Rus = RemoteUtilities.GetRemoteUtilities();        //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        //       SESSION OBJECT ATTRIBUTES        //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        // Native Listing Window        internal static NXOpen.ListingWindow LW = Nts.ListingWindow;        // Native Message Box        internal static NXOpen.NXMessageBox MBox = Uis.NXMessageBox;        // WorkPart        internal static NXOpen.Part WorkPart = Nts.Parts.Work;        // ************************************************************************************        public static void Main()        {        }        public static int udop(string inString)        {            IntPtr udopPtr = IntPtr.Zero;            IntPtr operPtr = IntPtr.Zero;            UFUdop.Purpose purpose;            string operName = string.Empty;            IntPtr pathPtr = IntPtr.Zero;            Ufs.Udop.AskUdop(IntPtr.Zero, out udopPtr);            Ufs.Udop.AskOper(udopPtr, out operPtr);            Ufs.Udop.AskPurpose(udopPtr, out purpose);            Ufs.Oper.AskName(operPtr, out operName);            Ufs.Oper.AskPath(operPtr, out pathPtr);            if (purpose == UFUdop.Purpose.UserParams)            {                MBox.Show("User Params", NXMessageBox.DialogType.Information, "User Params");            }            if (purpose == UFUdop.Purpose.Generate)            {                Ufs.Path.InitToolPath(pathPtr);                UFPath.LinearMotion linearMotion;                linearMotion.feed_value = 0;                linearMotion.type = UFPath.MotionType.MotionTypeCut;                linearMotion.feed_unit = UFPath.FeedUnit.FeedUnitNone;                double[] pos = { 0, 0, 0 };                linearMotion.position = pos;                double[] tAxis = { 0, 0, 1 };                linearMotion.tool_axis = tAxis;                Ufs.Path.CreateLinearMotion(pathPtr, ref linearMotion);                linearMotion.position[0] = 0;                linearMotion.position[1] = 0.707;                linearMotion.position[2] = 0.707;                linearMotion.tool_axis[0] = 0;                linearMotion.tool_axis[1] = 1;                linearMotion.tool_axis[2] = 0;                Ufs.Path.CreateLinearMotion(pathPtr, ref linearMotion);                linearMotion.position[0] = 1;                linearMotion.position[1] = 0;                linearMotion.position[2] = 0;                linearMotion.tool_axis[0] = 0;                linearMotion.tool_axis[1] = 1;                linearMotion.tool_axis[2] = 1;                Ufs.Path.CreateLinearMotion(pathPtr, ref linearMotion);                Ufs.Path.EndToolPath(pathPtr);            }            return 0;        }        // ************************************************************************************        public static int GetUnloadOption(string arg)        {            return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);        }    }}
C#源码

 

'=============================================================================''                    Copyright (c) 2009 Siemens PLM Software '                    Unpublished - All rights reserved''===============================================================================' '============================================================================='File description: Sample NX/Open Application''This is basic example of how to write a UDOP entry in CS'To use this after you build the dll as cs_udop.dll'1) Put the dll in a folder - for example c:\my_udops\'2) Create an system environment variable MYCORP_UDOP_2 and set it to'   c:\my_udops\cs_udop.dll'3) Now in NX CAM create a MILL_USER and in the UI enter MYCORP_UDOP_2'   for the "CAM API Exit Name in the user interface'   press either "User Parameters" or "Generate" to see the results''==============================================================================='Imports System.CollectionsImports System.Collections.GenericImports System.IOImports System.GlobalizationImports NXOpenImports NXOpen.UFImports NXOpen.UIStylerNamespace test1    Public Class Class1        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        '       SESSION ATTRIBUTES        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        ' Native .NET Session        Friend Shared Nts As NXOpen.Session = Session.GetSession()        ' User Function Session        Friend Shared Ufs As NXOpen.UF.UFSession = UFSession.GetUFSession()        ' Native UI Session        Friend Shared Uis As NXOpen.UI = UI.GetUI()        ' Native CAM Session        Friend Shared Cams As NXOpen.CAM.CAMSession = Nts.CAMSession        ' Native Remote Utilities Session        Friend Shared Rus As NXOpen.RemoteUtilities = RemoteUtilities.GetRemoteUtilities()        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        '       SESSION OBJECT ATTRIBUTES        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''        ' Native Listing Window        Friend Shared LW As NXOpen.ListingWindow = Nts.ListingWindow        ' Native Message Box        Friend Shared MBox As NXOpen.NXMessageBox = Uis.NXMessageBox        ' WorkPart        Friend Shared WorkPart As NXOpen.Part = Nts.Parts.Work        ' ************************************************************************************        Public Shared Sub Main()        End Sub        Public Shared Function udop(inString As String) As Integer            Dim udopPtr As IntPtr = IntPtr.Zero            Dim operPtr As IntPtr = IntPtr.Zero            Dim purpose As UFUdop.Purpose            Dim operName As String = String.Empty            Dim pathPtr As IntPtr = IntPtr.Zero            Ufs.Udop.AskUdop(IntPtr.Zero, udopPtr)            Ufs.Udop.AskOper(udopPtr, operPtr)            Ufs.Udop.AskPurpose(udopPtr, purpose)            Ufs.Oper.AskName(operPtr, operName)            Ufs.Oper.AskPath(operPtr, pathPtr)            If purpose = UFUdop.Purpose.UserParams Then                MBox.Show("User Params", NXMessageBox.DialogType.Information, "User Params")            End If            If purpose = UFUdop.Purpose.Generate Then                Ufs.Path.InitToolPath(pathPtr)                Dim linearMotion As UFPath.LinearMotion                linearMotion.feed_value = 0                linearMotion.type = UFPath.MotionType.MotionTypeCut                linearMotion.feed_unit = UFPath.FeedUnit.FeedUnitNone                Dim pos As Double() = {
0, 0, 0} linearMotion.position = pos Dim tAxis As Double() = {
0, 0, 1} linearMotion.tool_axis = tAxis Ufs.Path.CreateLinearMotion(pathPtr, linearMotion) linearMotion.position(0) = 0 linearMotion.position(1) = 0.707 linearMotion.position(2) = 0.707 linearMotion.tool_axis(0) = 0 linearMotion.tool_axis(1) = 1 linearMotion.tool_axis(2) = 0 Ufs.Path.CreateLinearMotion(pathPtr, linearMotion) linearMotion.position(0) = 1 linearMotion.position(1) = 0 linearMotion.position(2) = 0 linearMotion.tool_axis(0) = 0 linearMotion.tool_axis(1) = 1 linearMotion.tool_axis(2) = 1 Ufs.Path.CreateLinearMotion(pathPtr, linearMotion) Ufs.Path.EndToolPath(pathPtr) End If Return 0 End Function ' ************************************************************************************ Public Shared Function GetUnloadOption(arg As String) As Integer Return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately) End Function End ClassEnd Namespace
VB.NET源码

原文地址: 

转载于:https://www.cnblogs.com/bizca/p/4667874.html

你可能感兴趣的文章
亲近用户—回归本质
查看>>
中文脏话识别的解决方案
查看>>
CSS之不常用但重要的样式总结
查看>>
Python编译错误总结
查看>>
URL编码与解码
查看>>
日常开发时遇到的一些坑(三)
查看>>
Eclipse 安装SVN插件
查看>>
深度学习
查看>>
TCP粘包问题及解决方案
查看>>
构建之法阅读笔记02
查看>>
添加按钮
查看>>
移动端页面开发适配 rem布局原理
查看>>
Ajax中文乱码问题解决方法(服务器端用servlet)
查看>>
会计电算化常考题目一
查看>>
阿里云服务器CentOS6.9安装Mysql
查看>>
剑指offer系列6:数值的整数次方
查看>>
js 过滤敏感词
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
软件开发和软件测试,我该如何选择?(蜗牛学院)
查看>>
基本封装方法
查看>>