iLogic Global Function Help

iLogic Global Function Help

pball
Mentor Mentor
782 Views
1 Reply
Message 1 of 2

iLogic Global Function Help

pball
Mentor
Mentor

I'm jumping down the rabbit hole of Vault and my collection of iLogic scripts now need to know the status of parts relating to Vault. I found some code that gives the Vault status but I want to have these functions in a single script file and reference them from multiple iLogic scripts. It sounds like I need to use a combination of addvbfile and straight vb code to get functions shared between scripts. I've found threads discussing this but no solid idiot proof examples of how to make this work.

 

Could someone either share an example of sharing a function or better yet tweak my code and give an example of using it from another script. Thanks.

 

'Other iLogic script calling shared function
Sub main
	MsgBox(VaultReadOnly)
End Sub
'Shared functions
Public Function VaultReadOnly As Boolean
	status = VaultStatus()
	If (status = 0 Or status = 1) Then 
		Return False
	Else 
		Return True
	End If
End Function

Public Function VaultStatus As Integer
	If (TCCI("VaultDataCardtop") = False) Then
		Return 0 'Not in Vault
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultUndoCheckouttop") = True) Then
		Return 1 'In Vault, Checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = True) Then
		Return 2 'In Vault, Not checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = False And TCCI("VaultCheckintop") = False) Then
		Return 3 'In Vault, Locked
	End If
End Function

Private Function TCCI(VaultParam As String)
	Return ThisApplication.CommandManager.ControlDefinitions.Item(VaultParam).Enabled
End Function

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Accepted solutions (1)
783 Views
1 Reply
Reply (1)
Message 2 of 2

pball
Mentor
Mentor
Accepted solution

Well after some stumbling around, lots of trial and error, and some vague hints from old forum posts I have something that works. Started with a kludgy solution of passing ThisApplication through each function all the down but managed to get a single call to a "load" sub to get ThisApplication working anywhere in the function module. Hope this helps someone else.

 

'Main Rule
AddVbFile "VaultStuff.iLogicvb"

VaultStuff.load(ThisApplication)

MsgBox(VaultReadOnly(),,"Read Only in Vault?")
'Function module
' <IsStraightVb>True</IsStraightVb>

Public Module VaultStuff
Public ThisApp As Object

Public Sub load(TA As Object)
	'Call sub to add access to ThisApplication in this module
	ThisApp = TA
End Sub

Public Function VaultReadOnly() As Boolean
	status = VaultStatus()
	If (status = 0 Or status = 1) Then 
		Return False
	Else 
		Return True
	End If
End Function

Public Function VaultStatus() As Integer
	If (TCCI("VaultDataCardtop") = False) Then
		Return 0 'Not in Vault
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultUndoCheckouttop") = True) Then
		Return 1 'In Vault, Checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = True) Then
		Return 2 'In Vault, Not checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = False And TCCI("VaultCheckintop") = False) Then
		Return 3 'In Vault, Locked
	End If
End Function

Private Function TCCI(VaultParam As String)
	Return thisapp.CommandManager.ControlDefinitions.Item(VaultParam).Enabled
End Function
End Module

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes