forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertTextToGeometry.rvb
82 lines (64 loc) · 2.34 KB
/
ConvertTextToGeometry.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ConvertTextToGeometry.rvb -- September 2008
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Convert text objects to geometry
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ConvertTextToGeometry
' Declare local variables
Dim obj_list, obj, saved_plane, cmd
Dim font, height, plane, style, text, bold, italic
' Select annotation objects
obj_list = Rhino.GetObjects("Select text to convert to geometry", 512, True, True)
If Not IsArray(obj_list) Then Exit Sub
' For speed, turn of screen redrawing
Call Rhino.EnableRedraw(False)
' Save the current construction plane
saved_plane = Rhino.ViewCPlane()
' Process each selected object
For Each obj In obj_list
' Weed out just the text objects
If Rhino.IsText(obj) Then
' Acquire the text parameters
font = Rhino.TextObjectFont(obj)
height = Rhino.TextObjectHeight(obj)
plane = Rhino.TextObjectPlane(obj)
style = Rhino.TextObjectStyle(obj)
text = Rhino.TextObjectText(obj)
If (style And 1) Then
bold = "_Yes"
Else
bold = "_No"
End If
If (style And 2) Then
italic = "_Yes"
Else
italic = "_No"
End If
' Set the current construction plane
Call Rhino.ViewCPlane(, plane)
' Add a new text object (geometry)
cmd = "_-TextObject "
cmd = cmd & "_GroupOutput=_Yes "
cmd = cmd & "_FontName=" & font & " "
cmd = cmd & "_Italic=" & italic & " "
cmd = cmd & "_Bold=" & bold & " "
cmd = cmd & "_Height=" & CStr(height) & " "
cmd = cmd & "_Output=_Curves "
cmd = cmd & "_AllowOpenCurves=_Yes "
cmd = cmd & Chr(34) & text & Chr(34) & " "
cmd = cmd & "0"
Call Rhino.Command(cmd, 0)
' Delete the original object
Call Rhino.DeleteObject(obj)
End If
Next
' Restore the saved construction plane
Call Rhino.ViewCPlane(, saved_plane)
' Enable screen redrawing
Call Rhino.EnableRedraw(True)
End Sub