Option Strict Off2 b# b8 m; R! N/ W3 D, J
Imports System i/ V' a- L! ^' p. h. M
Imports System.IO; ]4 v- U' J! [
Imports NXOpen
7 ?' j, j6 t# l2 H; l: FImports NXOpen.Features
/ Q. |! A7 ]) G" x) f3 n1 Y# {Imports NXOpen.Preferences$ B& O1 r- z) B. V3 C8 A- L' b
Imports NXOpen.UF
9 Z3 P7 A/ M& |" W! V& o
: ], m3 I' o* `: f5 O( z4 {( iModule EX_Curve_CreateSplineThruPts
( L1 [9 s4 v' V6 s7 @ O- ^7 b3 V9 ^3 V0 K( i% d1 X8 K5 d! E
Dim createMaster As Boolean = False ' set to True if creating a master file* r: d) p. `. `' _
Dim testName As String = "EX_Curve_CreateSplineThruPts"
: o! V* I" J! V$ s4 ?
4 l" L# x9 X( D1 M0 O! _" } Dim theSession As Session: J0 o. b# O- e$ z! T
Dim theUfSession As UFSession4 `8 Q7 B$ E8 }, {+ Z" A) q" L
( u( K9 ]9 ]* K8 x' J$ w1 F3 Y0 I
Public Const UF_CURVE_CRVATR_NONE As Integer = -1
/ r' \4 O" K1 V Public Const UF_CURVE_SLOPE_NONE As Integer = -1# `1 g7 g- V/ k: k) s
; g9 W, g. w3 G& e
0 L4 R9 B- T9 v+ {- A
7 }8 r/ D U4 L& g% N& A
! L- h4 }7 H* x: V5 w
Function Execute(ByVal stream As StreamWriter, ByVal theUfSession As NXOpen.UF.UFSession) As Integer% k/ W, D3 c1 ?! [
Try
/ y. r. Y6 } z) m5 p* C Dim PartTag As NXOpen.Tag( n+ N$ w. W% M# b! s; Y
Dim units As Integer = [UFConstants].ENGLISH
: ?" ]4 X+ f2 _+ m% G Dim PartName As String
. f( c. E. l$ z+ W; Q. ~" X2 C& X5 @
% s* E0 u+ V6 r theUfSession.Part.[New](testName, units, PartTag)
- e) S0 o/ H6 E4 m( I/ Y theUfSession.Part.AskPartName(PartTag, PartName)
0 C, G& A# w, Z1 q! [) I stream.WriteLine("New Part File Created :-" + testName)
\9 i; S8 W8 B5 E% s) J8 v- r% X( r9 X
'B-spline parameters% l# o a9 A9 y
stream.WriteLine("CreateSplineThruPts Data Creation:-")
5 i, B1 m. r2 u m/ t3 n Dim degree As Integer = 38 D; ]9 Q6 d" D5 A# ]$ @: t
Dim periodicity As Integer = 06 a: K0 |" W- z+ B3 P/ N* F
Dim num_points As Integer = 5
9 n& T4 O# z+ o$ ?9 a, `% n7 ?# | s! p& }$ E
' Point/slope UFCurve attribute array *) g3 p) y1 E+ F3 b4 L. {
Dim point_data(num_points) As UFCurve.PtSlopeCrvatr
3 X/ J8 g# x% [2 _" _# y
) s. B0 x6 I# t4 c '' Arrays of user's defining point data K% c" h, q {- W0 ]" s; t8 k
Dim parameters() As Double = {0.0, 0.17, 0.32, 0.45, 1.29}' N6 g& v7 k. N0 b: E* \* T
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}8 s* r$ S) b; c3 R3 f
$ _% ]6 l6 J4 p' C) |2 S 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}4 C6 m3 Y# V/ A8 e* S+ s
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}' i# S$ w8 P, T% Q d
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}5 z J: W+ N. R' Y, |% p
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}( r! b, J& w, v3 M+ O
4 w& Q7 O2 N5 D8 i% Z. j4 B7 p
Dim save_def_data As Integer = 1
. Y* p4 I6 K; [ Q1 Y% S Dim spline_tag As Tag
. m% D3 h( y" a( g
) d2 \* e) W$ _5 r5 Q! t For i As Integer = 0 To num_points - 1
4 ?& P( X. Y9 o( ]+ \; s1 W point_data(i) = New UFCurve.PtSlopeCrvatr6 c" C% X4 J- t( N, D
Dim tempPoints(2) As Double
) @, m0 t- E' v$ n7 F% [- X; E tempPoints(0) = points(3 * i); i7 J% w* H2 v$ a" `! m& M
tempPoints(1) = points(3 * i + 1)$ T: Q t% `( I" c9 W
tempPoints(2) = points(3 * i + 2)
! b% R! C, x0 ^5 {% E: ~ point_data(i).point = tempPoints, p i' R7 N) H. ]% M4 G Y p& r
point_data(i).slope_type = slopeTypes(i)
2 _/ L( O/ _- v8 _ Dim tempSlope(2) As Double; {3 w2 M. {. O% H: l, ~
tempSlope(0) = slopeVecs(3 * i)
9 [# A j4 Z! M7 r' ^ tempSlope(1) = slopeVecs(3 * i + 1)
& K, _7 u& ?6 b" J; o% R tempSlope(2) = slopeVecs(3 * i + 2)
) }4 m. M2 U2 h, g* L" E( z1 D$ X- C point_data(i).slope = tempSlope
: ]! G" d7 k* d( T# `& X% I4 m. X point_data(i).crvatr_type = crvatrTypes(i)& @" m0 W* ?/ _' e- Z, _& O# M
Dim tempCrvatr(2) As Double, s7 P: \1 c9 E- I0 v
tempCrvatr(0) = crvatrVecs(3 * i), X; e2 u& k6 @! ^9 X- j
tempCrvatr(1) = crvatrVecs(3 * i + 1)8 H# q( Y% |: D! l& K* p
tempCrvatr(2) = crvatrVecs(3 * i + 2)
9 w1 I+ U- J% J2 X% B point_data(i).crvatr = tempCrvatr
4 G& E# ]- e% Z3 }# J+ g Next
" x: ]. M4 _& r1 O4 n' C stream.WriteLine("Successful")- I' T; X+ {2 w, A; x
'Create B-spline UFCurve + ?8 \$ m' b% B/ k5 J
stream.WriteLine("Create Spine Through Points= ")& h8 H; P, Z, [1 b
theUfSession.Curve.CreateSplineThruPts(degree, periodicity, num_points, point_data, parameters, save_def_data, spline_tag)
& A4 z- o/ ^( S5 Z( { stream.WriteLine("Successful")6 Y; Z1 R, o d" m
4 `# y V/ y3 I 'Ask spline thr points parameters
" E0 ~& K7 c! N( b' R! N9 N stream.WriteLine("Query Spine Through Points= ")* _1 Q) L+ m% ]( q; ^* _
Dim ask_degree As Integer% u. H. I( |! c Q. J. P
Dim ask_periodicity As Integer6 G7 e4 M3 U* l2 i( I8 L5 S
Dim ask_num_points As Integer
- V S1 E' u/ \, {& p: i; B Dim ask_parameters() As Double
% P l8 C$ o9 J$ m5 ]9 H Dim ask_point_data() As UFCurve.PtSlopeCrvatr
! S9 K/ l( r7 A& }( _4 t0 U9 ~ theUfSession.Curve.AskSplineThruPts(spline_tag, ask_degree, ask_periodicity, ask_num_points, ask_point_data, ask_parameters)# N6 L0 `; e3 A1 q; _" f" Z$ F i
stream.WriteLine("Successful")' Z0 K/ L0 X* a# f1 l4 ~: L
stream.WriteLine("SplineThruPts Data"): z- v, D$ o+ m
stream.WriteLine("degree= " + ask_degree.ToString)4 t+ T- ]# ^ x7 b& k/ s
stream.WriteLine("periodicity= " + ask_periodicity.ToString)
7 Z" [9 C: z4 g/ @% \: ?8 Z' T: t5 s stream.WriteLine("num_points= " + ask_num_points.ToString)* P/ T3 m) w. i" a2 m& R. U
stream.Write("parameters= {")- L1 P0 N! ]3 g9 V/ y
For J As Integer = 0 To ask_parameters.Length - 1
9 y2 ~3 Z2 R2 I2 s stream.Write(ask_parameters(J).ToString)
4 {* ]( [: Q' F! ~/ O if(J < ask_parameters.Length - 1)2 ~$ o: ]! W7 ~
stream.Write(",")
' w f' Y5 i. u, J! S End if
. H/ R5 o" `% m5 y# x Next& F N4 R" C1 Y' L( \' W3 w u1 r
stream.WriteLine("}")$ C* g! k j5 T$ a0 h
M3 i9 H# U. c; X
stream.Write("point_data= {")
$ e5 _9 \) f s2 ~ For i As Integer = 0 To ask_point_data.Length - 19 G0 E; g( K) F! b; w+ ]. \
stream.Writeline("------------point_data[{0}]", i)
" f! [: ^/ w3 z$ w7 Y7 }6 h6 k stream.Write("point {")! ]! k* L, o0 A* m4 n
For j As Integer = 0 To ask_point_data(i).point.Length - 1) U b2 y2 J$ W7 n; X, h2 f7 N
stream.Write(ask_point_data(i).point(j))% K, b( e) `; d3 }$ |# l+ Y
if(j < ask_point_data(i).point.Length - 1)& S2 _# S$ k6 L: p2 k
stream.Write(",")
% Y7 u/ z) w/ [( H7 P6 ?1 Z End if
/ f H7 j* T) S8 t2 m/ L Next
; J( [+ {4 ]3 l. s stream.WriteLine("}")
/ V2 e( u4 A8 u& p5 p stream.Writeline("slope_type " + ask_point_data(i).slope_type.ToString) u. T- U z# Z) b7 z! z, S
stream.Write("slope {")
* `( X/ E$ ~. z7 H& r: M& _' I s For k As Integer = 0 To ask_point_data(i).slope.Length - 1
1 b5 E& Y& P3 U# o1 \" x stream.Write(ask_point_data(i).slope(k))
8 G' q% R' E) q4 g: @$ ^+ @ if(k < ask_point_data(i).slope.Length - 1)+ N& F/ G8 C- d7 j
stream.Write(",")9 C h1 p& z9 w! L4 c0 i
End if$ L) Q t5 v4 z9 \
Next% O: W. L* y6 A
stream.WriteLine("}")
9 U0 T0 h, l, Q! g. X stream.Writeline("crvatr_type " + ask_point_data(i).crvatr_type.ToString); U- p- ]. S. H( p. u, Q3 p+ a
stream.Write("crvatr {")
$ {" h1 w" N9 k% ^2 j# j+ b( s2 F For l As Integer = 0 To ask_point_data(i).crvatr.Length - 1
+ @4 g4 R$ { E9 } stream.Write(ask_point_data(i).crvatr(l))% D/ X8 O( D; p3 H7 B% }$ ?4 U
if(l < ask_point_data(i).crvatr.Length - 1): ]# q, ?: \. L) q
stream.Write(",")$ |1 u/ [. K4 v$ F: g% }) J
End if0 M' w6 y w: F1 Z! S7 c% i- d
Next
; Y8 K( T2 V& |7 z6 S stream.Writeline("}")
" o8 o, H# c2 U: ?9 ~ Next6 Q0 v! v L) @
8 l* G- r# d5 \3 F/ U9 T
theUfSession.Part.Save()
, G* j. L" ~2 x) q" Q0 @* h% k' L1 s! q
Catch ex As Exception) T: a1 _% C6 z. T+ o$ B5 P! t
stream.WriteLine("EXCEPTION: ", ex.Message)
* h! @, Q( g2 g. _1 \0 b4 C# R0 s" ] Return 1
6 l9 R; J: d0 ?6 U End Try
$ D% I; d% x- ~2 m/ ]7 Q. p- v Return 0: G) |0 R9 N5 I
- K3 X w% A/ I7 m6 V' Y9 J End Function
+ o; E9 P0 i9 X4 b( p1 I. \
5 f- g/ u! s5 E- c: z0 I+ z# [End Module |