|
using System;
% W1 c& ?& m8 T) lusing NXOpen;
: Z% u8 b1 j3 _; w& h9 vusing NXOpen.UF;
6 O0 C7 d- N! _8 }& p( @using NXOpenUI; * c# z" X5 {5 _2 o
, A+ u# |, W @6 x9 u V3 Q
namespace C__test_01 , j7 G8 F. o& D% j% b: r3 \, @8 M- D
{
u! g- ~5 N2 G5 X0 E' {4 ~ public class Csharp_test 7 q' k6 ~: @/ [( T. }' }
{
- ~- Y! t9 U% S: D public static void Main(string[] args)
) K, l! u: R9 c- @2 O$ d {
# l7 ^- Y( x- h( |* m8 D' Y9 [3 L Session theSession = Session.GetSession(); . ]4 j; Y! G. o: @& I& j6 O
UFSession theUFSession=UFSession.GetUFSession(); - B' E5 M. j3 u" K
4 u5 i( @0 r9 S' Z1 {' R UFUi ufui=theUFSession.Ui; $ ]& u3 V Z, v3 V
5 ]) T& ]. ~; w Part workPart = theSession.Parts.Work; 8 D$ u* K8 a* r! ^3 R9 N2 g2 \
* [; o* R& O4 r Z7 s) `$ [; t
NXOpen.Features.Feature nullFeatures_Feature = null; e7 Q& [+ M- Y* V0 @
% Q& v# {. P. S9 X# P, j/ v/ c NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; 6 `) K" H* I! j, K- g8 o- I
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);
# ]* e' h3 Q: G: x/ R% t
V4 u0 ^1 T* b6 M' n blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; 7 ]: B; a8 L4 z3 b
3 F6 u' w% J6 V+ x, X: }' d: g
Body[] targetBodies1 = new Body[1]; 3 L) y0 A% w: Y M
Body nullBody = null; 3 W: ~' z( N0 E; N l9 |
targetBodies1[0] = nullBody;
8 K% t" z% a/ s" n! V- s0 t blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
) e: W& x# F; G8 x7 F) W
' {( T, X9 q) {. ^+ h+ e ^/ M/ u0 n Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
! i* B/ @" p4 q8 I4 W
2 x9 M0 [0 r; w" d9 C8 |# G blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths; ; |7 A: R7 c4 V4 x- K! W
2 V( x/ P3 U0 n" U% A! k: o // 使用点构造器创建点
1 R& ?+ r w3 ~) @ string cue = "请选择一点";
( ~+ c+ Z8 w9 ~1 d" I! y UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
) ]: y! E& p# `5 @. {. R8 E3 e0 E Tag tPt; 1 p" u# _9 f: b' {7 ^ l: A
double []base_pt = new double[3]; . K3 e1 u6 v5 B/ q, [
int resp;
: H, [, A% N5 V" }8 l ( Z6 d i, ?$ d. g" J& P) F: D
ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
, I, Y# ]& ^& c" Z, Q " S: r2 m y% A# C$ n
// 输出坐标信息
4 \7 f, |8 y4 \: N# }& a! y7 y: X( W ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
# `3 c4 B( p; n- O h6 z! T4 o: Y " Q; b! K1 P+ y( k
Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]);
* r, j- R n' `! w; }0 r/ l 7 M, r: `1 K) M* F3 f9 R
// 设定原点和长宽高 9 g- k) \. \" v1 A
blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180");
. a! X! B& _# }4 P* I
- w9 W0 O. B k0 e+ i blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); : l, |2 Y- ?# r3 K+ {/ T8 N# Y3 `# Q
7 Z0 a+ R- n! T% e, @6 n# O. F
NXOpen.Features.Feature feature1;
. U* L8 ~/ |2 g# d feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
5 ]2 T- E0 g6 l5 ~( C blockFeatureBuilder1.Destroy();
1 S/ C! \9 j' x6 D1 m1 m' T
/ a }1 U8 K/ V8 } }
9 i7 Y5 M/ _ {( @0 S5 d" b1 I
& L, N8 X, H4 n7 N; R# D public static int GetUnloadOption(string dummy) ' [9 [- s! B A2 L( o
{
7 t# f! E9 J/ Z( Y/ C' M return (int)Session.LibraryUnloadOption.Immediately;
8 q, q- W6 {6 [* c; [* F } : }+ t' W y3 T( }8 S% K4 b9 X; f' [
}
9 a; i4 A) f I/ o2 a" o} & F8 L# c9 g G+ F$ T. L
4 t9 r6 I6 R) H- Q" X- r: W9 S% I
" x$ r/ h7 N% o* L6 j// 仅供学习交流! (smthan@163.com) |
|