|
using System;
9 ^! U5 I6 |2 g4 k) {using NXOpen;
/ B: Q8 R# q% {$ g, ]( K# I" v0 tusing NXOpen.UF;
) g7 K8 Z$ J6 p4 `" ^using NXOpenUI; % C6 ~" d3 L/ I( m @
, d+ s, r2 H1 ]8 Y: u& M+ W7 lnamespace C__test_01
$ C+ g6 X1 P% m- B2 j8 |" d9 C9 p{
4 N* c( W" t0 t0 `- D6 d- D( k4 r public class Csharp_test ) O4 E5 f5 k0 s( E
{ ! P) k" U- @$ Y; M7 T
public static void Main(string[] args)
! m& {6 S8 P. w, Z( p { ( Y7 H7 O4 V& A" E6 J
Session theSession = Session.GetSession(); # l% K" g3 {& g+ m
UFSession theUFSession=UFSession.GetUFSession();
, t& `3 _0 J l0 S7 i 2 `; T- I1 Z6 w, e1 z
UFUi ufui=theUFSession.Ui;
# [' i6 M# K/ v4 e/ R . g. a. C+ o1 Y3 _) o
Part workPart = theSession.Parts.Work; % x f! d* g+ K k: H
$ l, v; J) L7 h5 C0 @
NXOpen.Features.Feature nullFeatures_Feature = null;
; W- F+ m1 w0 F 7 [% \. w" ~. b+ ^6 ~2 X4 Z1 Z4 W
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
2 J/ [$ v# A3 {5 b* M blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); 0 \/ |( b1 d6 w8 M7 ?$ i
- x" n" ^. p. r blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
) `5 o) k& f: f: f9 [1 h* }
2 n* i& J8 ~4 n# G; ~$ g. x Body[] targetBodies1 = new Body[1];
8 l, G" t0 c: O Body nullBody = null;
; b7 E6 V% r. E! n8 w1 { targetBodies1[0] = nullBody; " o* d5 y& J7 E2 F' @6 H
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算
% k5 W( @) o! t# n3 T
* ]) z% s ]0 S. X' D Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
6 Q; O5 [$ R5 ?. n T 7 ~ A* O( h+ ?2 r- ]! p3 U. d4 \$ p
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
8 E2 Q# Y. A" q X" b" A ! V; Y; X( N6 x' l; l2 A% Q! d
// 使用点构造器创建点 ) g, H5 E) U9 ^
string cue = "请选择一点"; 4 c. O, W9 u* ^' P0 J2 J
UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos; 9 w( Y7 l- a- a8 Y, y8 `2 p9 b
Tag tPt; : J; f U F/ V. O! g
double []base_pt = new double[3]; 3 \. b& z" S, V9 Q
int resp; 9 r$ n+ a8 N$ _( W- e, T3 L( v
% q& k Y) P9 ^5 @ ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp); 7 w: E6 G- ^" U8 L. ^/ k
Y3 z' m1 K" u4 }6 m9 U4 i // 输出坐标信息 / |3 w7 p' A% A( ^
ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
# S' ~! h( Z9 o. k& w' \1 Q
- g/ ]' B, u& J' v; P; t4 T/ K* v Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); & M& D& p6 X1 {6 e& y% `, i
. W: _- h7 G6 p. ~* d) Y
// 设定原点和长宽高
. T- _" I6 q0 {) e. c. I0 g' _ blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); + m5 n& g" |- ~; ?4 d( m
; a# e, ?: X6 x6 Y8 N
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);
, n' T; Q* c8 i- p ; T4 s& _& \/ W& Q
NXOpen.Features.Feature feature1;
, N; t9 i& m0 a; n6 n4 O feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
# |, y( D7 \9 t4 O# |$ h blockFeatureBuilder1.Destroy(); & n: z/ B9 H, f( G l/ ^( F
, w/ K, v, M; e5 D } ) E# S+ ^5 h! O3 d- u4 ~
1 L8 T. a. T q. w public static int GetUnloadOption(string dummy) + D* ~/ s# `( O
{
6 ]' y, S b3 ~( H) X* V8 M2 Z S return (int)Session.LibraryUnloadOption.Immediately;
- n5 |/ e3 s! K& p- N- J7 F } * d: F, J( c6 v, _. H
} 2 D+ d g& T- n: A( ~8 e- m
} * H- O8 t# n, ~+ T, D& _3 h3 y
E' F9 B+ {+ d! e" e* |/ g' y: M2 I
// 仅供学习交流! (smthan@163.com) |
|