青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

青华模具培训学院
查看: 1890|回复: 1

[原创] 根据Object.Tag导出part部件

[复制链接]
发表于 2013-11-14 16:17 | 显示全部楼层 |阅读模式
'如何得到Object.Tag
0 A8 C4 T; P, P. P% ^8 o7 r7 L. X '遍历得到所有body的Tag
5 Q, X  h* u$ l. j. a( `. h6 P 'theUfSession.Obj.CycleObjsInPart(workPart.Tag, 70, objTag)/ v0 E, B# a/ n" J# @

- y3 V! t1 u+ jSub ExportPart(ByRef part_tag As Tag)
' x9 _- ]/ g2 J+ V3 c" h        Dim theSession As Session = Session.GetSession()
/ B/ _* i  ]+ z( t/ b; P8 C        Dim theUI As UI = UI.GetUI()8 H7 a. t3 G. S7 {, X
        Dim theUfSession As UFSession = UFSession.GetUFSession()
4 ]3 i& I. |1 ?        Dim workPart As Part = theSession.Parts.Work2 g* t! [6 R* a0 P+ I7 N  l: c
        Dim displayPart As Part = theSession.Parts.Display( i- T; Y( k& }
        Dim body As Body = CType(NXObjectManager.Get(part_tag), Body)4 ]- L- B. U" f/ x9 S# m
        Dim part_id As String = body.GetStringAttribute("part_id") '得到属性“part_id”作为零件名称,可以自己设置其他内容
4 K+ d# N7 T5 b1 E3 X5 c        Try' R, @8 I+ K) X8 C
            Dim fileNew1 As FileNew
' I7 O: u1 g# R9 k+ o            fileNew1 = theSession.Parts.FileNew()
: \% `" H* l" _: j& l0 C            fileNew1.TemplateFileName = "model-plain-1-mm-template.prt" '导出模板名称
+ _* e0 |5 L) r7 g! f            fileNew1.Application = FileNewApplication.Modeling
% |  @# c) B! i8 L) I, {            fileNew1.Units = Part.Units.Millimeters
( `. B$ k; d5 Z- R; O* f            fileNew1.TemplateType = FileNewTemplateType.Item
. E- J9 H5 f) V, z7 r8 ^. O            fileNew1.NewFileName = "D:\" & part_id & ".prt"  '保存路径8 r! X9 O. {6 Z7 M6 N
            fileNew1.MasterFileName = ""
1 t2 I' Y; V: z- a- w. d4 B+ x            fileNew1.UseBlankTemplate = False
$ \- a: R" \5 O8 p. L            fileNew1.MakeDisplayedPart = False% w" T2 b. a# U. ^

9 m' j$ t  p, z3 K$ U. l            Dim createNewComponentBuilder As Assemblies.CreateNewComponentBuilder- x; z) z0 `9 Q- [7 b* x# z; w
            createNewComponentBuilder = workPart.AssemblyManager.CreateNewComponentBuilder()* \# f" T& G2 _7 @  T/ E
            createNewComponentBuilder.ReferenceSetName = "Model"* ]* v8 u2 m4 u9 ]
            createNewComponentBuilder.OriginalObjectsDeleted = True '一般设置成False,删除源文件中的对象
6 ~2 u6 z2 H8 }. I1 T, B            createNewComponentBuilder.NewComponentName = part_id
% D: H- n" ~, N1 ^7 M6 G! v            Dim added1 As Boolean
: g2 \: L' z: o: S- X3 Z            added1 = createNewComponentBuilder.ObjectForNewComponent.Add(body)4 I+ ~9 [" @! B2 R
            createNewComponentBuilder.NewFile = fileNew1
' N% L, L- K, F) _  S4 A1 Z1 ]            Dim nXObject1 As NXObject
2 r* L) v) n$ {5 \. U' b- p            nXObject1 = createNewComponentBuilder.Commit()% a" i0 S' @& E: r( B
            createNewComponentBuilder.Destroy()
9 v2 f1 K( h3 ?        Catch ex As Exception7 K: a; T! X. l9 [
            MsgBox(ex.Message)
& i8 S/ k( f* M9 k+ F+ d: w        End Try
5 g! m, A9 d1 }/ |    End Sub& w0 K% E  N% ?% ~1 `
发表于 2013-11-18 16:48 | 显示全部楼层
NXOPEN .NET很好的例子,顶LZ一个!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|关于我们|sitemap|小黑屋|Archiver|手机版|UG网-UG技术论坛-青华数控模具培训学校 ( 粤ICP备15108561号 )

GMT+8, 2025-6-29 02:41 , Processed in 0.104796 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表