NX Open 切削层加载
2015-06-16 14:36
288 查看
UF_CUT_LEVELS_load
Loads the current cut levels for the specified operation into the data
structure UF_CUT_LEVELS_t.
在.NET下面使用方法为NXOpen.UF.UFCutLevels.Load(ByVal operation_tag As
NXOpen.Tag, ByRef cut_levels_ptr_addr() As
NXOpen.UF.UFCutLevels.CutLevelsStruct)
可是你想加载成功,是不可能的。我觉得是在封装API库的时候出了点问题。
以下源代码会引发异常:
解决办法重新封装UF_CUT_LEVELS_load
以下为源代码:
调用方法如下:
这样就解决了问题,不过缺陷是:由于本人技术有限,没有卸载非托管代码使用的的内存。还望大牛们赐教!!!
Loads the current cut levels for the specified operation into the data
structure UF_CUT_LEVELS_t.
在.NET下面使用方法为NXOpen.UF.UFCutLevels.Load(ByVal operation_tag As
NXOpen.Tag, ByRef cut_levels_ptr_addr() As
NXOpen.UF.UFCutLevels.CutLevelsStruct)
可是你想加载成功,是不可能的。我觉得是在封装API库的时候出了点问题。
以下源代码会引发异常:
解决办法重新封装UF_CUT_LEVELS_load
以下为源代码:
</pre><pre name="code" class="vb">#Region "UF_CUT_LEVELS_load" Friend Function CreateException(ByVal errorCode As Integer) As NXOpen.NXException Return NXOpen.NXException.Create(errorCode) End Function <DllImport("libufun.dll", EntryPoint:="UF_CUT_LEVELS_load", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _ Private Function _CUT_LEVELS_load(ByVal operation_tag As Tag, ByRef cut_levels_ptr_addr As IntPtr) As Integer End Function Private Structure _CutLevelsStruct Public num_levels As Integer Public cut_levels As IntPtr Public num_top_off_levels As Integer Public top_off_levels As IntPtr End Structure ''' <summary> ''' 加载切削层 ''' </summary> ''' <param name="operation_tag">操作tag值</param> ''' <param name="cut_levels_ptr_addr">切削层参数结构</param> ''' <remarks>重写加载切削层结构</remarks> Public Sub UF_CUT_LEVELS_load(ByVal operation_tag As NXOpen.Tag, ByRef cut_levels_ptr_addr As NXOpen.UF.UFCutLevels.CutLevelsStruct) Dim ptr As IntPtr NXOpen.Utilities.JAM.StartUFCall() Dim errorCode As Integer = _CUT_LEVELS_load(operation_tag, ptr) NXOpen.Utilities.JAM.EndUFCall() If errorCode <> 0 Then Throw CreateException(errorCode) End If Dim structArray As New _CutLevelsStruct cut_levels_ptr_addr = New NXOpen.UF.UFCutLevels.CutLevelsStruct structArray = DirectCast(Marshal.PtrToStructure(ptr, GetType(_CutLevelsStruct)), _CutLevelsStruct) cut_levels_ptr_addr.num_levels = structArray.num_levels Dim num As Integer = Marshal.SizeOf(GetType(NXOpen.UF.CutLevelSingle)) Dim num2 As Integer = structArray.num_levels Dim zero As Long = structArray.cut_levels.ToInt64 If num2 > 0 Then cut_levels_ptr_addr.cut_levels = New NXOpen.UF.CutLevelSingle(num2 - 1) {} End If If zero <> Nothing Then Dim num6 As Integer = 0 Do While num6 < num2 cut_levels_ptr_addr.cut_levels(num6) = DirectCast(Marshal.PtrToStructure(CType(zero, IntPtr), GetType(NXOpen.UF.CutLevelSingle)), NXOpen.UF.CutLevelSingle) zero = (zero + num) num6 += 1 Loop End If 'Marshal.FreeHGlobal(structArray.cut_levels) structArray.cut_levels = IntPtr.Zero cut_levels_ptr_addr.num_top_off_levels = structArray.num_top_off_levels num2 = structArray.num_top_off_levels num = Marshal.SizeOf(GetType(NXOpen.UF.CutLevelSingle)) zero = structArray.top_off_levels.ToInt64 If (num2 > 0) Then cut_levels_ptr_addr.top_off_levels = New NXOpen.UF.CutLevelSingle(num2 - 1) {} End If If (zero <> Nothing) Then For num6 = 0 To num2 - 1 cut_levels_ptr_addr.top_off_levels(num6) = DirectCast(Marshal.PtrToStructure(CType(zero, IntPtr), GetType(NXOpen.UF.CutLevelSingle)), NXOpen.UF.CutLevelSingle) zero = (zero + num) Next num6 End If 'Marshal.FreeHGlobal(structArray.top_off_levels) structArray.top_off_levels = IntPtr.Zero End Sub #End Region
调用方法如下:
这样就解决了问题,不过缺陷是:由于本人技术有限,没有卸载非托管代码使用的的内存。还望大牛们赐教!!!
相关文章推荐
- linux学习 命令ll后字段的解释(转)
- 【Java安全技术探索之路系列:Java可扩展安全架构】之二十二:SASL(三):SASL编程模型.md
- 【Java安全技术探索之路系列:Java可扩展安全架构】之二十一:SASL(二):SASL类和接口.md
- shell 读取某个目录下的所有文件
- linux 字符集更改
- 【Java安全技术探索之路系列:Java可扩展安全架构】之二十:SASL(一):SASL架构介绍.md
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十九:JGSS(三):JGSS编程模型.md
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十八:JGSS(二):JGSS类和接口
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十七:JGSS(一):JGSS架构介绍
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十六:JAAS(三):JAAS编程模型
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十五:JAAS(二):JAAS类和接口
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十四:JAAS(一):JAAS架构介绍
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十三:JSSE(三):JSSE编程模型
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十二:JSSE(二):JSSE类和接口
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十一:JSSE(一):JSSE架构介绍
- 【Java安全技术探索之路系列:Java可扩展安全架构】之十:JCP(三):JCP编程模型
- linux 命令——25 linux文件属性详解
- 【Java安全技术探索之路系列:Java可扩展安全架构】之九:JCP(二):JCP类和接口
- 【Java安全技术探索之路系列:Java可扩展安全架构】之八:JCP(一):JCP架构介绍
- svn+apache配置多版本库