Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extract Center line of a cylindrical body 4

Status
Not open for further replies.

manikandaprabhuc

Mechanical
Jun 23, 2012
18
Hi,

I need to extract center line of a cylindrical body as a curve, (i.e) center line of a pipe which has been imported from an STEP file.

Regards

Manikanda
 
Replies continue below

Recommended for you

It is possible thru macro... search in this forum "extract centerline". You have to convert the geom into a B-surface though..
 
If the faces are cylindrical (or any face that is the result of a 'revolve' type of operation), you can use "extract virtual curve" to get the centerline (axis of rotation).

www.nxjournaling.com
 
Hi Cowski,

The component like a flexible hoses, which not like a regular defined shapes. also like tubes which connected in the lubrication system.

Regards

Manikanda
 
Dear Cowski,

Thanks for the info and i have tested this code and its working fantastic with the flexible hoses. and i couldn't create for the tubes which is made like straight and radius.

Problem which am facing is, this utility needs to select a face and the normal tube faces are not getting selected at a time since it has different faces.(Hope you are getting me what am trying to convey).

Kindly suggest is there any work around for this scenario also.

Regards

Manikanda
 
My latest program did not allow for faces that are open in one direction. That is if the cylindrical surface is made up of say two 180 degree arc faces then the program will not work. If this is what you are referring to please let us know this and I can looking at adding it to the program. If I don't have the correct idea then you would have to make available a sample part.

Frank Swinkels
 
Since you're running NX 9.0, have you tried using the 'Extract Virtual Curve' function (you can find it using the 'Command Finder')? While it won't do the 'elbows' it will give you the centerlines of the straight sections.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Thanks John,

I have tried Extract Virtual curve function. But needed is the center line for Both Straight and Elbow.

Regards

Manikanda
 
I usually just go back and 'add' the arc segments using a fillet command.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Here is a journal than worked on your part.
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features

Module SingleSurfaceCentreLine
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work()
    Sub Main()
        Dim response1 As Selection.Response = Selection.Response.Cancel
        Dim theFace As Face = Nothing
start1:
        response1 = select_a_face("Select the face", theFace)
        If response1 = Selection.Response.Cancel _
            Or response1 = Selection.Response.Back Then GoTo end1
        Dim extractedfeat1 As Feature = Nothing
        Dim extractedbodyfeat1 As BodyFeature = Nothing
        Dim extractedbody1() As Body = Nothing
        Dim faces() As Face
        Dim testface As Face
        Dim bsurface1 As UFModl.Bsurface = Nothing
        createExtractedBSurface(theFace, extractedfeat1)
        extractedbodyfeat1 = DirectCast(extractedfeat1, BodyFeature)
        extractedbody1 = extractedbodyfeat1.GetBodies
        faces = extractedbody1(0).GetFaces
        ufs.Modl.AskBsurf(faces(0).Tag, bsurface1)
        testface = faces(0)
        Dim knotsU() As Double = bsurface1.knots_u
        Dim knotsV() As Double = bsurface1.knots_v
        Dim params(1) As Double
        Dim pnt0(2) As Double
        Dim pnt1(2) As Double
        Dim pnt2(2) As Double
        Dim pnt3(2) As Double
        Dim junk3(2) As Double
        Dim junk2(1) As Double
        Dim coordinates1 As Point3d = New Point3d
        ' check if closed in u direction or in v direction
        If knotsU(0) < 0.0 Then
            ' closed in u direction
            Dim uparm() As Double = {0.0, 0.5}
            Dim vparm(knotsV.Length - 5) As Double
            vparm(0) = 0.0
            For i As Integer = 1 To knotsV.Length - 7 Step 3
                vparm(i) = knotsV(i + 2) + (knotsV(i + 3) - knotsV(i + 2)) / 3.0
                vparm(i + 1) = knotsV(i + 2) + 2.0 * (knotsV(i + 3) - knotsV(i + 2)) / 3.0
                vparm(i + 2) = knotsV(i + 3)
            Next
            Dim ArrayOfPoints(vparm.Length - 1) As Point
            For i As Integer = 0 To vparm.Length - 1
                params(0) = uparm(0)
                params(1) = vparm(i)
                ufs.Modl.AskFaceProps(testface.Tag, params, pnt0, junk3, junk3, junk3, junk3, junk3, junk2)
                params(0) = uparm(1)
                ufs.Modl.AskFaceProps(testface.Tag, params, pnt1, junk3, junk3, junk3, junk3, junk3, junk2)
                coordinates1 = New Point3d((pnt0(0) + pnt1(0)) / 2.0, (pnt0(1) + pnt1(1)) / 2.0, (pnt0(2) + pnt1(2)) / 2.0)
                ArrayOfPoints(i) = wp.Points.CreatePoint(coordinates1)
            Next
            Dim myStudioSpline As Features.StudioSpline
            myStudioSpline = CreateStudioSplineThruPoints(ArrayOfPoints)
        ElseIf knotsV(0) < 0.0 Then
            ' closed in v direction
            Dim vparm() As Double = {0.0, 0.5}
            Dim uparm(knotsU.Length - 5) As Double
            uparm(0) = 0.0
            For i As Integer = 1 To knotsU.Length - 7 Step 3
                uparm(i) = knotsU(i + 2) + (knotsU(i + 3) - knotsU(i + 2)) / 3.0
                uparm(i + 1) = knotsU(i + 2) + 2.0 * (knotsU(i + 3) - knotsU(i + 2)) / 3.0
                uparm(i + 2) = knotsU(i + 3)
            Next
            Dim ArrayOfPoints(uparm.Length - 1) As Point
            For i As Integer = 0 To uparm.Length - 1
                params(0) = uparm(i)
                params(1) = vparm(0)
                ufs.Modl.AskFaceProps(testface.Tag, params, pnt0, junk3, junk3, junk3, junk3, junk3, junk2)
                params(1) = vparm(1)
                ufs.Modl.AskFaceProps(testface.Tag, params, pnt1, junk3, junk3, junk3, junk3, junk3, junk2)
                coordinates1 = New Point3d((pnt0(0) + pnt1(0)) / 2.0, (pnt0(1) + pnt1(1)) / 2.0, (pnt0(2) + pnt1(2)) / 2.0)
                ArrayOfPoints(i) = wp.Points.CreatePoint(coordinates1)
            Next
            Dim myStudioSpline As Features.StudioSpline
            myStudioSpline = CreateStudioSplineThruPoints(ArrayOfPoints)
        Else
            MsgBox("Surface must be closed in one direction")
            GoTo end1
        End If
        Dim objects1(0) As NXObject
        Dim extension1 As Features.Extension = extractedbodyfeat1
        objects1(0) = extension1
        Dim nErrs1 As Integer
        nErrs1 = s.UpdateManager.AddToDeleteList(objects1)
        Dim markId5 As Session.UndoMarkId
        markId5 = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
        Dim nErrs2 As Integer
        nErrs2 = s.UpdateManager.DoUpdate(markId5)
        GoTo start1
