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.
Try to use user environment variable %OneDrive% or something similar.
See picture below or try it in command line using SET command without arguments
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)
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.
Blog: hjalte.nl - github.com