|
using System; ) G: Z; N9 E* z. m
using NXOpen;
$ w' i% Z+ K$ fusing NXOpen.UF; / S$ a* l& q' j: Z1 N2 l
using NXOpenUI; ) a" b+ T8 L: h5 M
( z7 W) r9 Y( N8 g- C# lnamespace C__test_01
6 e- I8 ]; H6 J9 T{
& A! c% H7 k/ i3 \0 | public class Csharp_test
) V, d- O+ p' x5 x3 e* h% k {
1 Z- H7 U5 J: y! A: a* P public static void Main(string[] args)
6 R ~1 L# G5 l2 d" A/ z$ j, n { " ?- d' a2 b! j' v, _1 w4 k! Y6 d1 l
Session theSession = Session.GetSession();
) L6 x$ ?- P! @. {' L0 k: c UFSession theUFSession=UFSession.GetUFSession(); 0 q) Y( A: Z' ~! v4 C6 ~+ e
) G* O0 f T* K* w UFUi ufui=theUFSession.Ui;
" I" R0 I2 |4 @3 |2 n7 c( t ! T4 c9 R0 Y: H3 Y
Part workPart = theSession.Parts.Work; ' ^: s' U" T' B# E/ a
/ I" F( E, P% y2 R4 d
NXOpen.Features.Feature nullFeatures_Feature = null;
( N5 ~2 t5 E: L) A: T2 M; t # Z1 p7 h* c& y. c+ M. h( _5 P
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; ! A$ @. K" ^1 _. C3 V' l
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); 7 V r7 S0 T/ @2 m& h1 ?3 O
: `9 j- w% s. i2 c
blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; ) O/ B3 i$ t7 I8 I* z" c' S% |
7 Q5 i) O5 E5 ?$ h' e$ X' [
Body[] targetBodies1 = new Body[1];
& H& x" y% B5 h Body nullBody = null; / W2 w0 S3 ?+ C2 ^& |2 V4 ?6 `6 ~- A
targetBodies1[0] = nullBody; ; N( Z$ ?& R E8 k2 y" E4 O3 f5 N
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
7 p# q7 K" g( l, K& ?$ X3 x
: V. E. k) B' P6 |4 k- M- c Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
7 x0 W7 [$ @& D" y
; ` F G# ~& s4 q blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths; 4 \% ? M2 o- q7 n! h
; r1 J- w1 E# z- y) s; z& ?6 t. p, _
// 使用点构造器创建点 : e+ l1 W; g' V. d* N9 h
string cue = "请选择一点";
. e# B9 j* z& T* } UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
$ }; `2 [" a8 z; Z9 \ Tag tPt; ( Y; |) ~ S+ J6 o! W/ g' p7 i2 u B, a
double []base_pt = new double[3];
1 T7 [. I! N$ X# P; g! I4 r! ^ int resp;
A% ^5 a' V/ @+ ~ % k; n/ E8 Q/ M: a5 |9 {' b: D3 Z
ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp); 4 u: P0 B; o) @9 M
6 l7 m0 r0 U4 ?, H, i$ X
// 输出坐标信息
. s- u3 U5 v C2 j- E ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1); 3 z0 N u$ \2 E n$ R: Z
; q0 O. [4 O. M V+ M6 i0 f& P, D Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]);
: `' [. t; s# L/ ?% l3 E
) e, b8 p A0 i) r2 J! w6 U2 e // 设定原点和长宽高
! X- `2 o5 I" a \ blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180");
) x* y' m+ J7 P( a) n
0 p. p$ a( h# Z9 E blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); * x( A. m" Q0 u
# y: D2 Q+ }* o% i" m* ]* \
NXOpen.Features.Feature feature1;
* n, K1 \3 R/ N' U8 _0 J: _% e' N feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
0 p. b, P) J6 s2 E& n blockFeatureBuilder1.Destroy();
) I1 i( x7 H4 ]! [, l5 ~8 F( s
0 Q3 d( b4 j+ ~' y }
3 x; R( A1 }+ B* v
7 E- [9 G* B0 x% z# Z0 j public static int GetUnloadOption(string dummy)
2 A8 R3 n$ F! y+ b, A { 1 c& `1 H+ u4 B. a x7 @
return (int)Session.LibraryUnloadOption.Immediately;
) A, X. f- z$ ` }
) e5 g0 m" Z) } } # ?! j& j! I6 [: [& Y9 N7 c
} - Q) t0 A* s5 U/ ^
3 A6 R/ ]+ a3 t
( p: J4 `; b% ^( @" u, q3 s3 I! O
// 仅供学习交流! (smthan@163.com) |
|