|
using System;
: ^: V @7 { @" O+ G) X5 [using NXOpen; ; {! `# p$ t- {( B# E/ e
using NXOpen.UF;
/ A- e" ?5 j4 ]0 ^using NXOpenUI; * y& |/ o% b3 d6 ~* P- L
5 J9 v/ V* j& K. \% G3 z8 R% rnamespace C__test_01
! E3 T: |0 }! p{
0 v/ s3 T4 I- R9 Z% v3 { public class Csharp_test
4 z" t' q4 P& y+ j5 ] {
$ ?/ G2 q& o5 o5 s# K$ m public static void Main(string[] args) : v0 b3 }* c/ D8 d
{ 1 s/ _) E& @4 \7 {& I0 l; Q
Session theSession = Session.GetSession(); 1 b+ r% g1 ?# N' y4 V
UFSession theUFSession=UFSession.GetUFSession();
: x/ q, @# u+ o6 j. i6 K4 m
! A' q. L# n7 b& |) i# V UFUi ufui=theUFSession.Ui;
/ X; g# c4 C# N9 ?
4 l3 k& B6 u$ n% h f) G Part workPart = theSession.Parts.Work;
0 t6 ?: a! c" O1 t; ?
% _$ m# l" p% ?; j5 W" n/ i$ |$ Q NXOpen.Features.Feature nullFeatures_Feature = null; % T- l. @5 M8 N' ~2 B8 w) w
- Q1 B2 k4 l1 S, s6 p9 T4 Y
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; : x! q6 D& R b o. D4 a
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);
7 i( g4 w% b' y. @! ]+ J3 y
1 f$ A' v6 m7 T blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; 3 Y! U6 B* \6 H- x: ^0 O
5 x/ ]( ]' X% @; \
Body[] targetBodies1 = new Body[1];
{0 ^) g8 K4 l6 H+ g4 L8 P Body nullBody = null; 6 U7 e9 A7 q9 ~" U
targetBodies1[0] = nullBody;
% f; M: u7 q; J: J% ~2 h9 a; A blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算 , \& `! K: ^; F) j- _
0 X: i. E( r. U% _. z/ Z* A: E Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter"); % W# n3 m2 ^& |: H; m" S. {
$ a! b# }* b: A3 l$ s
blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
- m) C% _1 H- H p/ [+ [3 u% }
) d7 y( g9 T( n, @0 H // 使用点构造器创建点
& \1 b# ]. {3 I! [. m; B string cue = "请选择一点";
3 o! o$ u: |0 J9 { UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
' R- g: G1 ^: C0 x' _9 n Tag tPt;
4 y! b/ l e( q; J* t: m" y: x+ N9 [ double []base_pt = new double[3];
7 `+ ^3 j5 ~# b$ P' I! C int resp; * Q; V& w/ Y* N0 P( x) u
; W$ G# }7 {( D ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
: |9 }7 R. s* I; \; R$ O" o 7 l$ n% m& a3 d
// 输出坐标信息 3 i8 i4 K& B& H( |9 }' I
ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1);
- H! R9 S$ g Z/ i1 K' m$ {' U
; I( I2 M5 W- v$ u2 F Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); ; d5 c1 ?0 X( ]* J) c9 _
" ]4 v5 o% c* G! P* ~* M7 D // 设定原点和长宽高
5 [" _8 y$ K% Z$ _ l$ {( b blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180"); 6 P4 t; n$ I: |) b9 x! M- I: y: I; z
( b4 @8 M$ e* s4 k( B; J blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);
3 y D1 d# [; \, j7 X- p# m$ H" j
# r) V' ?4 i+ } NXOpen.Features.Feature feature1;
! [. Z5 T% A7 f/ B* ~ feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
& g P( i" i) h W( w& O. ? blockFeatureBuilder1.Destroy();
4 _0 U3 a3 ~9 b! ^) `# C6 }, p
5 `; W1 I5 `( M% o0 E } / e( z9 g9 e$ t" }
; R& q: w5 X, |0 R- y3 f' L public static int GetUnloadOption(string dummy) ; K' Y, T7 k$ ]$ S, O) s2 x+ r
{
% h. J- y, P* u! z$ ? return (int)Session.LibraryUnloadOption.Immediately;
8 q0 F: S; Y$ Q+ w; Z* V# L }
' m4 c: ~0 | m k% J0 } } $ S( H% s/ q6 ^0 O; y
}
! Z6 E8 e- U7 F; B 6 [' X+ j: x9 w; R) p2 J M% s
) Z; E2 D) N) i; H
// 仅供学习交流! (smthan@163.com) |
|