|
在vb.net里面开发的一个函数: y+ a$ Z% \; t4 q2 g2 |' B, q/ {
Option Strict Off
. W! X, ~7 q r3 vImports System
I" c+ M r: ~Imports NXOpen0 J* d9 L! z k) j+ Y( l
Imports NXOpen.UF# P `6 X/ ~* N7 M9 O, ?% v
Imports NXOpen.Utilities8 M. q1 g. |( h& `6 L% g
2 S7 U; S. I; n* K% S7 t m
Module NXJournal
2 E1 P! B" r+ `6 s) XSub Main
6 l7 |0 V! }+ y, h% g8 z, }% _
1 ]5 K; j3 ]( R A1 D Dim s As Session = Session.GetSession()
. o- D/ s* ~; a+ h8 S Dim ufs As UFSession = UFSession.GetUFSession()( Q s F1 n9 z& @/ ^
. b" G8 a) Z4 g" ?, s
Dim wp As Part = s.Parts.Work()/ g1 X; H/ [/ T
$ B) `6 D3 ]* X* P) a
Dim cyl_feat_tag As NXOpen.Tag
' U( r4 N, I$ Z+ ? Dim orig() As Double = {1, 1, 0}! [$ B" q, y2 D7 ` [
Dim dir() As Double = {1, 1, 1}* {5 a( C, A2 k7 X
7 p2 Q, ^( W# e9 G# b. W
ufs.Modl.CreateCylinder(FeatureSigns.Nullsign, Nothing, orig, "50","25", dir, cyl_feat_tag)/ e# n4 E$ M- C0 D1 A4 u$ j
/ r* W9 X' {; G2 U+ u+ w w- L( p9 K
Dim cyl_body_tag As Tag
Y" J# m0 g9 p- z* e; M @ F4 S# X F' `. b
ufs.Modl.AskFeatBody(cyl_feat_tag, cyl_body_tag)1 l. K, R- O# I/ g5 S6 ?
Dim cyl_body As Body = CType(NXObjectManager.Get(cyl_body_tag), Body)8 e6 a' U+ j3 z: w
% G0 v, Y2 E- o( N' v% A+ P$ O cyl_body.Color = 3 ‘ //更改颜色8 z- C' `" H( w p1 D/ s
cyl_body.RedisplayObject()
1 ?! r8 m! }: n8 BEnd Sub" e5 }+ Q: j' y8 x
End Module
, x3 U% C9 n6 K% S我把它转换到c#里面遇到问题了
; `1 f- J8 K. \# I# I4 } z& c9 x! e Session s = Session.GetSession();; G9 {' o: ^. c% J/ x' u# S. c
UFSession ufs = UFSession.GetUFSession();
1 T4 t- X% |1 `2 N4 {7 }; C) d) S- i8 j1 R' t) A
Part wp = s.Parts.Work;) r- w& u# R' L* n
, |0 {7 ~* n ]3 \" f. E9 |8 l/ b4 n NXOpen.Tag cyl_feat_tag; # A/ n; h) E% F) ~: o, I3 N
NXOpen.Tag cyl_feat_tag2; 4 J5 R) a1 R$ d$ v3 b- G" ^* u
Double[] orig = new double[3] {1, 1, 0}; L/ K2 J# @& r
Double[] dir = new double[3]{1, 1, 1};
. b" a1 Q5 [' e% Q& N, K try
/ _' t4 J: N* z {' s0 H- R0 _/ ~; e3 |
ufs.Modl.CreateCylinder(FeatureSigns.Nullsign,cyl_feat_tag2,orig, "50","25", dir,out cyl_feat_tag);5 p6 o* n, `5 B/ g. n; m
}, h; x s+ p& T1 k$ @& j D- t. V
catch(NXException pp)8 q8 c) t T2 u- ^0 i
{' s' y" Q3 Q$ H0 n6 `
MessageBox.Show(pp.Message);
( i" d/ ~6 a/ D9 i1 p2 f2 b$ N }
- t5 L# q! y! c# h6 m/ X% M- u/ N2 [- K6 V7 T
Tag cyl_body_tag;
0 r. @2 L. c7 o# }
# V' D; G8 }. r1 \' M) V+ [ ufs.Modl.AskFeatBody( cyl_feat_tag,out cyl_body_tag);
$ v; m( e5 u X+ T Body cyl_body = CType(NXObjectManager.Get(cyl_body_tag), Body);
% ]4 ^7 x8 l# t0 I. q
9 r R7 X0 B4 O. ~% `/ J cyl_body.Color = 3;
0 M) W7 [, b- E cyl_body.RedisplayObject();6 [. ?, i6 k1 c: ]9 f- }
因为我查看了CreateCylinder函数在c#里面的api,第二个和最后一个参数均为tag枚举,我定义了两个tag,但是程序出现异常,我用null代替第二个参数,提示不能转换null为tag,我查看api里面的NXOpen.tag为枚举,但是里面的内容为NULL,就一个东西,还有后面的CType函数不知道怎么用,而且ctype函数的第二个参数为一个类不知道怎么转换了,那位达人能给我将vb的程序转换到c#里面,小弟将不胜感激,跪谢了 |
|