end1:
    End Sub

    Function select_a_face(ByRef prompt As String, ByRef face1 As Face) As Selection.Response
        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        End With
        Dim cursor As Point3d = Nothing
        Dim response1 As Selection.Response = Selection.Response.Cancel
        select_a_face = Nothing
        response1 = ui.GetUI.SelectionManager.SelectTaggedObject(prompt, prompt, _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, False, _
            False, mask, face1, cursor)
        If response1 = Selection.Response.ObjectSelected Or _
            response1 = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        ElseIf response1 = Selection.Response.Back Then
            Return Selection.Response.Back
        Else
            Return Selection.Response.Cancel
        End If
    End Function

    Public Sub createExtractedBSurface(ByVal face1 As Face, ByRef extractedfeat1 As Feature)
        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
        extractFaceBuilder1 = wp.Features.CreateExtractFaceBuilder(nullFeatures_Feature)
        extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.WorkPart
        extractFaceBuilder1.Associative = True
        extractFaceBuilder1.FixAtCurrentTimestamp = True
        extractFaceBuilder1.HideOriginal = False
        extractFaceBuilder1.Type = Features.ExtractFaceBuilder.ExtractType.Face
        extractFaceBuilder1.InheritDisplayProperties = False
        extractFaceBuilder1.SurfaceType = Features.ExtractFaceBuilder.FaceSurfaceType.PolynomialCubic
        Dim added1 As Boolean
        added1 = extractFaceBuilder1.ObjectToExtract.Add(face1)
        extractedfeat1 = extractFaceBuilder1.Commit
    End Sub

    Public Function CreateStudioSplineThruPoints(ByRef points() As Point) As Features.StudioSpline
        Dim markId9 As Session.UndoMarkId
        markId9 = s.SetUndoMark(Session.MarkVisibility.Visible, "Studio Spline Thru Points")
        Dim Pcount As Integer = points.Length - 1
        Dim nullFeatures_StudioSpline As Features.StudioSpline = Nothing
        Dim studioSplineBuilderex1 As Features.StudioSplineBuilderEx
        studioSplineBuilderex1 = wp.Features.CreateStudioSplineBuilderEx(nullFeatures_StudioSpline)
        studioSplineBuilderex1.OrientExpress.ReferenceOption = GeometricUtilities.OrientXpressBuilder.Reference.ProgramDefined
        studioSplineBuilderex1.Degree = 3
        studioSplineBuilderex1.OrientExpress.AxisOption = GeometricUtilities.OrientXpressBuilder.Axis.Passive
        studioSplineBuilderex1.OrientExpress.PlaneOption = GeometricUtilities.OrientXpressBuilder.Plane.Passive
        studioSplineBuilderex1.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
        Dim knots1(-1) As Double
        studioSplineBuilderex1.SetKnots(knots1)
        Dim parameters1(-1) As Double
        studioSplineBuilderex1.SetParameters(parameters1)
        Dim nullDirection As Direction = Nothing
        Dim nullScalar As Scalar = Nothing
        Dim nullOffset As Offset = Nothing
        Dim geometricConstraintData(Pcount) As Features.GeometricConstraintData
        For ii As Integer = 0 To Pcount
            geometricConstraintData(ii) = studioSplineBuilderex1.ConstraintManager.CreateGeometricConstraintData()
            geometricConstraintData(ii).Point = points(ii)
            geometricConstraintData(ii).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
            geometricConstraintData(ii).AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.Tangent
            geometricConstraintData(ii).TangentDirection = nullDirection
            geometricConstraintData(ii).TangentMagnitude = nullScalar
            geometricConstraintData(ii).Curvature = nullOffset
            geometricConstraintData(ii).CurvatureDerivative = nullOffset
            geometricConstraintData(ii).HasSymmetricModelingConstraint = False
        Next ii
        studioSplineBuilderex1.ConstraintManager.SetContents(geometricConstraintData)
        Dim feature1 As Features.StudioSpline
        feature1 = studioSplineBuilderex1.CommitFeature()
        studioSplineBuilderex1.Destroy()
        Return feature1
    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

Frank Swinkels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor