Option Strict Off( M6 o7 T4 z* {8 B- k( }; _
Imports System3 e: p1 u' N" O; c
Imports System.IO2 ~2 d2 h( B' _* w( Z' W
Imports NXOpen& I1 c/ z: h: b" Z, k" E( f
Imports NXOpen.Features; w& ?: k/ p' ?% n* D' v: J. _
Imports NXOpen.Preferences
9 X4 e. m5 N ZImports NXOpen.UF
2 w3 n4 D" u z) i! q# w& J; O% r/ f& |8 S& f3 H, H
Module EX_Curve_CreateSplineThruPts
6 ^4 s7 h& c0 S; j5 o
p/ h. X2 ]+ M- g) x( e Dim createMaster As Boolean = False ' set to True if creating a master file
: G: x+ ], u1 D' `' [ Dim testName As String = "EX_Curve_CreateSplineThruPts"8 I" ~; U& v7 Q: h6 ]8 r* W
6 x+ l2 V! f, m& G0 o
Dim theSession As Session
, }. w& A$ G" E( k Dim theUfSession As UFSession( z. V! x/ K1 A: Y1 o1 j& M
; \, `) y6 O. ]+ m, t) E
Public Const UF_CURVE_CRVATR_NONE As Integer = -1
( b1 t7 k2 b' D$ @0 M Public Const UF_CURVE_SLOPE_NONE As Integer = -10 D3 y, ]* C0 n$ s: o% Y
& Y" ]9 U0 \( T& d. U
$ A& @/ U3 C: T; d l
: t2 N+ t" o/ [2 \" K6 L4 g+ Z! N3 h ~0 J; r) n N4 D
Function Execute(ByVal stream As StreamWriter, ByVal theUfSession As NXOpen.UF.UFSession) As Integer
1 ~* d2 u( I9 N: T( z* @- [6 S Try6 c5 z& h$ G" }: I: ]0 ]
Dim PartTag As NXOpen.Tag) @: A9 l: e8 T9 ~6 V S& o( b& H8 v2 o
Dim units As Integer = [UFConstants].ENGLISH( P( r w: P5 j9 Q
Dim PartName As String
9 P7 [$ N( u9 x' U
, S( S$ v+ a1 {7 N# U5 O/ b theUfSession.Part.[New](testName, units, PartTag)9 o9 g h" {( e
theUfSession.Part.AskPartName(PartTag, PartName)
% }8 |- D6 _8 _5 H stream.WriteLine("New Part File Created :-" + testName)
! |7 Z9 z- ?) L z4 M$ I' Q6 a6 L9 |0 K- A1 Y' j
'B-spline parameters$ g" }: \5 Y2 n, u" Y
stream.WriteLine("CreateSplineThruPts Data Creation:-")0 ]9 x0 f# i/ e7 S8 B4 ]
Dim degree As Integer = 3
M# D6 e9 q$ c/ H Dim periodicity As Integer = 0
9 p% p8 K: x* l& Y9 \' h; u Dim num_points As Integer = 5
$ A# _6 v2 }% ?3 J3 W. \& [1 U: S: }' I% n9 a
' Point/slope UFCurve attribute array *1 g/ I, I h3 [# Q2 y
Dim point_data(num_points) As UFCurve.PtSlopeCrvatr: b3 B6 k$ o6 W! M7 U
6 _" p, U0 \# x+ L# ?& X3 _
'' Arrays of user's defining point data . g) \' i( j6 S2 ]# z' C5 {
Dim parameters() As Double = {0.0, 0.17, 0.32, 0.45, 1.29}
) j; L9 {5 d$ z- S Dim points() As Double = {1.1, 0.532, 2.0, 1.524, 0.6789, 2.3, 2.0, 0.9, 3.5956, 2.3456, 1.3456, 3.789, 3.1, 2.4567, 3.3214}
0 e' H9 r Z* I- c5 a5 K$ R' {/ E1 H3 h; m
Dim slopeTypes() As Integer = {[UFConstants].UF_CURVE_SLOPE_DIR, [UFConstants].UF_CURVE_SLOPE_AUTO, UF_CURVE_SLOPE_NONE, [UFConstants].UF_CURVE_SLOPE_DIR, [UFConstants].UF_CURVE_SLOPE_VEC}
+ c0 H& S* u% B Dim slopeVecs() As Double = {1.23, 5.0506, 4.036, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 1.0, -2.0, 1.0}8 ]: K0 S3 D) s9 I8 F4 }6 e9 f
Dim crvatrTypes() As Integer = {UF_CURVE_CRVATR_NONE, [UFConstants].UF_CURVE_CRVATR_AUTO_DIR, UF_CURVE_CRVATR_NONE, [UFConstants].UF_CURVE_CRVATR_VEC, [UFConstants].UF_CURVE_CRVATR_VEC}: Y2 Y- K0 S; f# h
Dim crvatrVecs() As Double = {0.0, 0.0, 0.0, 1.0, 2.578, 5.67, 0.0, 0.0, 0.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0}
8 A9 `; q& q- u, t3 `6 j
* D& I9 I% f; _7 g3 {- o Dim save_def_data As Integer = 1
# u& Z, R& h0 h# q Dim spline_tag As Tag
- i- G& C2 x( b6 R- `- L {7 U* j4 E+ D, Z1 r7 y& N) p0 n
For i As Integer = 0 To num_points - 1
# U! e: k, C7 V. _9 h" W point_data(i) = New UFCurve.PtSlopeCrvatr) U) e9 I% `( g" b& c: z; l
Dim tempPoints(2) As Double
' d* }5 }! \# Z" C. ~5 n( Z tempPoints(0) = points(3 * i)! _5 \- x3 k! ~% x
tempPoints(1) = points(3 * i + 1)! Q' t5 n- Z* b \: F# L5 ^5 v& i
tempPoints(2) = points(3 * i + 2)
! L' c: z. W; G& o: O8 Y, d point_data(i).point = tempPoints0 s' z# G! h1 I8 H4 {) Q2 E9 S7 f
point_data(i).slope_type = slopeTypes(i)
( f3 l9 z K2 R% g Dim tempSlope(2) As Double
3 Z" l" \9 k+ `$ K$ A tempSlope(0) = slopeVecs(3 * i)
- _/ K# p9 j! w1 T tempSlope(1) = slopeVecs(3 * i + 1)8 C1 f8 f5 S# _0 U
tempSlope(2) = slopeVecs(3 * i + 2)5 u" ~( ]: H1 b
point_data(i).slope = tempSlope
+ K" a9 K& {9 K: _8 H" ~# F9 `+ |, Z point_data(i).crvatr_type = crvatrTypes(i); S& v5 j# K9 G) ~1 j6 m, I' ]! s
Dim tempCrvatr(2) As Double
# J I* e2 F0 E9 m& p, u1 f tempCrvatr(0) = crvatrVecs(3 * i)2 H8 V2 s. F* |: }8 J
tempCrvatr(1) = crvatrVecs(3 * i + 1)
3 j) V- d; t' b9 [/ I8 M. e5 J tempCrvatr(2) = crvatrVecs(3 * i + 2)8 Y+ _" ?# R$ S( ^) l, z
point_data(i).crvatr = tempCrvatr
, R# o" p* `# X Next
) h7 g" \5 k/ F2 B stream.WriteLine("Successful")7 y+ @7 n! }$ L; o$ P; G. C
'Create B-spline UFCurve 1 W. s3 A( l9 Y' a
stream.WriteLine("Create Spine Through Points= ")
. R3 c/ \! T# D: V- m theUfSession.Curve.CreateSplineThruPts(degree, periodicity, num_points, point_data, parameters, save_def_data, spline_tag)) Z; {; V. M2 I
stream.WriteLine("Successful")$ z5 e/ e7 |1 V
" L6 T) _1 `- C$ b% U/ `* z
'Ask spline thr points parameters
e4 L* A$ _* v: y9 @ stream.WriteLine("Query Spine Through Points= ")# |; ^6 t! t4 t7 |7 N! }: e$ D- ]8 v
Dim ask_degree As Integer
4 B/ W0 X: {; }8 v7 X4 q Dim ask_periodicity As Integer0 `& b0 K- W. R" }
Dim ask_num_points As Integer
! G8 |, E$ `& d- _- @' \# {" c. E Dim ask_parameters() As Double
8 J Z- P5 D4 ]: X/ m4 n# Z Dim ask_point_data() As UFCurve.PtSlopeCrvatr
$ f) e3 S2 r" @* k theUfSession.Curve.AskSplineThruPts(spline_tag, ask_degree, ask_periodicity, ask_num_points, ask_point_data, ask_parameters)
! f( I, _1 v, z4 {0 p7 [) `$ I stream.WriteLine("Successful"); m0 s K( U2 s1 p. R% _
stream.WriteLine("SplineThruPts Data"). u- ]7 t( m" }$ m1 B0 e
stream.WriteLine("degree= " + ask_degree.ToString) w1 d1 J0 V7 p3 d, x: _( L
stream.WriteLine("periodicity= " + ask_periodicity.ToString)% K5 `0 k/ H, r# A0 J' M0 C3 _
stream.WriteLine("num_points= " + ask_num_points.ToString)
' m: c/ F& x& o( x stream.Write("parameters= {")
6 }( O4 f# J3 X6 z For J As Integer = 0 To ask_parameters.Length - 1
+ z1 c2 R% q8 ]: v stream.Write(ask_parameters(J).ToString)
, x( I6 y" t5 u* z; ~ if(J < ask_parameters.Length - 1)- t, }$ A# n% t# F+ o! t* {& [
stream.Write(",")3 p6 Q/ [3 W& Q2 o0 f
End if
7 B9 k3 K5 ~: E% ^6 k: R6 T& w3 b Next9 J! _' J6 p7 D
stream.WriteLine("}")2 D6 ]& [) ?! w5 @& u1 C) X; V
3 S6 p$ {2 m5 K" W* f stream.Write("point_data= {")4 ]% o6 z3 I( _+ P5 L6 h2 t! d9 A
For i As Integer = 0 To ask_point_data.Length - 1; l* U/ o' W" A* f9 g$ z
stream.Writeline("------------point_data[{0}]", i)) w7 h! P3 o3 J9 |$ {
stream.Write("point {")" E0 b( u3 j: O
For j As Integer = 0 To ask_point_data(i).point.Length - 1
2 h, K: g: u2 m: _1 F stream.Write(ask_point_data(i).point(j))8 Z9 ^" \; d& n Q2 L, }# v+ {* f% p
if(j < ask_point_data(i).point.Length - 1)
9 z" _ c* W, C( X4 k stream.Write(",")0 R$ D. d9 x( e& L6 Y: E3 X
End if
' ` |/ b- P6 Q4 K Next" \3 {: Q0 K+ @( W, }6 P3 l
stream.WriteLine("}")
5 z, }* t/ j% }% w, N( F stream.Writeline("slope_type " + ask_point_data(i).slope_type.ToString)3 i! F- O# y; z3 Q5 L# ^% a) I: a
stream.Write("slope {")
+ z/ W' I1 ~! }8 t& d9 G For k As Integer = 0 To ask_point_data(i).slope.Length - 17 @! l; ?: ?. X+ U, ]1 Z
stream.Write(ask_point_data(i).slope(k))
) b7 u4 s8 T7 n8 T6 J' u" j if(k < ask_point_data(i).slope.Length - 1)
2 F3 I9 d% W0 Z( M/ F stream.Write(",")! f( d/ I4 h$ I6 a/ J7 U6 @$ }' T
End if
& c' }2 J0 s+ b; z+ o4 ~! J Next% }5 ]3 ^& d* {4 ], ]) s# \
stream.WriteLine("}")
1 F$ }( t- h2 p/ n1 T3 G stream.Writeline("crvatr_type " + ask_point_data(i).crvatr_type.ToString)
- m6 E$ g$ E; k2 { stream.Write("crvatr {")
6 q7 K4 f) i( ~, ]. @9 u4 \ For l As Integer = 0 To ask_point_data(i).crvatr.Length - 1) o7 q2 J4 H0 d6 P
stream.Write(ask_point_data(i).crvatr(l))
. f: J5 a9 T8 _0 p. @. M% U7 U if(l < ask_point_data(i).crvatr.Length - 1)
/ D2 d/ ^$ Z, ` stream.Write(",")
" M) U) |' H+ C; F& I6 `) ~* c* d End if
, B( w7 H9 d% ]2 ^, l. s0 { Next9 g- O- u$ N6 x) o% F3 ?
stream.Writeline("}")! Z+ s) y0 U5 a8 N
Next
6 i% z9 l5 B6 f( C. [6 i* A x0 R, n V
theUfSession.Part.Save(): u& a4 U) g# U$ n* B$ @' N
" A- ~6 y0 K' j" r! Y
Catch ex As Exception% [7 o7 g, e" s) d; z7 X
stream.WriteLine("EXCEPTION: ", ex.Message)
( y8 x. K/ k6 T, z5 r3 t) J: } Return 17 ?, r5 h- o0 p4 k7 } U6 d
End Try- \; w/ g6 J, \1 J1 {3 ?
Return 02 n: k% G' O5 B& k' T5 ~! e
9 {: q7 \( F4 ~' f+ c& t* \
End Function
% \7 Y- s+ n$ [( ^ t H4 C- M8 |# P1 e0 c& v/ V
End Module |