|
using System; 6 `8 O3 e, i- n& C4 u7 H2 Z
using NXOpen; & a, [( [! ~& v6 n# g% w9 h
using NXOpen.UF; 0 C" Q7 a; G9 D; [( j% |
using NXOpenUI;
- S( D3 N: Z. c o: ^
. ]8 V2 n3 l3 R$ q: \namespace C__test_01
, A8 ]7 O$ @: K! a! Y* _8 V{
# R4 l, @; Z" e0 N6 t# P' R public class Csharp_test
1 k# B E2 l/ w }% I4 {: Z: v {
. x+ b Z6 M: t: g: G: x public static void Main(string[] args)
% W F" E8 v' q! ~2 V { + R6 m5 c0 O) Y4 S
Session theSession = Session.GetSession(); 4 c' ], s0 V9 H/ [
UFSession theUFSession=UFSession.GetUFSession(); " x5 {* L2 b1 I4 q: R8 `# k
& Z; \: C; m( k4 X/ y4 s* @- } ~
UFUi ufui=theUFSession.Ui; , M7 p7 Q. G' N; O/ l
3 _# w; Y+ M" k9 Q* Q; A) v2 Y
Part workPart = theSession.Parts.Work;
6 ^! x' j3 e& ]2 n3 q/ V( C! D 6 B7 L6 ]8 \( h( p( G! u
NXOpen.Features.Feature nullFeatures_Feature = null; ! ?" ?% \ F" J3 x% o
; E- i7 L/ J) b- a! n5 ^! X NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; " j+ r R C, P7 c( Z# k5 {
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);
! l* E# Z; s, z6 w; K) o
5 `/ G% M/ l1 y6 \8 v5 M0 P" W2 j2 m blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; r: D" B) V% i3 g$ D" `
+ y( M& T+ z- R' s+ v+ x' ^, {+ W
Body[] targetBodies1 = new Body[1];
4 E$ S4 b& T. V Body nullBody = null; 8 g4 j9 i3 @) l' Y* t% i
targetBodies1[0] = nullBody; : \9 d& _, d) F
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算 + d. v# S! [5 H6 Y n; D7 K7 g
$ m; T: q+ O" s6 k( l( o$ f Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
3 k6 U+ s g$ U/ X2 ?+ V( o 5 Z- `0 _8 _! @0 W( X/ O6 H
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
1 W7 P" i- k' U6 F4 }7 P9 D& ^ 9 t! o5 o+ y& f9 V# C3 ?
// 使用点构造器创建点
" u& P( d& s& W5 o. { string cue = "请选择一点";
* A4 f8 f5 p3 s ^ UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
+ L, \ x% A a! ^0 g4 G Tag tPt; & G" ]6 _$ }( Y; k
double []base_pt = new double[3];
, r$ j* m5 }+ z w+ Z8 k( e3 x& ~4 U0 X int resp; ! e3 h4 C. [) e
4 Q# W" [* X' c( P2 K ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
' k8 h# p+ \% V6 F# r
9 I5 K) r- [6 K0 N/ @ // 输出坐标信息 9 U7 a; W; T6 c) P/ r) K: F/ D
ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
8 ]9 _0 O4 I$ ]! U1 c7 ^: @6 _7 ~ # E4 n6 \7 ?) V; h: j6 I0 t6 p2 J9 X
Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); . d- q D- y7 l) [% D
: _4 H0 O3 w/ d3 }3 b) e: e5 ]
// 设定原点和长宽高 ( H) }, d( x( E3 _; S- O" n
blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); 7 g" b$ h+ J$ E' J; j& x, @; T
3 G6 j" K' ]5 L: D" T% ]
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); 2 |9 f0 m- O/ q( H# e5 S
+ H6 X% [3 x; x: | NXOpen.Features.Feature feature1;
: S% O! v& L( H+ d e) R feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
5 F% `. L$ a1 g( n( n- c8 @ blockFeatureBuilder1.Destroy(); 3 E+ t, G6 D: g6 `6 x _* J
$ c( z4 u9 m9 r/ I4 r# o9 a
}
: F+ [! l1 |( m& g( I& I
7 r1 {( B, K- T4 I public static int GetUnloadOption(string dummy) . M" n- v* l, ?: `9 n
{ - T1 _, A$ A0 [! D* f
return (int)Session.LibraryUnloadOption.Immediately; ) p! P8 p+ ?) e& J* D8 {) Q* F
}
4 {) I& v* [; Z% y) V: ?( r3 I }
5 p8 t" b; A/ ?7 l! ?3 e& S} 7 `' {( p- Z5 D2 y
5 ]+ j2 g% ^" N8 U* i H) c
7 @' ?) R* B" A, F$ F& Z1 s" j// 仅供学习交流! (smthan@163.com) |
|