×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")

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?

RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")

At the top of your .vb file (before the "Module NXJournal"), there should be a line:

CODE

Imports System 

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")

(OP)
Thanks for replying Cowski. That line is there. In fact in searching for an answer I found a video where someone added the line Imports System.IO to fix the error. I tried changing it to that and it didnt work either. Is there another Imports System command I can use that might be different than those two?

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")

(OP)
Change that. I must have added that later as I dont see it in the original post. lol

RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")

(OP)
Ok, in playing with it, I got it to do something different. I get an error now saying the line "Dim myStream As Stream = Nothing" is not defined.

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")

Edit: this post is in response to your post timestamped 3 Feb 17 19:45; I got pulled away while replying so didn't see the newest posts.

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")

If you are reading a file, I suggest using a StreamReader. You will need to import the System.IO namespace or fully qualify the stream reader object when you declare/use it. Some example code can be found here:
http://nxjournaling.com/content/read-text-file

www.nxjournaling.com

RE: Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")

(OP)
To my knowledge, I am not attempting to do anything but open a file per say. I took this code from reading the post as meant to simply change the Color Palette to the System Color Palette that is kept in the UGII 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")

The code opens/reads a text file (the CDF file) and loads the information into your current part's CDF. I'm not sure what the myStream variable is doing, it appears to be unused in the code. Try commenting out that line and see what happens. The FileOpen and LineInput functions are older ways of reading a file; you may need to import the Microsoft.VisualBasic namespace if you want to use them. The StreamReader shown above is the .net object to use to read files.

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")

(OP)
Thanks Cowski

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources