青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
发表于 2013-11-14 16:17 | 显示全部楼层 |阅读模式
'如何得到Object.Tag
8 r! X8 r! u6 W' r '遍历得到所有body的Tag
/ h! ?7 Z/ w  S 'theUfSession.Obj.CycleObjsInPart(workPart.Tag, 70, objTag)
$ j! a! T9 Y/ V7 _+ b* A
/ y: q  R% u+ V( pSub ExportPart(ByRef part_tag As Tag)' @9 a' @& a4 a, K* ]8 \5 f! e
        Dim theSession As Session = Session.GetSession()
/ l9 J3 ]2 |" B; R        Dim theUI As UI = UI.GetUI()
8 f9 I% T+ f5 A! @  b7 Y        Dim theUfSession As UFSession = UFSession.GetUFSession()7 z0 k2 Z6 y" D* T
        Dim workPart As Part = theSession.Parts.Work8 C( d) i* H7 o8 s
        Dim displayPart As Part = theSession.Parts.Display- ^4 I& d3 y. I0 t3 @
        Dim body As Body = CType(NXObjectManager.Get(part_tag), Body)
) a) z5 P. _; }6 k$ [* s        Dim part_id As String = body.GetStringAttribute("part_id") '得到属性“part_id”作为零件名称,可以自己设置其他内容8 b7 K" t+ X- P" }
        Try
( V% C' J' j7 [& \0 u# l: T7 M8 ]            Dim fileNew1 As FileNew' _' G/ x4 [' ~8 |2 A/ I' K( t
            fileNew1 = theSession.Parts.FileNew()
/ {7 _% V6 g+ N* S* s& ^            fileNew1.TemplateFileName = "model-plain-1-mm-template.prt" '导出模板名称
$ I: G1 R2 ]9 v1 i* t            fileNew1.Application = FileNewApplication.Modeling  U6 j; X/ E$ R  b/ W% M' s
            fileNew1.Units = Part.Units.Millimeters
/ C( p) X& W" V& Q+ m            fileNew1.TemplateType = FileNewTemplateType.Item
$ I4 \# S5 F* S; x! c4 D            fileNew1.NewFileName = "D:\" & part_id & ".prt"  '保存路径* c8 }* V( `. Q6 J2 o! d0 [
            fileNew1.MasterFileName = ""8 d7 p* u7 G% K3 _$ D
            fileNew1.UseBlankTemplate = False* ~7 M  t. H% n+ a' m
            fileNew1.MakeDisplayedPart = False
" i1 L& _* y- e' ~; B& }% u  c: |: ]1 J2 p; d0 l& ^$ {2 _
            Dim createNewComponentBuilder As Assemblies.CreateNewComponentBuilder
" k* F2 ?  ^  T! n( j& X# m            createNewComponentBuilder = workPart.AssemblyManager.CreateNewComponentBuilder()
' F/ l& ~5 @# r0 H            createNewComponentBuilder.ReferenceSetName = "Model"+ X! s3 h, T5 Y
            createNewComponentBuilder.OriginalObjectsDeleted = True '一般设置成False,删除源文件中的对象# H1 @; V6 M0 }
            createNewComponentBuilder.NewComponentName = part_id
9 u3 @0 A- Y" V9 l; t" F% x            Dim added1 As Boolean
+ \* }' Q/ H8 y- m: x; Y, Z            added1 = createNewComponentBuilder.ObjectForNewComponent.Add(body)+ I/ D- \3 A) b- k3 B
            createNewComponentBuilder.NewFile = fileNew1! G' p8 {8 h, x. N
            Dim nXObject1 As NXObject
0 S  e; _) `  O& l            nXObject1 = createNewComponentBuilder.Commit()' E8 ^8 [# k1 t- j
            createNewComponentBuilder.Destroy()7 Z9 m- N' h4 Y
        Catch ex As Exception% w' F( V3 j- j# {2 t
            MsgBox(ex.Message)
9 I- S0 L. U: C) T% `7 H        End Try& p6 s$ N( l& _; f% P# p
    End Sub4 ]5 B+ W- k2 N1 h0 n/ n
发表于 2013-11-18 16:48 | 显示全部楼层
NXOPEN .NET很好的例子,顶LZ一个!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-3 02:10 , Processed in 0.052141 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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