Cancel
Showing results for 
Search instead for 
Did you mean: 

Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Pioneer
Pioneer

info.jpg

 

{Raeed Kena}, {Mechanical / Civil Engineer}


Production: {NX11,CATIA,SOLIDWORK,ANSYS,AUTOCAD,TEAMCENTER}

Development: {Visual Basic Net} Testing: {NX12,ANSYS}
7 REPLIES

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Pioneer
Pioneer

Case Solved .

{Raeed Kena}, {Mechanical / Civil Engineer}


Production: {NX11,CATIA,SOLIDWORK,ANSYS,AUTOCAD,TEAMCENTER}

Development: {Visual Basic Net} Testing: {NX12,ANSYS}

Create line parallel to the selected Datum Axis and 2nd to select all datum arises

Pioneer
Pioneer

The code here will add a paralle line to  the Datum Axis and  datum csys to initial point on the current layer ,also will added datum csys to the line .

 

Option Strict Off
Imports System
Imports NXOpen
Imports MiniSnap
Imports NXOpen.Axis.Types
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF

Module Line_Datum_Convert
    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()
        Dim B As String = InputBox("The Program will will Skip Unselected Layer or Hidden Object.Give the Value for the Line to be scaled", "Add Line On Datum Axis", "200")
        If B = "" Then Exit Sub
        B = CInt(B)

        For Each curve As NXOpen.Curve In workPart.Curves
            If TypeOf (curve) Is Line Or TypeOf (curve) Is Spline Then
                Dim snapCurve = CType(curve, MiniSnap.NX.Curve)
                Dim origin As Point3d
                Dim N As Vector3d
                Dim startPt As MiniSnap.Position = snapCurve.StartPoint
                Dim endPt As MiniSnap.Position = snapCurve.EndPoint

                origin = startPt
                N.X = endPt.X - startPt.X
                N.Y = endPt.Y - startPt.Y
                N.Z = endPt.Z - startPt.Z

                Dim currentdatumlayer As Integer = curve.Layer
                Dim modifiedobject As DisplayableObject = CType(curve, DisplayableObject)

                If workPart.Layers.GetState(currentdatumlayer) <> Layer.State.Hidden And modifiedobject.IsBlanked = False Then
                    theSession.Parts.Work.Layers.WorkLayer = currentdatumlayer
                    CreateDatumCSYS(origin, N)
                End If
            End If
        Next


        For Each myFeature As Feature In workPart.Features
            If TypeOf (myFeature) Is DatumAxisFeature Then
                Dim origin As Point3d
                Dim vector As Vector3d
                Dim N As Vector3d
                Dim point2 As Point3d
                Dim x, y, z, xx, yy, zz As Double
                origin = myFeature.Location
                vector = DirectCast(myFeature, NXOpen.Features.DatumAxisFeature).DatumAxis.Direction
                xx = (vector.X) - 0
                yy = (vector.Y) - 0
                zz = (vector.Z) - 0

                x = (origin.X) + B * xx
                y = (origin.Y) + B * yy
                z = (origin.Z) + B * zz

                N.X = x - origin.X
                N.Y = y - origin.Y
                N.Z = z - origin.Z

                point2.X = x
                point2.Y = y
                point2.Z = z

                Dim currentdatumlayer As Integer = DirectCast(myFeature, NXOpen.Features.DatumAxisFeature).DatumAxis.Layer
                If Not DirectCast(myFeature, NXOpen.Features.DatumAxisFeature).DatumAxis.IsBlanked And _
                    workPart.Layers.GetState(DirectCast(myFeature, NXOpen.Features.DatumAxisFeature).DatumAxis.Layer) <> Layer.State.Hidden Then
                    theSession.Parts.Work.Layers.WorkLayer = currentdatumlayer
                    Dim line1 = workPart.Curves.CreateLine(origin, point2)
                    CreateDatumCSYS(origin, N)
                End If
            End If
        Next
        theSession.Parts.Work.Layers.WorkLayer = 1
    End Sub

    Public Sub CreateDatumCSYS(ByVal origin As Point3d, ByVal N As Vector3d)
        Dim b1, b2 As Vector3d
        Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing
        Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder = Nothing
        datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)
        If Math.Abs(N.X) >= Math.Abs(N.Y) And Math.Abs(N.X) >= Math.Abs(N.Z) Then
            b1.X = N.Y / N.X
            b1.Y = -1.0
            b1.Z = 0.0
            Dim d As Double = N.X * N.X + N.Y * N.Y
            b2.X = N.X * N.Z / d
            b2.Y = N.Y * N.Z / d
            b2.Z = -1.0
        ElseIf Math.Abs(N.Y) >= Math.Abs(N.X) And Math.Abs(N.Y) >= Math.Abs(N.Z) Then
            b1.X = -1.0
            b1.Y = N.X / N.Y
            b1.Z = 0.0
            Dim d As Double = N.X * N.X + N.Y * N.Y
            b2.X = N.X * N.Z / d
            b2.Y = N.Y * N.Z / d
            b2.Z = -1.0

        ElseIf Math.Abs(N.Z) >= Math.Abs(N.X) And Math.Abs(N.Z) >= Math.Abs(N.Y) Then
            b1.X = -1.0
            b1.Y = 0.0
            b1.Z = N.X / N.Z
            Dim d As Double = N.X * N.X + N.Z * N.Z
            b2.X = N.X * N.Y / d
            b2.Y = -1.0
            b2.Z = N.Y * N.Z / d
        End If
        Dim origin5 As NXOpen.Point3d = origin
        Dim xDirection1 As NXOpen.Vector3d = New NXOpen.Vector3d(b2.X, b2.Y, b2.Z)
        Dim yDirection1 As NXOpen.Vector3d = New NXOpen.Vector3d(b1.X, b1.Y, b1.Z)
        Dim xform1 As NXOpen.Xform = Nothing
        xform1 = workPart.Xforms.CreateXform(origin5, xDirection1, yDirection1, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)
        Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing
        cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling)
        datumCsysBuilder1.Csys = cartesianCoordinateSystem1
        datumCsysBuilder1.DisplayScaleFactor = 1.25
        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = datumCsysBuilder1.Commit()
        datumCsysBuilder1.Destroy()
    End Sub
