Extract Center line of a cylindrical body
Extract Center line of a cylindrical body
(OP)
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
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





RE: Extract Center line of a cylindrical body
RE: Extract Center line of a cylindrical body
www.nxjournaling.com
RE: Extract Center line of a cylindrical body
The component like a flexible hoses, which not like a regular defined shapes. also like tubes which connected in the lubrication system.
Regards
Manikanda
RE: Extract Center line of a cylindrical body
thread561-366408: Looking for a journal which gives total length of cable
or here:
http://nxjournaling.com/content/extract-centerline...
If you find the code useful, be sure to give Frank a star in the eng-tips thread linked to above.
www.nxjournaling.com
RE: Extract Center line of a cylindrical body
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
RE: Extract Center line of a cylindrical body
Frank Swinkels
RE: Extract Center line of a cylindrical body
Thanks for your kind reply.
Please find the sample part for your reference.
Regards
Manikanda
RE: Extract Center line of a cylindrical body
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.
RE: Extract Center line of a cylindrical body
I have tried Extract Virtual curve function. But needed is the center line for Both Straight and Elbow.
Regards
Manikanda
RE: Extract Center line of a cylindrical body
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.
RE: Extract Center line of a cylindrical body
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 ModuleFrank Swinkels
RE: Extract Center line of a cylindrical body
It solves my req.
Regards
Manikanda