How to get path to current rule location?

How to get path to current rule location?

j.pavlicek
Collaborator Collaborator
1,002 Views
3 Replies
Message 1 of 4

How to get path to current rule location?

j.pavlicek
Collaborator
Collaborator

Hello,

is somehow possible to get path to the current (running) rule location?

 

Why I need it? I have iLogic form (using Windows Forms) where are some images placed. I want to be able to get a relative path to theirs location, for further portability.

 

What I tried: To place images into same folder as the rule and set:

.ImageLocation = "../imagename.png"

Doesn't work.

 

Thanks for help!



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Accepted solutions (1)
1,003 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor

Hi @j.pavlicek 

 

Is it an external rule?

Can the path be found like this?

For Each oPath As String In iLogicVb.Automation.FileOptions.ExternalRuleDirectories
	MsgBox(oPath)
Next

 

 

Message 3 of 4

j.pavlicek
Collaborator
Collaborator

Thanks for reply.

 

I saw this approach before. You are right, it is possible to get all paths returned with your code and then use FileSystemObject FileExists Method to check each of these paths if the image is present there.

 

But this seems a little over-engineered to me...



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 4 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @j.pavlicek 

Yes, maybe a bit overkill. But I can't really see a better solution. This should give you the path of the external rule and the function is very small:

 

Sub Main
MsgBox(getRulePath)
End Sub


Function getRulePath
For Each oPath As String In iLogicVb.Automation.FileOptions.ExternalRuleDirectories
	If System.IO.Directory.GetFiles(oPath, iLogicVb.RuleName + ".*").Count > 0 Then Return oPath
Next
End Function