|
using System; 9 Q* K6 h9 e: _
using NXOpen;
7 ^- M2 u: K7 F7 Uusing NXOpen.UF;
( R0 ]6 y, ^- u& zusing NXOpenUI;
5 N$ ~4 ~, r! A; J9 V" Q5 c! G
% y! f* A' d" u3 X, R, ynamespace C__test_01
8 w+ v8 Z/ p4 E& h1 p{
# C. R* M: v8 t public class Csharp_test 1 y, F o" X. H8 Z& p
{ ( w, P0 p; H, G) l
public static void Main(string[] args) 8 K: L' E: {( a3 \# n/ j' I
{ ; [3 o! F2 l; n3 ?
Session theSession = Session.GetSession(); % e: |" F/ i6 R1 N0 u9 ]8 z! v
UFSession theUFSession=UFSession.GetUFSession();
; X* N* L! g( l+ @+ K4 c3 a- v
7 J1 z3 M' D; H( [- y% m1 z/ }- {$ @ UFUi ufui=theUFSession.Ui;
- e4 k Q- d% o$ M) u B
/ P u$ f: o' H1 Z Part workPart = theSession.Parts.Work;
) K9 O2 z2 E/ x. T& _0 e K + F+ I3 e% N @* K
NXOpen.Features.Feature nullFeatures_Feature = null; / V' X4 W( U( {6 _+ K
+ C/ q/ g3 F9 _6 k; Z NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; 9 Q- K* b6 \* b5 L: ^& v
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); ' V) N/ v# Y7 F# ]
1 n7 |2 R3 C( S* h
blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; $ n. @+ ]) g6 D: B: G
$ ?+ F" F7 X* }! T* B7 ]: c Body[] targetBodies1 = new Body[1]; 4 P# c4 X9 E! C. L, |% `$ {
Body nullBody = null;
" p3 g7 @7 [) H( V+ D$ j targetBodies1[0] = nullBody; + ?8 U! D5 Z: D# J6 \, t
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
$ a+ D8 c$ ^% X% {
5 @( b# W2 M8 Z% t- A Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
5 [8 R0 T$ c8 V5 O+ }
( l/ Z# H: M' m+ S) E1 P blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths; 2 G4 u$ A! A% G$ t: @
8 R u; i# {) z- W( T3 ~ // 使用点构造器创建点 4 u% m0 f: Y# Q, V) h2 `
string cue = "请选择一点"; 3 t4 t# S1 b( w, I0 B8 M
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
" ~! u9 u- H1 P# D# ~/ T9 i# O Tag tPt; Z' g+ z1 K9 v
double []base_pt = new double[3]; 7 g# t: i. |) r$ W! ]) F$ ^
int resp;
5 Y9 K0 k7 o9 g8 A% c6 |- U8 G
- a- Y* e, k9 D" D% C ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
$ l( {/ Z1 S) W2 f' B. ~& a
. d A0 x9 p# ]" e% r/ v // 输出坐标信息
. L9 B4 x$ k* K4 {/ T1 Y ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
2 U. `$ X% V F9 L0 b0 e 2 W3 Z& }# P$ y9 v4 i C3 c
Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]);
/ f( j2 C& J1 L
" [( E) A- s, w8 X // 设定原点和长宽高
0 S+ N4 G' u$ I# F2 ^- a7 y, C3 w, m blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); 0 l6 }; v0 i$ S5 n6 g
6 O+ B* G+ O3 {5 I* t! D
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);
( z! U" O# X J6 G6 I Y
5 q& l# T9 i7 M3 X3 T) _ N NXOpen.Features.Feature feature1;
- I1 ~$ W8 t$ N# g' { feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
2 x: k5 {/ i) d$ b blockFeatureBuilder1.Destroy(); 0 n* }+ \1 g+ G: w
% J. e% u P: E: q6 f
} / y" I7 K0 n8 H+ s( n7 S
, o, U1 s% d @) I$ H
public static int GetUnloadOption(string dummy)
# h2 Y- U4 D8 T7 n4 f3 M, m& ] {
, W, a) R1 M1 e! c$ l! t9 _ return (int)Session.LibraryUnloadOption.Immediately;
+ @3 ]! C; d( u }
4 E$ z k C' l } 3 J( o2 b8 n& R" ^2 l
} 0 n- V& P- g& O6 [; d% |3 _
9 ]. ^5 @! Z n! T2 t
# o# |, ^' ` J// 仅供学习交流! (smthan@163.com) |
|