Submitted by JXB on Mon, 12/08/2014 - 00:22
Forums:
to all,
Does anyone know where I can get information on the NXColor Class? There is nothing in the documentation about colour code. I am plying around with an idea and recording a session gave me the following lines of codes;
Dim meshDisplaySettings4 As CAE.MeshDisplaySettings
meshDisplaySettings4 = mesh4.GetMeshDisplaySettings()
meshDisplaySettings4.Color = workSimPart.Colors.Find("Magenta")
not a problem in itself. I am looping through meshes if the mesh has specific criteria I am hoping/planning to set it to an agreed colour. I thought what could use a (integer) code (blue is 211 !) rather than a name so I am after information in that NXColor Class?
Any help would be welcome
Thanks
Regards
JXB
re: NX color
You are correct, there does not seem to be much information on the NX color class. Perhaps this would be a good topic for a future article, hmmm...
Anyway, back to the problem at hand.
Each NX part file has a Color Definition File (CDF) within the prt file. In this CDF file, there are 216 colors that the user may choose from; each color is given an integer ID number. The .Find method is overloaded, there is another version that will accept an integer as input (as opposed to the color name string input); so you could use workSimPart.Colors.Find(211) to find the NXColor with ID 211.
Now, bear in mind that ID 211 is NOT the universal ID number for the color "blue". ID 211 simply represents one color in the CDF, which could point to any valid color the user defined. If you never edit your CDF file and you are only working on your own files, assuming color 211 = "blue" may be fairly safe. However, if you are using files from other sources, or simply wish to make your code more robust, you may want to use the function: .AskClosestColor() to return the closest color in the current CDF to your specified color.
re: NX color
Thanks for the info NXJournaling. Great insight as usual. I'll have to think about this CDF file mentioned but I do not think it's going to be an issue as we are not "really" playing with the default values/parameters. I noticed that there is something called 'NXColor.Rgb'. Maybe worth a look. Anyway in my case I am planning/hoping to use default values but 1s testing failed miserably as the syntax is not applicable to mesh (Colors is not a member of NXOpen.CAE.Mesh )
Dim thefEModel As CAE.FEModel = CType(thefemPart.BaseFEModel(), CAE.FEModel)
Dim theMeshManager As CAE.MeshManager = CType(thefEModel.Find("MeshManager"), CAE.MeshManager)
Dim theMeshDisplaySettings As CAE.MeshDisplaySettings
For Each theMeshCollector As CAE.IMeshCollector In theMeshManager.GetMeshCollectors()
'allocate a color to all the mesh in the mesh collector
theMeshes = theMeshCollector.GetMeshes()
For Each mesh As CAE.Mesh In theMeshes
theMeshDisplaySettings = mesh.GetMeshDisplaySettings()
theMeshDisplaySettings.Color = mesh.Colors.Find("Magenta") mesh.RedisplayObject()
Next mesh
Next
Thanks
Regards
re: mesh color
How about:
mesh.Color = 211
mesh.RedisplayObject
re: mesh color
thanks for that. The lines of codes originally proposed were lifted from a recorded journal. It seems that NX does make things rather complicated when recording a journal.
Thanks
JXB
Thanks
Regards
Colors
If you have access to SNAP, things are a bit easier:
There are SNAP functions that give you the NX color and the NX color index corresponding to a given *Windows* color. So ...
Dim windowsBlue As System.Drawing.Color = System.Drawing.Color.Blue
' Get the NX color corresponding to "blue"
Dim nxBlue As NXOpen.NXColor = Snap.Color.NXColor(windowsBlue)
' Get the NX Color index (in the current CDF) corresponding to "blue"
Dim nxBlueIndex As Integer = Snap.Color.ColorIndex(windowsBlue)
If you need to stick with NX/Open functions, you can do things like this (in C#):
NXOpen.UF.UFDisp display = ufs.Disp;
int colorIndex = 0;
int colorModel = NXOpen.UF.UFConstants.UF_DISP_rgb_model;
int method = NXOpen.UF.UFConstants.UF_DISP_CCM_EUCLIDEAN_DISTANCE;
display.AskClosestColor(colorModel,rgbValues,method,out colorIndex);
RE: Colors
Thanks the input ciao. Much appreciated. Another brick to my NX-vba-knowledge wall
Thanks
Regards
Look at the NXOpen.UF.UFDisp class
You can learn more about NX colors by studying the functions in the NXOpen.UF.UFDisp class.