青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
发表于 2013-11-14 16:17 | 显示全部楼层 |阅读模式
'如何得到Object.Tag
. p& P5 ]0 }( [( o$ k- H( B '遍历得到所有body的Tag
" E3 Z2 K/ b, \8 S 'theUfSession.Obj.CycleObjsInPart(workPart.Tag, 70, objTag)
% M) |: w# u5 ~4 G2 n
3 V" ~& f, t4 E1 R5 t& T2 t9 wSub ExportPart(ByRef part_tag As Tag)
& W0 j, M# x; V0 E4 Q        Dim theSession As Session = Session.GetSession()
- t  g  Q. F8 G% ]        Dim theUI As UI = UI.GetUI()8 @( E, E2 v$ y8 Q) B. |4 a' P
        Dim theUfSession As UFSession = UFSession.GetUFSession()
: P3 n' T% q, x: }* g; A& y( e        Dim workPart As Part = theSession.Parts.Work
0 z1 q/ @# \, e' E7 a. Q  }        Dim displayPart As Part = theSession.Parts.Display
. z$ o0 i# Y- X% o: y        Dim body As Body = CType(NXObjectManager.Get(part_tag), Body)0 A6 I7 X# _; N
        Dim part_id As String = body.GetStringAttribute("part_id") '得到属性“part_id”作为零件名称,可以自己设置其他内容9 s+ o/ ?4 t( C7 O) B  ?$ F
        Try8 U$ L9 B! \! m
            Dim fileNew1 As FileNew* l: Z9 t, [2 o# W5 c. \
            fileNew1 = theSession.Parts.FileNew(): A1 S) t: G6 c8 e9 }) z2 c
            fileNew1.TemplateFileName = "model-plain-1-mm-template.prt" '导出模板名称
7 d6 s6 }2 R6 s            fileNew1.Application = FileNewApplication.Modeling* a6 w# [; D$ g6 h5 I( |
            fileNew1.Units = Part.Units.Millimeters
& N# \6 P9 l- [) X6 G# R: T- p. L            fileNew1.TemplateType = FileNewTemplateType.Item& G$ x* B$ X. w3 R4 }
            fileNew1.NewFileName = "D:\" & part_id & ".prt"  '保存路径* r4 F- G& C' e8 h6 e; H: I- S+ p
            fileNew1.MasterFileName = ""4 O0 P" q4 x1 X1 Y
            fileNew1.UseBlankTemplate = False
& j1 P) {- }. p, _4 u7 v8 ?            fileNew1.MakeDisplayedPart = False% s/ [+ ~6 _, c  x/ H

8 G5 D4 @6 s% B. I) ]8 F            Dim createNewComponentBuilder As Assemblies.CreateNewComponentBuilder
" D) s+ A2 a! f! i8 }' t) K$ P            createNewComponentBuilder = workPart.AssemblyManager.CreateNewComponentBuilder()
! i& F: J' i* a- v5 d/ g  z/ c; K            createNewComponentBuilder.ReferenceSetName = "Model"6 ~5 K) h' |; F% p
            createNewComponentBuilder.OriginalObjectsDeleted = True '一般设置成False,删除源文件中的对象
3 I2 s! S: Z) q            createNewComponentBuilder.NewComponentName = part_id
* G/ o7 R  t% O+ d+ J" ]& Y. D4 f            Dim added1 As Boolean# b7 X$ {* U1 v! C" E& q
            added1 = createNewComponentBuilder.ObjectForNewComponent.Add(body)
( x! [, l: `  I/ D) T            createNewComponentBuilder.NewFile = fileNew1
- ^- @4 z6 k8 |! S* {" W+ _" t8 T            Dim nXObject1 As NXObject" k, a" |) F* M5 ~& B! {
            nXObject1 = createNewComponentBuilder.Commit()% m1 G/ a) m& [' H5 q7 i
            createNewComponentBuilder.Destroy()
: b# q  x. ^8 g* o8 P# l        Catch ex As Exception8 T$ K* ?. E/ |8 H
            MsgBox(ex.Message)
  y1 \6 v! M$ r5 Q: @# L) K        End Try
. W1 P6 N  Z) ?6 S. ~7 V    End Sub- }1 t* J* g' z4 q) R) Y0 I: I
发表于 2013-11-18 16:48 | 显示全部楼层
NXOPEN .NET很好的例子,顶LZ一个!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-17 15:11 , Processed in 0.053790 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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