|
using System; 6 M2 k0 _* s4 o$ A5 A/ e, ?8 }
using NXOpen;
' \( ~+ E& k- C. {# ?1 C" Husing NXOpen.UF;
; e" u' G M5 B _# D L" y7 Iusing NXOpenUI; : F( ]: `$ r9 l$ G8 M2 Q& h6 P" U
; G7 Q6 A$ U0 o. h# Gnamespace C__test_01
N- v2 ^/ ~1 g( v{ % \$ W$ K; b- i X0 I. s
public class Csharp_test
9 N( c' f1 \3 C- P3 _ { % D1 U* I2 Q" p Q
public static void Main(string[] args)
: ?- W5 j% l4 X4 ? {
$ T3 I" M P, _# S$ O- t. Z Session theSession = Session.GetSession();
4 h& [8 @( m8 p# z$ k* `8 `0 r UFSession theUFSession=UFSession.GetUFSession(); ' b" [; H# j$ p5 }/ Z8 z6 T! O( l
W: E1 i$ Y) G5 A( E UFUi ufui=theUFSession.Ui;
/ @1 T; A Z: y3 t5 @9 g % o8 p7 e: } ~7 s& K
Part workPart = theSession.Parts.Work;
7 T3 V" Y2 N% b' j. X6 F* e" e, F
Z+ j) B% X; ?2 F" ^$ c4 E* h$ A NXOpen.Features.Feature nullFeatures_Feature = null; ( W7 K. ~! x5 j* e4 X
+ G. R7 r+ I0 X6 z; G* H% ^# R
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
5 j6 f6 C V8 ^! j F blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);
% j8 I |5 s+ G 9 e! S# K* Q8 B) D
blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; : F4 n6 N T0 G+ F
9 L3 y# K7 z2 O2 D3 O- E; E1 O* C! D Body[] targetBodies1 = new Body[1];
/ i8 _/ ^8 W& v# s) f2 e Body nullBody = null;
! c& Q- U4 j5 e targetBodies1[0] = nullBody; ! e1 A* A$ b- b* F
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
$ J: v3 a; v/ V9 j
0 M1 s2 L5 u9 N0 g0 z/ `0 v Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
5 _. w. I, I6 J' D9 n8 u$ ~
5 n; }/ c$ l0 o" V0 B5 [7 l blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
, @) m4 g, Y& C9 }
, L8 F5 ]' n: k) n/ C3 ~" { // 使用点构造器创建点 + E" E& f- c/ d6 ~$ R2 G- Z
string cue = "请选择一点"; 8 m/ f' b0 n7 ]+ F
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
6 x$ B$ I* U4 X. H' U; O Tag tPt; / ]7 c7 \' ]$ r) Q
double []base_pt = new double[3]; 6 D1 G1 C- g/ P8 ~; E, @
int resp; 4 A" }, K2 O# K& x: ?) o% A
E7 T3 {. P& f! ~$ d ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
9 C1 M( p# @# \( Z; W # X. Z* N2 ~ ~% g) w
// 输出坐标信息 3 ~, \9 M- ^( A5 H; g4 y" ^7 V
ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1); ) O. B" C) q! ]' B
: ~. Z) @9 b& ~( S5 H
Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]);
0 z. i# `; {3 T% R
. H+ w8 H1 X- N$ @ H // 设定原点和长宽高
0 S) o& m( h3 g$ c0 K1 U S8 W' T blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180");
8 t* @! t1 f; n O ^9 q, z! u1 t7 G : c. Y0 b3 @ G( K9 s1 e* W
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); * o. g3 y$ i( ^% |
8 `( S) _9 [& p% Q6 @, R8 s
NXOpen.Features.Feature feature1;
1 Z% n) P' k8 Z8 v feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block 0 I5 T" P2 h* K2 _& c5 R! ^
blockFeatureBuilder1.Destroy();
* \* ?+ o7 ], l b
2 I! l' t( I+ ~0 l }
. N1 z& _' T9 U
2 E2 F+ ], b Y! H/ d. | public static int GetUnloadOption(string dummy) 9 M! ?2 F3 ^$ E( N0 l8 F
{ # s5 I# t) p3 J2 y5 t. ~: n3 q% v
return (int)Session.LibraryUnloadOption.Immediately;
5 x* [! f( D; J6 M- ~! r }
4 M5 q: ]. X3 x } 2 L+ W l% F. N" @. k
}
! o& r9 B2 w! n, ~
, W: l1 ?5 L. O# e
3 E+ c8 T- }+ c: B) z// 仅供学习交流! (smthan@163.com) |
|