On the attached image bellow is an single line which is perpendicular to the pathe curve. That line is patterned along the curve.
I am wondering if someone could give me idea how to get the start (fixed) point of each instance. I can do by creating intesection points between curve and each instance but problem happened when I try to sort the coords of the points by x or y value. Points are getting mixed. Coordinates of the points must be arranged by the instance order.
Any idea is gladly appreciated!
Solved! Go to Solution.
Can you get a point on curve percentage on each of the instances? If the directions are mixed, you might have to create 0 and 100 percent, and ask which one is closer to the parent curve.
Alternatively, you could use the distance by arc length to sort your intersection points. Just ask for distance to 0 percent point of the parent curve.
length, curves = theSession.Measurement.GetArcLengthBetweenPoints(p1, p2)
But then you can even calculate the arc length percentages your intersection points are at!
If you use workPart.Points.CreatePoint() (workPart.Points is a NXOpen.PointCollection)
with this signature
Signature CreatePoint(edgeCurve, scalarT, locationOption, updateOption)
I am not familiar with Python programming. I use VB.Net (VS2015) and search for the functions that you provided.
In the meaning time, I have used PointSet option to create points on curve (path used for pattern before) by equal arc length but the results are not what I expected.
Compare created points and start points of the instances are showed on the image bellow.
Hmm, that could either be a tolerance thing, or a display thing. Are they still different points if you set the display resolution to high in the Visualization Preferences?
If they really are different, I'd suggest creating the 0-percent points for each child curve.
The function names are usually the same. I just found out that the .NET reference is not available online. Weird. I'd look for the PointCollection.CreatePoint function.
Try running the following journal. Note that it assumes the objects that were patterned are lines (as shown in your screenshot), other objects may give errors or odd results.
Option Strict Off
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim myPatternGeo As Features.PatternGeometry = Nothing
Dim found As Boolean = False
For Each temp As Features.Feature In workPart.Features
If TypeOf (temp) Is Features.PatternGeometry Then
myPatternGeo = temp
found = True
If Not found Then
lw.WriteLine("no pattern geometry feature found")
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
Dim patternedObjs() As DisplayableObject
patternedObjs = myPatternGeo.GetAssociatedCurvesPointsDatums
lw.WriteLine("number of patterned objects: " & patternedObjs.Length.ToString)
lw.WriteLine("start points of patterned lines")
For Each temp As Line In patternedObjs
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
This works great and there should not be a problem cause the object that I would like to pattern is always a single line.
There is one more thing that I would like to achieve. On the attached video you will see why I needed start point of each instance line. After instances are trimmed with some studio spline, I wanted to use start/end point to get midpoint of each trimmed curve. I have done it by using coordinates of start/end points for each trimmed curve.
Dim midPointX, midPointY As Double midPointX = (startPointX + endPointX) / 2 midPointY = (startPointY + endPointY) / 2
I believe there is some easier way by using NX functions.
If you need to create a point that is associative to the midpoint of the line, the .CreatePoint method has some options for that. If all you need are the unassociative coordinates of the midpoint for a given line, what you have is probably as easy as it gets.