|
using System; " j7 m5 s; R5 l
using NXOpen; : ^# L( F# {0 s5 n m+ M3 _3 d
using NXOpen.UF; # I( R& K+ d9 m* D" y1 J
using NXOpenUI; 5 F8 d, {9 g# D$ ~3 p. Z
/ B9 d6 J+ M+ R- K6 x0 a$ znamespace C__test_01
6 q$ t) k* D! H5 [{
& H# E/ h2 [4 b! J! c8 z' E public class Csharp_test / m, v0 l8 R" Q/ l1 Q" v8 X
{ / Q& I( c/ M% e/ L( A( j6 |
public static void Main(string[] args) ' W+ a/ u. f$ B) c
{
1 F, d( K7 C! m) f9 l; L, D# G Session theSession = Session.GetSession();
: C3 Y( P- @ X/ Z UFSession theUFSession=UFSession.GetUFSession(); 5 p! w% h8 f$ i! I0 c8 `6 J
N' J7 ]6 g) }) y- K% R R UFUi ufui=theUFSession.Ui; + ^. A+ X2 b: e; e2 L, R* e! @1 R- ]
2 n5 D5 ~7 B, D0 z# ?1 C1 b( z
Part workPart = theSession.Parts.Work; " a: O# E( A1 S3 f+ `7 T
0 ?4 A) d) a+ Q: D1 \/ k4 u+ a0 p
NXOpen.Features.Feature nullFeatures_Feature = null; / I7 y F% {$ A& Y8 B
* M5 {- a. w/ m$ H. W" K) y
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; 4 F- O4 [! d" J4 @2 L
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);
. w4 K4 P0 s+ G) z; W
: c3 n3 ^2 [( ], h blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; # P6 W9 `9 J Y8 U, p
7 d+ d# {8 k1 P8 t0 \2 d% ^* p
Body[] targetBodies1 = new Body[1]; ^2 _3 l, V; I6 ?" B- X' k
Body nullBody = null; 5 \) I" N$ K- d. l- @
targetBodies1[0] = nullBody;
/ m; Y& {, n+ S blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
3 P/ j+ S: B6 k* @5 V: d( { - e/ _1 B+ D0 ] p" y# v
Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
% D0 ]/ ]/ C6 H5 U ( S ^% A( U2 E# r- r' y4 p
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
6 n+ r$ R5 b4 ?7 A+ t3 q4 U' S
$ E1 K Z0 ^. p1 z) H // 使用点构造器创建点
; ^8 [( O% o! s* b4 j% c string cue = "请选择一点"; 7 J( x) M8 y! s% [( I9 x
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
, R' `$ V, m& a8 p Tag tPt; 0 _& C( q7 x2 ]7 S6 d" o5 Y; G
double []base_pt = new double[3]; 1 e2 f7 |7 l( x8 M
int resp; 2 L6 T! R* m2 L1 j9 s
% o1 C& R: R$ Y1 A1 m ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
0 I1 `" k; a, ?: b - s& r. x7 o! B% [1 q( d
// 输出坐标信息
; r) |, I- f- ?5 @8 t2 x ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
/ g k6 Y0 x u% G: i3 T% |6 _
- n' `4 x$ J0 A a/ a Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); , E6 n% O; p& D* X
! _. _# V# O3 x O- P
// 设定原点和长宽高
/ m: f1 b) h. u5 d4 k2 s: M blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); 1 |/ z4 r5 x( w. [$ d8 D
- O, d2 K! h- z/ B% A# {% L blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); % p) H3 h3 j" z# d! n F
+ S2 r8 s& B& t9 G P: |% w" |9 Z
NXOpen.Features.Feature feature1; % d' m# N- ~' S. C* |4 o+ J
feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
! S9 `8 l' Z, y! E4 L$ B# I. n blockFeatureBuilder1.Destroy();
& s+ j6 m4 E& F' o# A
$ S/ c B" m9 C, z' T2 @% ~ }
3 q# ?( n2 ]' j ( C+ Z/ T/ b* b8 @. I* F
public static int GetUnloadOption(string dummy)
; P6 {1 b- g6 A {
/ b2 Z/ K" I% i/ W9 F X return (int)Session.LibraryUnloadOption.Immediately; 6 A s; ?. Z# P# F2 ^: |
}
; E$ y5 T* w8 Q' u } 5 M m7 u4 t7 ]5 z/ C8 x J
} 0 y3 F+ G# K9 k7 q, F) ^
1 q4 }- b" w! Q# k2 F! D
/ r& G7 ?: h ] q) a) }( T" F1 V
// 仅供学习交流! (smthan@163.com) |
|