Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone!
I have few functions that are used in several external rules. At the moment, I've copied the function code on each rule, therefore I have the structure:
Sub Main()
...
End Sub
Function MyFunc()
...
End Function
Is there a way to store these functions in one file and use them without having the code on the rule itself?
Here an example of a function that I use in different rules:
Function ParameterCreate(Name As String, Optional Value As Object = "", Optional Unit As String = "ul")
' This rule works on every kind of Inventor files: Part, Assembly and Drawing
' If a parameter doens't exist, then it will be created.
' If a parameter exists, then it won't be changed.
'
' How to use:
'
' ParameterCreate("txtPara", "Hello World!")
' ParameterCreate("mmPara", 45, "mm")
' ParameterCreate("booPara", True)
' ParameterCreate("emptyPara")
' ParameterCreate("ulPara", 15)
Try ' Check if parameter exists.
Parameter(Name) = Parameter(Name)
Catch ' Parameter not found, so create it.
If TypeName(Value) = "Boolean" Then Unit = "BOOLEAN"
If TypeName(Value) = "String" Then Unit = "TEXT"
Dim oDoc As Document = ThisApplication.ActiveDocument
' Dim oDoc As Document = ThisDoc.Document
Dim oParam As UserParameters
If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
oParam = oDoc.Parameters.UserParameters ' Drawing.
Else
oParam = oDoc.ComponentDefinition.Parameters.UserParameters ' Part/Assembly.
End If
Select Case Unit
Case "BOOLEAN", "TEXT" : oParam.AddByValue(Name, Value, Unit)
Case Else : oParam.AddByExpression(Name, Value, Unit)
End Select
End Try
End Function
Solved! Go to Solution.