End Module

{Raeed Kena}, {Mechanical / Civil Engineer}


Production: {NX11,CATIA,SOLIDWORK,ANSYS,AUTOCAD,TEAMCENTER}

Development: {Visual Basic Net} Testing: {NX12,ANSYS}

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Hi @raeedkena, you can use spine command.

 

regards,

Fatih.

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Pioneer
Pioneer

Hi faith,

 What do you mean about  spine .The attched code is working fine for me to attach parallel line to the datum axis as well as will create Datum CSYS at the initial point of the Datum Axis. It will create Datum CSYS  at the  first point of the line. You need to hide or show the layer that has the datum axis  or the line.

 

Best Regards

{Raeed Kena}, {Mechanical / Civil Engineer}


Production: {NX11,CATIA,SOLIDWORK,ANSYS,AUTOCAD,TEAMCENTER}

Development: {Visual Basic Net} Testing: {NX12,ANSYS}

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

You can use spine command to crate line to perpendicular a datum plane or face. i though it work fine for you.

Regards
Fatih.

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Phenom
Phenom
This like a lot of trouble when you could just create a sketch on the plane of the datum coordinate system and create a line.

Re: Create a line parallel to the existing Datum Axis on the same layer and attach datum CSYS to it

Pioneer
Pioneer

The Goal of this Journal is:

 

1-  attach Line and Datum CSYS to the DATUM Axis. Because of the CAD file, The we receive and it has Die Vector and Die pole as datum axis doesn't show up on the step file during the conversion process. It is very tedious to create a line parallel to the datum Axis and attach Datum CSYS to it (search online about create a line parallel to Datum Axis if you are not familiar with that).

 

2-  attach Datum CSYS to the existent line ( you can hide or deselect the line) the program will skip the line

3-  the program will consider the layer of the Datum Axis or the line, so any created line or Daum CSYS will be on the same layer.


Please see the attached video for better clarification, and also I have attached the part file for your convenience. I created this journal to saved time with the accuracy of attaching the parallel line.

 

 

{Raeed Kena}, {Mechanical / Civil Engineer}


Production: {NX11,CATIA,SOLIDWORK,ANSYS,AUTOCAD,TEAMCENTER}

Development: {Visual Basic Net} Testing: {NX12,ANSYS}