|
using System; ( u! E) C" W8 ]5 u3 T, p: c. u8 B5 ?
using NXOpen; : t! m4 J# u8 Q1 p# l
using NXOpen.UF;
- c5 J: i/ b1 Q& w! s0 b$ n# Ousing NXOpenUI;
3 S/ p) y" ^& Z f
R* w4 t( F0 n0 \7 ]+ Z' m5 Inamespace C__test_01
& `2 z, p; O) P5 x/ ~; Z' T{
$ H8 ]# Z6 ]9 ], i) w4 E1 X public class Csharp_test
4 U$ X6 J8 g: T4 B P. I2 O) g C { " |' W: {) s- s; w V+ r
public static void Main(string[] args) - g; h& }1 Y/ h. g; s$ s3 {* i7 N
{ + x3 n* b' ]* n
Session theSession = Session.GetSession();
1 Q( o3 ^2 O* Y2 K& _6 @! j* G/ ? g7 ^ UFSession theUFSession=UFSession.GetUFSession(); " c# |( u2 o/ p
. }/ T+ ?; E% n8 P6 q* z
UFUi ufui=theUFSession.Ui; ! H: w& i4 }5 k7 r& K9 W2 X
- m" B6 M6 s( A& N8 H. L# [$ X
Part workPart = theSession.Parts.Work;
9 |" Q" v! [0 G' \5 \9 x' ?
0 ~2 V( |1 b. ^ v! d/ P NXOpen.Features.Feature nullFeatures_Feature = null; - f. ^- y) R0 ^; V4 E1 ~- a
5 b: k: |3 ~+ Q. P5 Z8 V NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
& l" e6 ]% [; U. t( \8 s! W9 T blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); & e5 i& ?8 v0 ^, q
# ]# ]& `- U* P+ f" i+ ~
blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
, \( Q8 ], X7 |) g4 c) o; S
1 _+ s5 k/ w! h3 z0 ~" C; V! M3 o Body[] targetBodies1 = new Body[1]; 7 s* n1 F: c" R0 b2 [" Z
Body nullBody = null; # k8 U' h" F' {2 O* ^
targetBodies1[0] = nullBody; ! W! }- U/ y( s& M' i
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
' V; H) }8 K" t) G1 V / o7 H& L2 o/ j! e) C4 B3 X
Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
+ m E! O$ M2 w0 j! m9 Q& u1 } ; h- l4 f A1 ~8 D- x
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths; ' l6 l) z" g/ B+ B# ~' `4 k
! ^+ W f0 ~8 U) _ j; J // 使用点构造器创建点
% d4 B9 m5 ^& M5 B) l+ s i+ T string cue = "请选择一点"; ) r/ h( `- T. x! A+ ]' ~, E6 y
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos; + K. j. V2 Y- f2 q
Tag tPt;
) e1 f: ? F+ m' C: d' X8 N double []base_pt = new double[3]; 9 o# v2 {& O9 K) s* c6 _7 F5 |; t
int resp;
. O- M% a% B- u0 ]% s6 l
0 v$ P/ y3 c- e' q! } q ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp); 3 r, ?! i( A. K( k* M% n6 _3 @& W4 U
/ z( w* s/ I$ M" N6 W
// 输出坐标信息
) Z* b5 v0 j9 R+ U9 P- H4 E ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
9 \3 D, U* }9 [: q
2 ~0 N3 i$ @" y" n+ [6 Q Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); / z3 u3 E& H1 P
' @ w ?9 G% O7 k o/ T( h! h
// 设定原点和长宽高 , [ I3 ?* _3 J4 H, i
blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180");
# |* D% ?- V* M2 m4 ~& @
; t$ | u# ^: u blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);
3 l2 t3 F7 O i7 G; E 7 _4 o$ }& s- a! G% C/ o% i$ O0 D! x# Q
NXOpen.Features.Feature feature1; 2 x3 {* s+ B" U$ z
feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block . V- G9 u& L0 U7 Q
blockFeatureBuilder1.Destroy();
+ \# N- u- L; y a; _ 3 m; \# a3 M" E; r, k1 [) i
} ( r, L7 [6 L. X# f
$ A, r1 Y, c5 F0 n public static int GetUnloadOption(string dummy) " w x" Q" E, y* U( Q; l ~* F
{
: y6 f+ n3 f+ K return (int)Session.LibraryUnloadOption.Immediately; # G: R6 B; U, i" N& ^: g
}
; E. v: [/ y! Q) b& |: P } / ~9 g0 i+ x2 u% k. T" P9 p
}
* X9 h5 r9 U5 T* r: [ [/ z7 s) k2 F* A
; S4 H2 q7 Z4 \% ?1 |// 仅供学习交流! (smthan@163.com) |
|