Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX open version

Status
Not open for further replies.

niedzviedz

Mechanical
Apr 1, 2012
307
Hello everyone,

I would like to check on which version of NX open the journal is currently running. The reason is simply - from NX9, representation for limits and fits has changes. I wanna change my journals to works on NX8.5 and also on new version. When I use them (from NX8.5) on NX 9/10 they work, but when the dimensions lost associativity and You re associate them, then when You have for example "10 f8" NX automatic change it to "10H7". To prevent this I must check which version is running, and then apply right code.


With best regards
Michael
 
Replies continue below

Recommended for you

Use this below code to get the NX version.
Code:
string nxVersion = NXOpen.Session.GetSession().GetEnvironmentVariableValue("UGII_FULL_VERSION");

Thanks,
Selvaraj Chellamuthu
NX Automation Engineer
 
Thanks SelvarajC, it's working. Now I have to figure out some conditions, because in NX8.5 I get v8.5.3.3 but in NX10 v10.0.3.5. There are different number of chars.

With best regards
Michael
 
Try this:

Code:
        Dim nxVersion As String = theSession.GetEnvironmentVariableValue("UGII_MAJOR_VERSION") & "." & theSession.GetEnvironmentVariableValue("UGII_MINOR_VERSION")

www.nxjournaling.com
 
Thanks @Cowski for Your help. It's works like a charm :) but now I have another problem.

I try this:
Code:
Dim nxVersion As String = theSession.GetEnvironmentVariableValue("UGII_MAJOR_VERSION") & "." & theSession.GetEnvironmentVariableValue("UGII_MINOR_VERSION") 

if nxversion > 8.5 then
	msgbox("YES")
else 
	msgbox("NO")
end if

And I receive error:
Code:
System.InvalidCastException: Conversion from sequence "10.0" to type 'Double' is not valid.
In Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) 
(...)

Any clue how to solve it?

With best regards
Michael
 
Thanks again.

I have tested this:
[ul]
[li]Double.TryParse(Nxversion, nxversion1) -> which return 0 in all cases[/li]
[li]nxversion = val(nxversion) -> which return 10 in NX 10.0 and 8.5 in NX 8.5[/li]
[li]Double.Parse(nxversion) -> gives me an error [/li]
[li]Double.Parse(nxversion), USculture) -> works like val. [/li]
[li]CDbl(nxversion) -> gives me an error [/li]
[li]Ctype(nxversion, double) -> also gives me the same error [/li]
and finally

[li] Convert.ToDouble(nxversion) -> gives me similar error[/li]
[/ul]

I think the simplest method is val, but I lost trailing zeros. Also some functions which aren't working because of regional settings in system.


With best regards
Michael
 
Hello everyone. Here is my code for "f8". It's works perfect in NX10, but what I didn't predicted is some part of code will give me an error in NX 8.5. Is there any way to exclude some part of code from check by NX 8.5 compiler?

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations

Module NX85LimitsFits

    Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = s.Parts.Work
    Dim nxVersion As String = s.GetEnvironmentVariableValue("UGII_MAJOR_VERSION") & "." & s.GetEnvironmentVariableValue("UGII_MINOR_VERSION")

    Sub Main()

        Dim selecteddims(-1) As TaggedObject
        Dim response1 As Selection.Response = Selection.Response.Cancel

	nxversion = val(nxversion) 

	if nxversion > 8.5 then

		start1:
        		response1 = Select_dims(selecteddims)

		        EditDimensionTolerance2(selecteddims)
		end1:
	
	else 	
		start2:
        		response1 = Select_dims(selecteddims)
		        EditDimensionTolerance(selecteddims)
		end2:
	end if

    End Sub
    ' ----------------------------------------------
    '   sub to edit tolerance
    ' ----------------------------------------------
    Sub EditDimensionTolerance(ByVal selecteddims () As TaggedObject)

        Dim markId3 As Session.UndoMarkId
        Dim dimname1 As String = Nothing

        For Each selecteddim As Dimension In selecteddims
            dimname1 = selecteddim.ToString()

 If dimname1.Contains("Radius") = True Then

            Dim radiusDimension1 As Annotations.RadiusDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = radiusDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            radiusDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = radiusDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            radiusDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Horizontal") = True Then

            Dim horizontalDimension1 As Annotations.HorizontalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = horizontalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            horizontalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = horizontalDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            horizontalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Vertical") = True Then

            Dim verticalDimension1 As Annotations.VerticalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = VerticalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            VerticalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = verticalDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            verticalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Parallel") = True Then

            Dim ParallelDimension1 As Annotations.ParallelDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = ParallelDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            ParallelDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = ParallelDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            ParallelDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Diameter") = True Then

            Dim DiameterDimension1 As Annotations.DiameterDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = DiameterDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            DiameterDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = DiameterDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            DiameterDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Cylindrical") = True Then

            Dim CylindricalDimension1 As Annotations.CylindricalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = CylindricalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            CylindricalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = CylindricalDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            CylindricalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Perpendicular") = True Then

            Dim PerpendicularDimension1 As Annotations.PerpendicularDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = PerpendicularDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            PerpendicularDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = PerpendicularDimension1.GetDimensionPreferences()
            dimensionPreferences1.LimitFitDeviation = "f"
            dimensionPreferences1.LimitFitGrade = 8
            PerpendicularDimension1.SetDimensionPreferences(dimensionPreferences1)

        End If
	
	Next
        Dim nErrs1 As Integer
        nErrs1 = s.UpdateManager.DoUpdate(markId3)

    End Sub

