Submitted by les-paul on Fri, 10/09/2015 - 00:56
Forums:
Hey guys,
I have a Problem. I have a sketch of a mechanism, which is mooving by changing an Expression (From 0-360°). I succesfully programmed a vb file which is changing the Expression the way I want. The sketch contains also a Point ( as Center of mass) This Point is moving as well. I want to project this Point on a seperate Datum plane after every change of the Expression, to get the mooving curve of this Point.
Is there a way to read out the koordinates of this Point for every iteration? How can i identify the Point-id? is there a command which works like " read out the koordinates of Point XX)
Thank you very much!
Daniel
re: point coordinates
I'd suggest that you give the point a custom name; doing so will make it easier to identify later in your journal code. Once you have a reference to the point object, you can use the .Coordinates property to read the point coordinates.
Thank you very much. Can you
Thank you very much. Can you tell my how i can do that? Would it be Helpful to pot the recorded Journal Code?
re: find named point
To name a point, right click on the point object in the NX file and choose "properties". On the properties dialog, change to the "General" tab; enter a name in the entry box. If you have chosen a point feature, you may see both a "name" entry and a "feature name" entry; in this case, use the "name" entry and ignore the "feature name". For illustration, let's say you name the point "TEST"; OK the dialog to close it. The code below will cycle through the points in the work part and report if it finds one named "TEST".
Option Strict Off
Imports System
Imports NXOpen
Module FindPoint
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UF.UFSession = UF.UFSession.GetUFSession
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim thePoint As Point
Const nameToFind As String = "TEST"
Dim found As Boolean = False
For Each pt As Point In workPart.Points
If pt.Name = nameToFind Then
thePoint = pt
found = True
'stop looping after the point is found
Exit For
End If
Next
If found Then
lw.WriteLine("point named: " & nameToFind & " was found, coordinates: " & thePoint.Coordinates.ToString)
Else
lw.WriteLine("no point named: " & nameToFind & " was found")
End If
lw.Close()
End Sub
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
To use a different name for the point, right click on the point and enter a new name. Update the journal code to look for the new name.
Small Success
Hello, I Think I got it. Here is a part of my code. It works the way I want to.
Dim GSP As Point
Const nameToFind As String = "Gesamtschwerpunkt"
Dim found As Boolean = False
For Each pt As Point In workPart.Points
If pt.Name = nameToFind Then
GSP = pt
found = True
'stop looping after the point is found
Exit For
End If
Next
If found Then
'lw.WriteLine("point named: " & nameToFind & " was found, coordinates: " & thePoint.Coordinates.X.ToString)
Else
' lw.WriteLine("no point named: " & nameToFind & " was found")
End If
'lw.WriteLine("point named: " & nameToFind & " was found, coordinates: " & thePoint.Coordinates.tostring)
'lw.Close()
'Koordinaten des gefundenen Punkts auslesen
Dim GSPX as double
dim GSPY as double
Dim GSPZ as double
GSPX= "100"
GSPY=GSP.coordinates.y.tostring
GSPZ=GSP.coordinates.z.tostring
'lw.WriteLine(" Haben wir Y? " & GSPZ)
'lw.Close()
'Point3d mit gefunden Koordinaten erstellen
dim GSP3D as point3d= new point3d (GSPX, GSPY, GSPZ)
'Point mit Gefundenen Koordinaten erstellen, warum auch immer?
dim GSP2D as point
GSP2D = workPart.Points.CreatePoint(GSP3D)
GSP2D.SetVisibility(SmartObject.VisibilityOption.Visible)
But it works just for the case the Point "Gesamtschwerpunkt" is a Point inside a sketch. How can I get this working if "Gesamtschwerpunkt" is a Point3d?
Thanks a alot
re: point
I've tried your code and it works for me whether the point is in a sketch or not. If you have multiple point objects with the same name, the code above will only process the first one that it finds. If you want it to process all of the points with a given name, the code will need to be modified.
hello,
hello,
when the searched pointname is changed from a Point in a sketch to a Point in the room, the following message appears:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
In english I would translate it as "The Object reference is not connected to an object entity"
Furthermor the line with the following Conde is mentioned as error Location
GSPX=GSP.coordinates.x.tostring
re: named point
Based on the error message, I'd guess that the point object was not found by your code. Check to make sure that the name of the point object and the name in the journal code match exactly - if they do not match exactly, the point will not be found. Also note that the code operates on the work part. Make sure that the part you want to search is the work part (or change the journal code accordingly).
The code example that I posted uses a boolean variable named "found" that gets set to "True" when the point is found. You can use this variable to see if the For loop found the point object or not. The rest of your code can take action accordingly.