Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (75 sloc) 2.599 kb
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ExportLabels.rvb -- February 2012
' 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Description
' Exports a dimension's value and it's user text (labels)
' to a commma-delimited (.CSV) file.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ExportLabels
' Local constants
Const RhAnnotations = 512
' Local variables
Dim arrDims, strDim, strValue, strUserText
Dim strFilter, strFileName, strLine
Dim objFSO, objStream
' Select some dimensions
arrDims = Rhino.GetObjects("Select dimensions with user-defined labels for export", RhAnnotations, True, True)
If IsNull(arrDims) Then Exit Sub
' Define a file filter
strFilter = "Comma-Delimited File (*.csv)|*.csv||"
' Get the name of the file to create
strFileName = Rhino.SaveFileName("Export", strFilter)
If IsNull(strFileName) Then Exit Sub
' Create a file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Try creating the file, overwrite if needed
On Error Resume Next
Set objStream = objFSO.CreateTextFile(strFileName, True, True)
If Err Then
MsgBox Err.Description
Exit Sub
End If
' Process each selected dimension
For Each strDim In arrDims
If Rhino.IsDimension(strDim) Then
' Build a comma-delimited string to write
strUserText = Rhino.DimensionUserText(strDim)
strUserText = ParseDimensionUserText(strUserText)
strValue = CStr(Rhino.DimensionValue(strDim))
strLine = strUserText & "," & strValue
' Write to file
objStream.WriteLine(strLine)
End If
Next
' Close the file
objStream.Close
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Description
' Utility function to remove "<>" prefix from string.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ParseDimensionUserText(strDim)
' Local variables
Dim nPos, nLen, objRegExp
' Validate string
If IsNull(strDim) Then
strDim = "<Empty>"
Else
' Remove "<>" block
Set objRegExp = New RegExp
objRegExp.Pattern = "<[^>]*>"
objRegExp.Global = True
strDim = objRegExp.Replace(strDim, "")
strDim = Trim(strDim)
End If
' One final validation
If Len(strDim) = 0 Then
strDim = "<Empty>"
End If
ParseDimensionUserText = strDim
End Function
Jump to Line
Something went wrong with that request. Please try again.