Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
(OP)
I have a VB code someone gave me here to change the color palette to the system file . I have never gotten it to work in the past due to this error.
I find at this path....
C:\UGNX9\UGII
There is the file I want to load....
ugcolor.cdf
From what someone has told me, they think for some reason NX is not allowed to see inside this folder so it cant find the directory using the VB code. If I manually try to load the color palette file, I have no problem finding it. But for some reason the journal doesnt seem to reach it. I am attaching an image of the error along with the portion of code that the error hilights.
Does anyone know what I can do to fix this? Why it happens?
I find at this path....
C:\UGNX9\UGII
There is the file I want to load....
ugcolor.cdf
From what someone has told me, they think for some reason NX is not allowed to see inside this folder so it cant find the directory using the VB code. If I manually try to load the color palette file, I have no problem finding it. But for some reason the journal doesnt seem to reach it. I am attaching an image of the error along with the portion of code that the error hilights.
Does anyone know what I can do to fix this? Why it happens?





RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
CODE
If this line is not there, add it. The error you see is telling you that it doesn't know what the "Environment" type is; the "Environment" type is defined in the System namespace, you need a reference to the System namespace.
www.nxjournaling.com
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
This is the URL to the thread where I got the code.
http://www.eng-tips.com/viewthread.cfm?qid=383296
As you can see, it has that line near the top. I just cant figure out why I still keep getting that error.
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
Here is the code I have on my journal right now. Can you see where it is messed up?
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
'Public Sub load_color_palette()
Dim rootDir As String = _
Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
Dim colorPalette As String = rootDir & "\ugcolor.cdf"
Dim colorName As String = ""
Dim red As String = ""
Dim green As String = ""
Dim blue As String = ""
Dim rgbColor(2) As Double
Dim thisColor As Integer = 0
Dim textLine As String = ""
Dim lineCounter As Integer = 0
Dim myStream As Stream = Nothing
Try
FileOpen(1, colorPalette, OpenMode.Input)
Do Until EOF(1)
textLine = LineInput(1)
If lineCounter > 3 Then
colorName = textLine.Substring(0, 30)
red = textLine.Substring(34, 8)
green = textLine.Substring(45, 8)
blue = textLine.Substring(56, 8)
rgbColor(0) = red
rgbColor(1) = green
rgbColor(2) = blue
thisColor = lineCounter - 4
ufs.Disp.SetColor(thisColor, _
UFConstants.UF_DISP_rgb_model, colorName, rgbColor)
End If
lineCounter += 1
Loop
FileClose(1)
ufs.Disp.LoadColorTable()
Catch Ex As NXException
s.ListingWindow.Open()
s.ListingWindow.WriteLine("Error in load_color_palette: ")
s.ListingWindow.WriteLine(Ex.GetBaseException.ToString())
End Try
End Sub
End Module
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
The code in the link is just a subroutine (not a full journal) which does not include the line mentioned above. The line of code in question is currently split out onto two lines in the source code file; it should not make a difference, but I'd try changing it back to one line and fully qualifying the "Environment" call.
CODE
Dim rootDir as String = System.Environment.GetEnvironmentVariable("UGII_ROOT_DIR")Also, your journal will also need a subroutine named "Main()" if it does not already have one; the main subroutine should call the "load_color_palette" subroutine.
www.nxjournaling.com
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
http://nxjournaling.com/content/read-text-file
www.nxjournaling.com
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
Likely I am misunderstanding you, as I have very little knowledge of this stuff. I feel like an old dog these days. I used to be able to dig in and teach myself whatever I looked into. Lately it is more fail than success when I do that. VB, VBA, this code stuff doesnt seem to sink in very well. lol
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
Edit: link added for reference (FileOpen and LineInput)
https://msdn.microsoft.com/en-us/library/microsoft...
www.nxjournaling.com
RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")
I will read those links and play with it and see if I can figure it out. I am starting to think my biggest problem is that I tried to teach myself this stuff to a point. I think I learned some stuff but never learned the most basic things in code, so when people explain things, it just confuses me. Its frustrating. lol There are two guys here that know a lot more than I do but they do other work and I cant bother them much. Creating journals and buttons for NX9 is only a side thing I do for my job so when I have to figure something out, its not like I have been constantly working in it and learning it.
Just explaining why I am so green with this stuff after being on here for a while now. I appreciate your patients.