Option Strict Off" o5 U' A0 N @2 @% Q
Imports System
+ c/ z: O0 x: X" O+ w* m) j4 C) \Imports System.IO& R& t$ W( v4 y+ n/ `! H8 S, C
Imports NXOpen
( Q0 d& y: `9 p4 Z" TImports NXOpen.Features
- d0 R2 [4 M- s% R9 JImports NXOpen.Preferences
0 M4 E4 Y' t3 V# _9 D" gImports NXOpen.UF V0 U' |) ^- ~# R9 F& m" M. S, w
0 ^# q1 e& d( Q1 D+ }
Module EX_Curve_CreateSplineThruPts
" q4 d5 f5 A" a( g
3 |! ^- T& K/ X9 q+ ^! j Dim createMaster As Boolean = False ' set to True if creating a master file6 d" Q4 T1 B3 a2 l
Dim testName As String = "EX_Curve_CreateSplineThruPts" l2 u/ ]$ L* f+ M, }
8 F$ g" _( D5 U# {8 M Dim theSession As Session% h( i$ `7 I) ^/ b9 u% q2 `0 s) r+ I
Dim theUfSession As UFSession
* P& c }8 {9 e4 }
- U" r m9 l) S! u% n Public Const UF_CURVE_CRVATR_NONE As Integer = -1
6 R# K. G5 r% {+ V% y4 Z4 } Public Const UF_CURVE_SLOPE_NONE As Integer = -1
$ _' W( J5 I( l u1 L- I" T$ K2 A0 i6 H9 p0 j
% l# j# j4 v, a, v' j5 ]; }
& y* r: z* i* k8 @ c& g7 T
! a u) y, d7 U1 H% J Function Execute(ByVal stream As StreamWriter, ByVal theUfSession As NXOpen.UF.UFSession) As Integer+ q+ |2 ~& t1 X2 ]/ N& U% z4 U* v
Try
, o& ?3 h; V* X$ `" t& T Dim PartTag As NXOpen.Tag( W5 n* z4 s9 S
Dim units As Integer = [UFConstants].ENGLISH
; D. H7 o! W4 u8 }) F8 R! d Dim PartName As String) C$ @2 O5 m) F
' t" A. u" ]% M' @8 \% r9 \ theUfSession.Part.[New](testName, units, PartTag)
/ {% r F5 r: E theUfSession.Part.AskPartName(PartTag, PartName)
# Z5 }: X5 J, v" `& Q9 {. _, b. v stream.WriteLine("New Part File Created :-" + testName)
; d' m3 f0 @7 j1 d# W4 }3 U/ H2 s8 Z. R" f! V/ y
'B-spline parameters" R& ?2 Y+ D& c0 P2 [
stream.WriteLine("CreateSplineThruPts Data Creation:-")
/ [1 w/ \7 v7 D8 z Dim degree As Integer = 3
' z# M- W& V1 [5 y8 V Dim periodicity As Integer = 0* W2 Y& b* R5 j$ H4 c& Y0 R
Dim num_points As Integer = 53 R; E+ E' |, X5 i t; Z; ?. S$ D
@) v: K1 B; N5 {; q ' Point/slope UFCurve attribute array *4 Z; V9 V/ T" ~) L1 W0 R
Dim point_data(num_points) As UFCurve.PtSlopeCrvatr5 f2 S/ X. C: [' Z
" h; E0 b7 ^. B3 B3 h8 e( n3 }& G3 a '' Arrays of user's defining point data
3 q+ x* A0 X. M7 U4 b6 ~; h2 q Dim parameters() As Double = {0.0, 0.17, 0.32, 0.45, 1.29}$ P, ]5 X7 e8 H5 Q
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}
: |! l6 `) a I0 r0 Y% H9 @6 s! ^% R: O5 ]
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}! C7 U1 H/ J$ v `3 o( h; d
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}1 L# E+ P4 z! Z$ }; J2 l
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 j1 @7 t0 b+ F4 h4 O( l0 } 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}% }) K0 m8 r" w5 w
$ @- \( A$ x* x: I
Dim save_def_data As Integer = 1
" h. w1 @- Y+ _' ] Dim spline_tag As Tag
( Z$ Y" u" x0 M4 O4 z& ^- J# T& u8 k* A8 M
For i As Integer = 0 To num_points - 1! b' O; d- S6 d& [0 [0 ?
point_data(i) = New UFCurve.PtSlopeCrvatr- E8 v: K3 _" A0 E% j
Dim tempPoints(2) As Double
+ R q7 L, d2 B7 r" V' O8 Z tempPoints(0) = points(3 * i)
2 N: `6 H) ?1 E# Z8 J; x/ { tempPoints(1) = points(3 * i + 1)
# i- X: B- z8 v4 D tempPoints(2) = points(3 * i + 2)' r! H0 f: _' c# A9 H* h7 X
point_data(i).point = tempPoints
3 U# n' P) I8 E) X6 c point_data(i).slope_type = slopeTypes(i)
% W) Q6 y* N0 g; S/ |+ z( D# L Dim tempSlope(2) As Double4 D$ j6 T% }2 r) b
tempSlope(0) = slopeVecs(3 * i)
0 F& c0 B4 t1 P- _; A; k tempSlope(1) = slopeVecs(3 * i + 1)% G5 T+ k0 a& m d
tempSlope(2) = slopeVecs(3 * i + 2)
6 e* d K7 z: ?9 d X0 M point_data(i).slope = tempSlope8 @) F$ U& f! s0 I% W8 L; ^6 H
point_data(i).crvatr_type = crvatrTypes(i)0 F; ^7 b* Y/ Y; z" B% Y
Dim tempCrvatr(2) As Double
( V2 ?0 m) a. ~( [ tempCrvatr(0) = crvatrVecs(3 * i)
& L2 w r! f7 e tempCrvatr(1) = crvatrVecs(3 * i + 1) p- Q/ O! [% T2 A
tempCrvatr(2) = crvatrVecs(3 * i + 2)
y3 e- w' `2 j point_data(i).crvatr = tempCrvatr
5 Z; ]) L0 G+ `/ N& t' Z Next
# |8 Q1 Z, R6 d! v) n( l stream.WriteLine("Successful")
9 m. T x: M$ c$ _9 l* K 'Create B-spline UFCurve 2 q3 s9 Z6 ?5 n9 r- b3 G- S9 Z" k Z* Q
stream.WriteLine("Create Spine Through Points= ")# E4 u: \9 m# P
theUfSession.Curve.CreateSplineThruPts(degree, periodicity, num_points, point_data, parameters, save_def_data, spline_tag)* {8 X* O: }, {+ V4 n% K- {) j
stream.WriteLine("Successful")$ P/ Q1 t, r/ x2 U' \0 v* J3 H
; h* c, N9 P. r# v) C/ i! E
'Ask spline thr points parameters
' y* }# m* g. }0 E stream.WriteLine("Query Spine Through Points= ")
+ V2 [8 X/ |/ s/ D Dim ask_degree As Integer4 n! q) l- X n" q) O7 d; e; m
Dim ask_periodicity As Integer& f2 n0 V2 `- n! f
Dim ask_num_points As Integer
* S4 e: j3 K+ }. [7 \1 } Dim ask_parameters() As Double) `/ d% c' a# W& R; O2 X
Dim ask_point_data() As UFCurve.PtSlopeCrvatr
0 A- g8 y6 y2 j, n theUfSession.Curve.AskSplineThruPts(spline_tag, ask_degree, ask_periodicity, ask_num_points, ask_point_data, ask_parameters)
6 R9 L% t# C U2 @0 J4 ~5 P+ h8 C stream.WriteLine("Successful")5 _/ c9 n: Q" l, I; {
stream.WriteLine("SplineThruPts Data")9 ?( p* ~+ d6 g9 L9 [6 l1 K
stream.WriteLine("degree= " + ask_degree.ToString)
h/ O3 k! l% O" U0 S- w W stream.WriteLine("periodicity= " + ask_periodicity.ToString)
8 T. I4 ~: g6 m stream.WriteLine("num_points= " + ask_num_points.ToString)4 w" L, b5 \( F6 N* y
stream.Write("parameters= {")8 a* j7 e( S, r
For J As Integer = 0 To ask_parameters.Length - 1
% F; Y) U6 d, r7 J8 s3 S stream.Write(ask_parameters(J).ToString)
( i u P% p- B8 n' E& t \" k if(J < ask_parameters.Length - 1)
5 N* n& b2 t) F5 q& d% O stream.Write(",")
9 z9 c" F1 i O! t) M, N+ R; I End if
! B5 }0 ~2 e8 r6 S5 @+ L# v Next
/ r8 t! P# ?; |5 G F stream.WriteLine("}"); ~4 G* \( Z2 F
- x( A$ s. g9 S# Y; e! ], U5 K stream.Write("point_data= {")+ I8 _9 A( N% u/ g6 ]4 u# [
For i As Integer = 0 To ask_point_data.Length - 1# \: T7 c0 i. Z' r; x& M
stream.Writeline("------------point_data[{0}]", i)
0 H: f/ q, a+ {0 G/ t9 s% [ stream.Write("point {")
5 @( t2 `) t* _6 _7 V4 Y For j As Integer = 0 To ask_point_data(i).point.Length - 1. j6 D- R6 b* z0 \) J2 K
stream.Write(ask_point_data(i).point(j))
- N' w& ~$ q3 ^% A if(j < ask_point_data(i).point.Length - 1)
$ J7 b0 [. {4 ^) K stream.Write(",")2 }7 c9 K. B, h8 A" F* I. m1 l
End if6 J! `. [# |4 d0 N9 m/ I
Next% X6 c& K7 ?3 W
stream.WriteLine("}")$ n- k- ^" |+ k1 C; W& b
stream.Writeline("slope_type " + ask_point_data(i).slope_type.ToString)8 f% {% D1 O& @( ?) j
stream.Write("slope {")( P2 h# J3 J. o1 }, p4 Q
For k As Integer = 0 To ask_point_data(i).slope.Length - 1& g/ P& x& L0 q' @- Z
stream.Write(ask_point_data(i).slope(k))
5 q# ?7 t0 R4 a% ^ if(k < ask_point_data(i).slope.Length - 1)
7 ^5 l4 c4 Q3 F# o; f stream.Write(",")
0 O0 e) k6 \; T* ]* ` End if
! B3 k" e8 R% V ?: n+ l9 ?0 l4 v Next' J7 o( H( T# x8 H; @% C
stream.WriteLine("}")
+ A2 m: g# X" k" ? stream.Writeline("crvatr_type " + ask_point_data(i).crvatr_type.ToString)6 q* h( Z n, t8 s
stream.Write("crvatr {")
4 ~- b7 Z: s; n# B8 D3 k4 @- R9 V For l As Integer = 0 To ask_point_data(i).crvatr.Length - 1& Y! T7 O) X+ K4 C
stream.Write(ask_point_data(i).crvatr(l))
K& t J, ]# P$ X) |! `5 J( l$ _$ a if(l < ask_point_data(i).crvatr.Length - 1)% c7 p' n/ r2 }, P$ q
stream.Write(",")
3 n% e% b# E/ d0 T! I End if
/ J: I- J8 S5 a; Z; t Next( `' k' R2 @+ [' x: @4 y; C( ^& W
stream.Writeline("}")4 Q# z3 L# Y b, I7 {% L, {5 f; c
Next
4 j/ R8 V) c$ w, ~6 ]' C
( J$ q* |: |8 T theUfSession.Part.Save()
' b) u' s: q8 M9 C/ q
; I9 H( a4 F! A. m$ v4 W Catch ex As Exception( h4 ^6 a* b! z, C5 M( l. l+ e' V
stream.WriteLine("EXCEPTION: ", ex.Message)
# g5 i6 _' I8 w$ b4 t/ c Return 1
( j! B. s$ y$ n/ t End Try
! w4 F( N2 Y% Q$ f+ S6 R0 [ Return 0
& z5 h5 V) n' Y9 k, ?7 o$ A& B# ~! x# _
End Function2 H2 C! j, A o- }" ^
' z! R/ ]3 n- \
End Module |