'************************************************************************************************************
'************************************************************************************************************

  Sub EditDimensionTolerance2(ByVal selecteddims () As TaggedObject)

        Dim markId3 As Session.UndoMarkId
        Dim dimname1 As String = Nothing

        For Each selecteddim As Dimension In selecteddims
            dimname1 = selecteddim.ToString()

 If dimname1.Contains("Radius") = True Then

            Dim radiusDimension1 As Annotations.RadiusDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = radiusDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            radiusDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = radiusDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitShaftGrade = 8
            radiusDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Horizontal") = True Then

            Dim horizontalDimension1 As Annotations.HorizontalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = horizontalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            horizontalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = horizontalDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitshaftGrade = 8
            horizontalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Vertical") = True Then

            Dim verticalDimension1 As Annotations.VerticalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = VerticalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            VerticalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = verticalDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitshaftGrade = 8
            verticalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Parallel") = True Then

            Dim ParallelDimension1 As Annotations.ParallelDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = ParallelDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            ParallelDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = ParallelDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitShaftGrade = 8
            ParallelDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Diameter") = True Then

            Dim DiameterDimension1 As Annotations.DiameterDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = DiameterDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            DiameterDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = DiameterDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitShaftGrade = 8
            DiameterDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Cylindrical") = True Then

            Dim CylindricalDimension1 As Annotations.CylindricalDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = CylindricalDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            CylindricalDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = CylindricalDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitShaftGrade = 8
            CylindricalDimension1.SetDimensionPreferences(dimensionPreferences1)

        ElseIf dimname1.Contains("Perpendicular") = True Then

            Dim PerpendicularDimension1 As Annotations.PerpendicularDimension = selecteddim
            Dim linearTolerance1 As Annotations.LinearTolerance
            linearTolerance1 = PerpendicularDimension1.GetTolerance()
            linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits
            PerpendicularDimension1.SetTolerance(linearTolerance1)
            Dim dimensionPreferences1 As Annotations.DimensionPreferences
            dimensionPreferences1 = PerpendicularDimension1.GetDimensionPreferences()
	    dimensionPreferences1.LimitFitAnsiHoleType = NXOpen.Annotations.FitAnsiHoleType.Shaft
            dimensionPreferences1.LimitFitShaftDeviation = "f"
            dimensionPreferences1.LimitFitShaftGrade = 8
            PerpendicularDimension1.SetDimensionPreferences(dimensionPreferences1)

        End If
	
	Next
        Dim nErrs1 As Integer
        nErrs1 = s.UpdateManager.DoUpdate(markId3)

    End Sub


    ' ----------------------------------------------
    '   function to select dimensions
    ' ----------------------------------------------
    Function Select_dims(ByRef obj() As TaggedObject) As Selection.Response

        Dim resp As Selection.Response = Selection.Response.Cancel
        Dim prompt As String = "Select dimensions"
        Dim message As String = "Select dimensions"
        Dim title As String = "Selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        With selectionMask_array(0)
            .Type = UFConstants.UF_dimension_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With

        resp = ui.SelectionManager.SelectTaggedObjects(prompt, message, _
            scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, obj)

        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor