此段是可以生成程序的完整代码,只有从坐标(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 <uf_defs.h>
#include <uf_cam.h>
#include <uf_udop.h>
#include <uf_oper.h>
#include <uf_path.h>
#include <uf.h>
#include <uf_exit.h>
#include <stdio.h> 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 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 ===============================================================================
*/ 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.Collections
Imports System.Collections.Generic
Imports System.IO
Imports System.Globalization
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UIStyler Namespace 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 Class
End Namespace

VB.NET源码

原文地址:http://www.cnblogs.com/bizca/p/4667874.html

NX开发 刀路生成的更多相关文章

  1. 基于CkEditor实现.net在线开发之路(7)列表页面开发动作介绍

    一个列表页面不止是查询,它也包含了很多业务上功能的实现,这些业务功能的实现的逻辑我称之为动作.如触发单击按钮删除数据,更改业务表数据,调用webService,调用WCF接口,弹出新窗体新增.修改.查 ...

  2. 饿了么基于Vue2.0的通用组件开发之路(分享会记录)

    Element:一套通用组件库的开发之路 Element 是由饿了么UED设计.饿了么大前端开发的一套基于 Vue 2.0 的桌面端组件库.今天我们要分享的就是开发 Element 的一些心得. 官网 ...

  3. 基于CkEditor实现.net在线开发之路(1)

    我以前的公司使用office sharepoint designer为界面设计器,嵌套各种自定义控件,进行各种管理软件,工作流的开发,遇到比较复杂的逻辑,则采用本地写类库,生成DLL上传到服务器,通过 ...

  4. Android流媒体开发之路二:NDK开发Android端RTMP直播推流程序

    NDK开发Android端RTMP直播推流程序 经过一番折腾,成功把RTMP直播推流代码,通过NDK交叉编译的方式,移植到了Android下,从而实现了Android端采集摄像头和麦克缝数据,然后进行 ...

  5. 喵的Unity游戏开发之路 - 玩家控制下的球的滑动

  6. 喵的Unity游戏开发之路 - 游泳

    原文: https://mp.weixin.qq.com/s/-ERFNB1GRZ6UAkHOhP9UQw 很多童鞋没有系统的Unity3D游戏开发基础,也不知道从何开始学.为此我们精选了一套国外优秀 ...

  7. 喵的Unity游戏开发之路 - 多场景:场景加载

    如果丢失格式.图片或视频,请查看原文:https://mp.weixin.qq.com/s/RDVMg6l41uc2IHBsscc0cQ 很多童鞋没有系统的Unity3D游戏开发基础,也不知道从何开始 ...

  8. [敏杰开发]知识路书——图形化文献管理大师 Beta版发布喽!!!

    [敏杰开发]知识路书--图形化文献管理大师 Beta版发布喽!!! 一.总览 项目名称:知识路书 发布形式:网页应用 发布地址:http://roadmap.imcoming.top 二.运行环境与使 ...

  9. WEB开发之路——基础部分

    WEB开发之路 受BBC的<BBC: Brain Story>和<BBC: The Brain - A Secret History>的影响,我一直有志于探究人类大脑,2015 ...

随机推荐

  1. MybatisPlus(一)——

    MybatisPlus https://www.cnblogs.com/JohanChan/p/14982870.html

  2. windows操作系统和java常识

    一.java5和java8版本更新很大,现在都是java8; 二.数据存储最小单位Byte字节八个比特位: 三.没有图形操作界面的windows系统: 四.java语言跨平台性:JVM充当不同操作系统 ...

  3. 【第一篇】- Git 教程之Spring Cloud直播商城 b2b2c电子商务技术总结

    Git 教程 Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制 ...

  4. Vue3.x全家桶+vite+TS-构建Vue3基本框架

    目录 一.搭建基础项目 1.vite创建项目 3.运行项目 2.环境变量设置介绍 vite配置多环境打包 二.配置Router 1.安装路由 2.配置路由 3.引入 三.配置Vuex 1.安装vuex ...

  5. kubectl apply部署时可以用 --record 方便记录版本 和回退

    1.部署时正常时下面的 kubectl apply -f http.yaml 2.如果修改文件文件重新部署或者之前有上一个版本的  想回退上一个的 可以无感知的回退回去 不影响业务 其中http-de ...

  6. 【PHP数据结构】图的遍历:深度优先与广度优先

    在上一篇文章中,我们学习完了图的相关的存储结构,也就是 邻接矩阵 和 邻接表 .它们分别就代表了最典型的 顺序存储 和 链式存储 两种类型.既然数据结构有了,那么我们接下来当然就是学习对这些数据结构的 ...

  7. 微信公众号授权获取code带多个参数 丢失参数

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&re ...

  8. Java开发基础平台带集成的审批工作流

    前言 activiti工作流,企业erp.oa.hr.crm等审批系统轻松落地,请假审批demo从流程绘制到审批结束实例. 一.项目形式 springboot+vue+activiti集成了activ ...

  9. LateX出坑

    1 公式是用$ 包围着的  $ 2 \begin{equation} 里面的公式自动编号   \end{equation} 要达成这样的效果,暂时想到如下方法: 1 \begin{equation} ...

  10. httprunner版本没有更新问题

    使用命令行创建虚拟环境,创建脚手架目录后,使用pycharm打开所创建的脚手架目录. 执行:hrun demo_testcase_request.yml 提示: E:\hrun_ven\test_hr ...