Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: Environment.GetEnvironmentVariable("UGII_ROOT_DIR")

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
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?
 
 http://files.engineering.com/getfile.aspx?folder=2b2d3f16-4ae3-4c65-b4ba-2c36a314d3a9&file=ugii_dir_error.JPG
Replies continue below

Recommended for you

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
 
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.
[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=383296[/url]
As you can see, it has that line near the top. I just cant figure out why I still keep getting that error.
 
Change that. I must have added that later as I dont see it in the original post. lol
 
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


 
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
 
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
 
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)
www.nxjournaling.com
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor