Setting Pathfile to be user specific in onedrive using ilogic

Setting Pathfile to be user specific in onedrive using ilogic

Castro_Jerome
Observer Observer
240 Views
2 Replies
Message 1 of 3

Setting Pathfile to be user specific in onedrive using ilogic

Castro_Jerome
Observer
Observer

Hi Guys!

 

I need help with setting the path to be username specific for ilogic.

This is the code i have.

 

If DOOR = "2 Pilot Lights" Then
	Component.Replace("DOOR", "C:\Users\JACA\OneDrive\Documents\Vault\Spartech\Power & Drives\LV MCC\FVNR Assemblies\Doors\FVNR_3X1_DOOR_2P_NR.iam", True)

ElseIf DOOR = "3 Pilot Lights" Then
	Component.Replace("DOOR", "C:\Users\JACA\OneDrive\Documents\Vault\Spartech\Power & Drives\LV MCC\FVNR Assemblies\Doors\FVNR_3X1_DOOR_3P.iam", True)

 

JACA is the username and i want to set that to be whatever their login username is. 

0 Likes
241 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor

Try to use user environment variable %OneDrive% or something similar.

See picture below or try it in command line using SET command without arguments

 

MichaelNavara_3-1700637379465.png

 

Command line sample:

 

Microsoft Windows [Version 10.0.22631.2428]
(c) Microsoft Corporation. Všechna práva vyhrazena.

C:\Users\michael.navara>set
... something here ...
OneDrive=C:\Users\michael.navara\OneDrive
... something here ...

 

 

And in iLogic you can use ExpandEnvironmentVariables to get the value

 

Dim oneDriveDir = System.Environment.ExpandEnvironmentVariables("%OneDrive%")
Dim fileName = System.IO.Path.Combine(oneDriveDir, "Documents\Vault\Spartech\Power & Drives\LV MCC\FVNR Assemblies\Doors\FVNR_3X1_DOOR_2P_NR.iam")

logger.Debug(fileName)

 

 

 

 

 

0 Likes
Message 3 of 3

JelteDeJong
Mentor
Mentor

Assuming that you have set up your project files correctly, then you can also use the information in there. This has the extra advantage that if you ever change your project file the rule will keep working.

try something like this.

Dim doc As AssemblyDocument = ThisDoc.document

Dim project = ThisApplication.DesignProjectManager.ActiveDesignProject
Dim designPath = project.WorkspacePath

Dim lastPartPath = String.Empty
If DOOR = "2 Pilot Lights" Then lastPartPath = "Spartech\Power & Drives\LV MCC\FVNR Assemblies\Doors\FVNR_3X1_DOOR_2P_NR.iam.iam"
If DOOR = "3 Pilot Lights" Then lastPartPath = "Spartech\Power & Drives\LV MCC\FVNR Assemblies\Doors\FVNR_3X1_DOOR_3P.iam"

Dim path = System.IO.Path.Combine(designPath, lastPartPath)

MsgBox(path)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com