This rule setting list of values in multivalue user parameter.
Taking this values from external text file.
Procedure:
- detecting document type
- testing exist of multivalued parameter (if not exist - then creating it)
- reading all lines from external text file
- taking values from this file lines into this multivalue parameter
External file:
- text type
- values separated by lines
Sub Main()
Dim pName = "myMultiSelect"
Dim sourceFile = "C:\Temp\test.txt"
Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
If Not ExistParam(pName) Then
oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(pName, ReadFromTxt(sourceFile).item(0), UnitsTypeEnum.kMillimeterLengthUnits)
End If
MultiValue.List(pName) = ReadFromTxt(sourceFile)
End If
End Sub
Private Function ExistParam(paramName As String)
Dim paramExist As Boolean = False
Try
p = Parameter.Param(paramName)
paramExist = True
Catch
paramExist = False
End Try
Return paramExist
End Function
Private Function ReadFromTxt(path As String)
Dim oList As New ArrayList
Dim tempInt As Integer
oFileStream = System.IO.File.OpenText(path)
FileReader = oFileStream.ReadToEnd()
oFileStream.Close()
allLine = Split(FileReader, vbCrLf)
For Each item In allLine
oList.Add(CDblAny(item))
Next
Return oList
End Function
Žádné komentáře:
Okomentovat