Option Strict Off
4 G4 ]6 W' I7 w1 X' r6 B a6 ]6 fImports System' e" \8 n4 K4 R7 ~# V3 h- ~
Imports System.IO
) D; ^) _3 \( ?0 g+ E4 C* t8 eImports NXOpen
* p+ @7 D8 a( w! D% x0 NImports NXOpen.Features
: p6 ?4 i/ z' ^ C a1 z0 z. Y9 ?Imports NXOpen.Preferences$ _+ m [# z3 t. k7 B* b
Imports NXOpen.UF4 K% n% U& ?* y, y& z/ k0 ~* Y
2 e3 M$ l3 e" F
Module EX_Curve_CreateSplineThruPts
( K+ N* x6 e1 h, O4 A$ F) M/ b9 [! P. H* {8 Z) K2 E+ v7 p
Dim createMaster As Boolean = False ' set to True if creating a master file7 e6 V8 W1 g* b# x
Dim testName As String = "EX_Curve_CreateSplineThruPts"; m( F6 Y. p0 I' P
% ]% Q; V- X) D0 f
Dim theSession As Session
$ t. z& Q: m* V- `* v Dim theUfSession As UFSession
* t9 Q! O5 {" w0 {% t! e# S/ _
Public Const UF_CURVE_CRVATR_NONE As Integer = -1
: @; @. G* g* L7 l2 g2 ^4 a5 p5 b Public Const UF_CURVE_SLOPE_NONE As Integer = -1) X8 f# m( i1 W
, d ?9 ^, R6 X2 m8 q# q- N1 ^3 U) D8 r/ e
$ A" O4 L& ?% E- r9 P
% P' I9 K: {& w
Function Execute(ByVal stream As StreamWriter, ByVal theUfSession As NXOpen.UF.UFSession) As Integer
; o _8 k5 |' ~; l' m+ {% _$ t. _ Try: }7 v' |9 D" R }0 H
Dim PartTag As NXOpen.Tag9 _. z x( x; r+ B$ d
Dim units As Integer = [UFConstants].ENGLISH) [8 h$ z9 a4 n
Dim PartName As String
/ Y3 G/ Z& n+ T3 R1 X" t K" [: L9 L0 w! M5 o2 W1 n: a) w
theUfSession.Part.[New](testName, units, PartTag)8 `7 l5 C; Y: P$ O* t8 S
theUfSession.Part.AskPartName(PartTag, PartName)1 A$ A5 X" m5 m% F; u R( Q
stream.WriteLine("New Part File Created :-" + testName) p, Z0 a$ y6 _0 J% _* y
1 c8 U: {& E+ r* F 'B-spline parameters
7 b2 O* S( f% Q& H stream.WriteLine("CreateSplineThruPts Data Creation:-")% ]0 n& \" y/ ^# d( P
Dim degree As Integer = 3 p+ p* @; z( F7 @$ ]! R9 v8 R0 h; s
Dim periodicity As Integer = 0' x# a& N2 r- m5 @1 ^
Dim num_points As Integer = 5
) l# i% y) Y a6 C( g; p- l% \8 ^# ~* O3 @! q% o" { |5 f7 x
' Point/slope UFCurve attribute array *
; {0 _6 {/ Y, E* m3 \ u. n Dim point_data(num_points) As UFCurve.PtSlopeCrvatr
' w, a) B: C% f$ ?: ^' U3 Y) n+ b" O* m& e
'' Arrays of user's defining point data 4 O( F% h8 N& c4 ^: J Y9 S
Dim parameters() As Double = {0.0, 0.17, 0.32, 0.45, 1.29}
3 R, K9 Y& E! q' X 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}
& E* v8 \1 J" i( j5 N* B2 ]# W: s, b/ ]0 z6 I
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}
' Y/ _4 _, L0 _2 S: S: h( \) g 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}7 v# K& i0 w1 h* K- {
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}- c0 U! n3 q/ I) S7 s: M
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}
$ c9 i, P! |/ f( I
( y# z! i: ~/ X2 b Dim save_def_data As Integer = 1
& Q' r- I3 V- Q6 C Dim spline_tag As Tag
% i+ [/ B9 L/ a! z# G5 i- u! V8 L; K9 `) o) v. ~/ ~
For i As Integer = 0 To num_points - 1 O$ k/ Y2 Q6 l T% p* B+ X/ [
point_data(i) = New UFCurve.PtSlopeCrvatr
# n# i7 {/ N+ `0 G4 H5 N Dim tempPoints(2) As Double
3 s) M% V9 U1 H0 n4 M% n. r tempPoints(0) = points(3 * i) H" ?1 ?+ ]0 \& T. M( Z7 A R: w
tempPoints(1) = points(3 * i + 1)5 A y% d) k4 U2 Y/ s
tempPoints(2) = points(3 * i + 2)
3 `& i! c: E1 u# z: U point_data(i).point = tempPoints
' }0 O' G6 s8 r; j point_data(i).slope_type = slopeTypes(i)
0 V& b2 u2 O1 I% l5 \8 p Dim tempSlope(2) As Double
9 z' ]! _ P @7 l/ Q( C L tempSlope(0) = slopeVecs(3 * i)
0 X" F. D t5 X" v- x: f: O* g& n tempSlope(1) = slopeVecs(3 * i + 1)3 H l9 z8 b5 G4 X1 ?+ @: D7 h
tempSlope(2) = slopeVecs(3 * i + 2)' C( ~* o+ R& N1 Q
point_data(i).slope = tempSlope) c( k5 S5 M0 ?( }
point_data(i).crvatr_type = crvatrTypes(i)* R9 X& E% z9 t+ S& n2 L7 H8 O
Dim tempCrvatr(2) As Double
) F) E1 l: E: `& z tempCrvatr(0) = crvatrVecs(3 * i)3 C1 K+ l5 K; v' N& O4 Q
tempCrvatr(1) = crvatrVecs(3 * i + 1)6 U: s. `% {% g
tempCrvatr(2) = crvatrVecs(3 * i + 2)
" G* F$ a5 k: K/ R9 l2 i point_data(i).crvatr = tempCrvatr
4 E& ]& S5 q! I0 H, p Next
" v; u' w$ V! e) L stream.WriteLine("Successful")7 ~' G+ k) n' _/ _
'Create B-spline UFCurve
0 A2 J6 }0 s1 C( f, ?( v9 ^ stream.WriteLine("Create Spine Through Points= ")
6 y \/ K4 ^# @/ i, j6 s, |9 x theUfSession.Curve.CreateSplineThruPts(degree, periodicity, num_points, point_data, parameters, save_def_data, spline_tag)4 J+ _4 B4 r, C& s
stream.WriteLine("Successful")
* r' U7 A1 b3 W o
& \$ W7 Z# r; Z) t) | 'Ask spline thr points parameters% }% l' D0 l; {" O
stream.WriteLine("Query Spine Through Points= ")
8 |2 U/ B7 H8 u$ J Dim ask_degree As Integer5 P) |8 E. M/ B! j4 ?3 v5 }$ S
Dim ask_periodicity As Integer
* V5 I9 i A: R" `' e) I Dim ask_num_points As Integer- S8 ~5 d# j! [2 [5 ]
Dim ask_parameters() As Double# V7 z: m0 p8 d& j" @# N
Dim ask_point_data() As UFCurve.PtSlopeCrvatr
F# U1 t+ R8 T/ W theUfSession.Curve.AskSplineThruPts(spline_tag, ask_degree, ask_periodicity, ask_num_points, ask_point_data, ask_parameters)9 z9 l1 K( a$ N9 @. y# J% j
stream.WriteLine("Successful")
0 G! N# H5 U7 K* ~! P, v+ x stream.WriteLine("SplineThruPts Data") t( @$ G* I3 j1 X, Z6 z
stream.WriteLine("degree= " + ask_degree.ToString)
8 j: ?7 S! o! y+ |9 u( [1 i stream.WriteLine("periodicity= " + ask_periodicity.ToString)' I& D! ~8 ?1 Z6 P* B1 V
stream.WriteLine("num_points= " + ask_num_points.ToString)
4 f( O6 M$ L# }) s stream.Write("parameters= {")& [# P5 T8 J/ a# a2 g/ w
For J As Integer = 0 To ask_parameters.Length - 1& w2 ~3 z G- W3 _1 k
stream.Write(ask_parameters(J).ToString)
& L/ \" R: R2 x- @ n6 a7 R if(J < ask_parameters.Length - 1)# s! l7 \' X; N; c6 n; `) K" Y
stream.Write(",")
1 Q6 Z& r; N5 O9 p& A* f8 K; ] End if! C/ x6 `2 v! ]! ~2 l
Next
1 T8 F6 J) E/ s5 a/ T stream.WriteLine("}")+ A& K2 ?. d% Q, L% X/ g
$ c: h5 m' S: |! o3 _+ R6 k stream.Write("point_data= {")! E' q C: q7 a( Z2 ]3 R7 d
For i As Integer = 0 To ask_point_data.Length - 1
8 k! @6 i& m, V/ z* g6 G* d5 v stream.Writeline("------------point_data[{0}]", i)9 n9 ]8 F* i+ q0 C+ h; B
stream.Write("point {")) Z" l" u* g- P
For j As Integer = 0 To ask_point_data(i).point.Length - 19 _2 k( _) D8 G
stream.Write(ask_point_data(i).point(j))1 E8 x+ N# N' P
if(j < ask_point_data(i).point.Length - 1)0 v3 }# }5 x7 @5 A
stream.Write(",")
' o$ H* @$ r8 s7 _! G) Q End if7 D7 _3 F0 m9 i, O! k# T7 Q
Next
! z+ f ^) F( c. G. s& y stream.WriteLine("}")5 v! p/ z/ U! g2 I- L" R' `3 T3 X, c
stream.Writeline("slope_type " + ask_point_data(i).slope_type.ToString); q+ r( T6 w: F5 _4 O' i
stream.Write("slope {")8 S% q# A E+ B5 B& ]1 @# _
For k As Integer = 0 To ask_point_data(i).slope.Length - 1
. d( w! I N8 X1 M stream.Write(ask_point_data(i).slope(k))# h- b. {& b3 W# C
if(k < ask_point_data(i).slope.Length - 1)2 p, E# P4 Y' X. a% A) t& ~
stream.Write(",")
; c' o# H4 a9 ~% q; ` End if
4 u1 G5 s" Q+ l4 a* x* s% R" K Next) u% g! h; H3 a
stream.WriteLine("}")& B; a. O: X) ]( o
stream.Writeline("crvatr_type " + ask_point_data(i).crvatr_type.ToString)
5 [+ m+ W4 E1 R Q& J: N stream.Write("crvatr {"), n3 b) ?; g+ V- z. S1 E" ]4 l
For l As Integer = 0 To ask_point_data(i).crvatr.Length - 1$ x2 r6 ]% k F0 O+ a# n
stream.Write(ask_point_data(i).crvatr(l)): r" C1 [9 c n- A
if(l < ask_point_data(i).crvatr.Length - 1)
# z/ {3 C: {6 k* q0 d! B stream.Write(",")- a! k/ h# V) i
End if
1 _2 t9 H$ [7 n' {9 U3 m Next* C. O5 z% e* @% L0 o7 O' c
stream.Writeline("}")
# I, g9 W3 @( W+ W8 K Next
7 G+ E# C* i, M$ `- F. @+ t1 D' L% c$ N5 M' W1 h$ q- r0 f+ o4 c
theUfSession.Part.Save()$ B* ~2 W7 L! Z+ P
* k+ I' O+ }! Z Catch ex As Exception
: ~/ I& ^3 \9 V- L! [3 K; u6 W" m stream.WriteLine("EXCEPTION: ", ex.Message)4 H, F, M2 v" a6 X8 ]( u; C
Return 1
) r8 X; x+ ]$ P; A End Try* @, D- m9 l. F/ r- A6 X8 @
Return 0! b x* b/ a N/ g6 x
+ t- x3 P e5 } K% c End Function5 ]& y( T8 a& U
) ?' r4 d! p. M$ b1 FEnd Module |