.net语言 开发UG NX二次开发 NX12


1.导出图片

 1 Imports System
 2 Imports NXOpen.uf
 3 
 4 Module NXJournal
 5 
 6     Sub Main(ByVal args() As String)
 7         Dim disp As UFDisp = UFSession.GetUFSession().Disp
 8 
 9         Dim path As String = "C:\Users\admin\Desktop\" '保存目录
10         Dim imgtype As UFDisp.ImageFormat = UFDisp.ImageFormat.Jpeg '图片类型
11         Dim BGcolor As UFDisp.BackgroundColor = UFDisp.BackgroundColor.White '背景色白色
12 
13         Dim StrDir As String  = ""
14 
15         Dim UFS As UFSession = UFSession.GetUFSession()
16         UFS.Part.AskPartName(UFS.Part.AskDisplayPart(), StrDir)    '获取当前路径
17         StrDir = StrDir.Replace(".prt", "")
18         StrDir = Mid(StrDir, InStrRev(StrDir, "\")+1, Len(StrDir)) '截取文件名
19         Dim dt As Date
20         dt = Now '获取当前日期
21 
22         StrDir += Format(dt, "  mmss")  '日期中格式出(分)(秒)添加文件名后
23         path += StrDir & ".jpg"
24         disp.CreateImage(path, imgtype, BGcolor)
25     End Sub
26 End Module

 2.修改图层类别名称

 1 Imports NXOpen
 2 Imports NXOpen.UF
 3 Module NXJournal
 4     Sub Main(ByVal args() As String)
 5         Dim ufs As UFSession = UFSession.GetUFSession()
 6         Dim UFl As UFLayer = UFSession.GetUFSession().Layer
 7         Dim category_layerTAG As Tag = Tag.Null
 8         UFl.AskCategoryTag("原类名称", category_layerTAG)
 9         UFl.EditCategoryName(category_layerTAG, "修改后名称")
10     End Sub
11 End Module

 3.遍历图层类别名称

 1 Option Strict Off
 2 Imports NXOpen
 3 Imports NXOpen.UF
 4 Imports NXOpen.UF.UFLayer
 5 Imports NXOpen.UF.UFConstants
 6 
 7 Module category_layerinfo_demo
 8     Sub Main()
 9         Dim UFS As UFSession = UFSession.GetUFSession()
10         Dim UFl As UFLayer = UFSession.GetUFSession().Layer
11         Dim category_layerinfo As CategoryInfo
12         Dim category_layerTAG As Tag = Tag.Null
13         UFS.Obj.CycleObjsInPart(UFS.Part.AskDisplayPart(), UF_layer_category_type, category_layerTAG)
14         While category_layerTAG <> Tag.Null
15             UFl.AskCategoryInfo(category_layerTAG, category_layerinfo)
16             MsgBox(category_layerinfo.name) 'name名称  descr 描述
17 
18             UFS.Obj.CycleObjsInPart(UFS.Part.AskDisplayPart(), UF_layer_category_type, category_layerTAG)
19         End While
20     End Sub
21 
22 End Module

 4.获取文件路径

 1 Imports NXOpen
 2 Imports NXOpen.UF
 3 Module NXJournal
 4 Sub Main (ByVal args() As String)
 5       Dim UFS As UFSession = UFSession.GetUFSession()
 6       Dim StrDir As String = ""
 7       UFS.Part.AskPartName(UFS.Part.AskDisplayPart(), StrDir)
 8       MsgBox(StrDir)
 9 End Sub
10 End Module

相关