|
using System;
( D$ A7 S+ t) ?/ I0 `4 }1 tusing NXOpen; $ Y H e$ g( ~9 @; M" T' q; f% U1 X
using NXOpen.UF;
' F# z |5 ?( n: Q0 C4 \3 Xusing NXOpenUI; ( p. I' F, v7 Z2 J
# V0 ?$ b- L4 L( m6 y5 g
namespace C__test_01 4 w$ a+ C: q( B
{
+ Z7 R: ]8 ^& U- Y4 n& n3 z9 K public class Csharp_test
) R( a0 b5 B: X5 [) k/ K- u7 B { ; z' Z$ B0 d# T6 j$ o3 A
public static void Main(string[] args)
0 c" _' J4 P7 E5 l6 |4 V. A {
' V1 F. W. O% s3 ?" G Session theSession = Session.GetSession(); - Q& v1 i; \+ o6 d2 W) Z
UFSession theUFSession=UFSession.GetUFSession();
" _8 o; h1 a% D, J5 G & B( ]( n& u. h2 ~& b2 J: F
UFUi ufui=theUFSession.Ui; : w5 G& J4 w) C7 c$ h
* l0 G8 T* S7 j9 T0 ~3 Z
Part workPart = theSession.Parts.Work;
/ e& m9 s+ K. `: L8 q8 q # R3 k- ~6 o7 K9 w5 B: J# t7 Z8 [
NXOpen.Features.Feature nullFeatures_Feature = null; , ?- G( D3 d4 _. x) }0 o
/ |# V. _+ E) }* d \2 O& j+ F4 R. v NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1; 4 o1 q( x8 l9 C" [$ D) E, _
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature); # s8 z0 Q6 ], v' ^
* f9 H* v4 y: b7 g* ?6 c9 R
blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
! U# N! R" |7 l6 T # g4 g; m" M! h5 w3 ^
Body[] targetBodies1 = new Body[1];
4 s: N* u; @/ q' V# x Body nullBody = null;
/ m5 J3 p+ U$ y8 H( _' J4 C targetBodies1[0] = nullBody; 4 j. w" w* f) W
blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1); // 不进行布尔运算 & P V" g' y, X9 F% A f
2 l. r; k- H2 @9 M
Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter"); $ \8 j) q; B6 V
; A/ q0 F, I6 w/ u% \% r9 g blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;
8 i% @% E Q' {6 B8 T' C( {+ n T3 N1 f( q0 G# O& P
// 使用点构造器创建点
/ @* R" M2 f( |* v- G% V; x string cue = "请选择一点";
5 z# K5 W& n) ~2 W UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
+ I2 ~9 z$ ?1 ^- i$ Y5 r; P2 k' ? Tag tPt; ( z2 H% L; z+ @
double []base_pt = new double[3]; / z+ s+ q4 g/ H
int resp;
. c T6 D4 I0 n- }4 u : j- l- _' S( J# Z* p" y
ufui.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp); l" L" G+ J- A$ w0 T
1 R2 j! o, b: H; k; E: w // 输出坐标信息 + I; I& e9 b. R! ]% J) `
ufui.DisplayMessage("x= "+base_pt[0].ToString()+"\ny= "+base_pt[1].ToString()+"\nz= "+base_pt[2].ToString(),1); . \# F+ h* ~( x3 C8 `. p, L. g
& v0 C0 X: ^7 }0 Z0 h Point3d pt = new Point3d(base_pt[0], base_pt[1], base_pt[2]); % q# b; a8 l0 \6 j. Z1 s- J
# | F, r M E1 _, G$ E0 j# X0 F
// 设定原点和长宽高
& ^- D' C6 i8 J+ v/ V# m blockFeatureBuilder1.SetOriginAndLengths(pt,"100","150","180");
2 l* b* x7 n0 s- {0 x6 G; Y , }' d5 c8 X+ Q) }5 x' v
blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);
* O; s2 d m& ?! _( ]) O7 T$ S7 u8 { , U6 q5 r3 x- Y2 l
NXOpen.Features.Feature feature1;
+ `# K* w7 h2 B Y/ o; W. j2 E feature1 = blockFeatureBuilder1.CommitFeature(); // 执行操作 生成block
; f" H$ ^, N; i: S7 B* ~# p v blockFeatureBuilder1.Destroy(); 1 @3 G4 Q" _3 f; u
?& D- B$ U7 y+ U. s5 k- k2 Y
} * a) w5 z7 u3 R) A
2 D5 h4 M# o5 O. k
public static int GetUnloadOption(string dummy)
: V" h4 m' L5 |" \1 r9 Q i7 e: U {
0 y: m9 T r$ Y# H1 j3 a. n+ h return (int)Session.LibraryUnloadOption.Immediately;
+ X: k1 e$ g, r }
3 F7 P4 e* d4 l3 ?( {$ R }
" z: K, {- P; R+ n5 F}
' q0 L+ s1 d/ }# j 5 Z E/ n: n$ S. G3 R9 {
1 N5 R3 [; Z2 s/ X2 G// 仅供学习交流! (smthan@163.com) |
|