|
using System;
6 G8 i l$ Q8 z* Ousing NXOpen;
$ E) l5 @+ s) b% k+ @using NXOpen.UF; |, G* K$ n) g J
using NXOpenUI;
+ n# E( E5 a" ^' l5 y + c. {8 x2 Q' i- ]+ a$ Q/ Z! _+ {
namespace C__test_01 * K, Y! O1 Y7 z/ ~2 T
{
" J$ a6 M% a- d- |3 H7 j% P1 U public class Csharp_test # `- ?4 H" x: @& \2 w+ p
{ % i2 b8 P- M, S) L0 p
public static void Main(string[] args)
% B. g1 F. P7 B2 C" D! f1 i; B) q' G1 y P { ! x6 R( ~0 n5 t2 J3 q; P. U% E6 E
Session theSession = Session.GetSession();
( q% v, L; \. Z3 S) x F UFSession theUFSession=UFSession.GetUFSession();
$ u% w! W5 y0 P; L8 Y 7 c/ L2 U7 A2 B. V+ P
UFUi ufui=theUFSession.Ui; ( V% X3 h+ [& }1 t
; W' u" Q. K8 y3 p* W
Part workPart = theSession.Parts.Work; , y3 x8 C3 F6 [* ?9 G) t
/ l5 C0 `- e/ y* W' Q" m2 Q G
NXOpen.Features.Feature nullFeatures_Feature = null;
& w0 H0 H$ R, l$ j b; v/ ~) _/ z8 U, T$ x
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
2 ^. B; Y/ Z8 `, k" s blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); 7 }4 T ]- i5 r2 d
! G- `: U: n8 s' q, @+ T& z blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
0 e& q# W3 {& L3 F3 y0 b1 H
1 A! v# Q! R4 K+ x Body[] targetBodies1 = new Body[1];
! ?1 [' t' q, f1 Y Body nullBody = null;
1 k! V0 D6 l+ c' ^/ |8 t targetBodies1[0] = nullBody; 4 u. D7 C# Z" i/ Z6 O
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算 # z+ V' f, N, l4 `; b
5 n9 b' O3 K+ l" E* T- K* s Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter"); $ @& s2 @( F$ p! J8 Z+ [! H! \
& Z8 k, M7 F# P c) v, @8 n
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
+ s# X' M4 k3 ~3 P- o- y ) s9 c/ D: T+ Q1 u8 y
// 使用点构造器创建点
! ~9 ]& E6 [, L1 P; M' v" ~ string cue = "请选择一点"; 0 m* a( s9 ~2 M# ~! q
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
; f) b+ Q6 {0 Y' `2 f Tag tPt;
~9 q3 _: d6 j3 w% R0 R9 T double []base_pt = new double[3]; 9 t! P: e+ k5 ~. T7 b
int resp;
! i3 m, I: H) D: a |4 Y0 d
( f: p6 W: T" e) w& T m3 m* _ ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp); 3 i& n' J7 }6 k2 c* S* R# z
/ B5 q: h3 s! J& W
// 输出坐标信息
8 ?" ^; b$ t- c6 H% g& ]0 O ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1); ' e) c! X% U( m# l
4 d! x5 d0 F$ T3 G5 q' s0 I7 h
Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); 2 I1 L: _! x( D& }# C0 a# ?
9 \/ P$ }6 [" x: R3 D
// 设定原点和长宽高 7 f) w5 w7 V+ h. Y" b* ^- X
blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); ( a$ k$ D$ T) `. [5 f
# J( U0 t# R' c, z
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody); % I9 y, ^" E2 v- N" Y" u& O) x
1 O) s7 U% p; h2 m' `* C; j r, Y NXOpen.Features.Feature feature1;
$ G" o* ?$ g1 M- D& I feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
* M% H# c/ P M* E blockFeatureBuilder1.Destroy(); 3 m2 j/ B6 i6 g
8 W) B3 L0 O, Q& t( k( H+ c) e }
2 u- }' K& |/ A- N) g! Z 4 z; Q3 J/ `, j( i$ d! f% j c" q" C0 j
public static int GetUnloadOption(string dummy)
5 I: ]6 q; p/ c {
- n) `' M+ a, X9 @2 [: v return (int)Session.LibraryUnloadOption.Immediately; : |) s, \- k3 @2 l8 a
} 0 E- C7 n% L" ^7 t7 v
}
; f( C3 N$ _9 v}
9 T1 b9 ] C( U! w. K) J 3 M) Y, J7 h1 f Q9 \
7 n, e2 h" ~& o o& Q% B( u
// 仅供学习交流! (smthan@163.com) |
|