raptr1775
Automotive
- Nov 17, 2023
- 3
Hi,
I came up with the below code that allows you to select a point in your CAD model and create centerlines around the point. And, since I have no prior experience with coding in general, the code is not working and giving errors. Please help me fix this.
The error is:
From my understanding, it has something to do with the incompatibility of data types between the two functions.
I came up with the below code that allows you to select a point in your CAD model and create centerlines around the point. And, since I have no prior experience with coding in general, the code is not working and giving errors. Please help me fix this.
Code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Public Class SelectPointWithPointConstructor
Public Shared theUfSession As UFSession
Public Shared theSession As Session
Public Shared Sub Main(ByVal args As String())
theSession = Session.GetSession()
theUfSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim basePt As Point3d = New Point3d()
While SelectPoint("Select point", basePt) = UFConstants.UF_UI_OK
' Create 10mm centrelines around the selected point with respect to WCS
CreateCenterlines(basePt, 10.0)
End While
End Sub
Public Shared Function SelectPoint(ByVal cue As String, ByRef basePt As Point3d) As Integer
Dim pointTag As NXOpen.Tag = NXOpen.Tag.Null
Dim response As Integer = 0
Dim baseMethod As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointInferred
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
theUfSession.Ui.PointConstruct(cue, baseMethod, pointTag, basePt, response)
theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Return response
End Function
Public Shared Sub CreateCenterlines(ByVal basePt As Point3d, ByVal length As Double)
Dim workPart As Part = theSession.Parts.Work
Dim startPoint() As Double
Dim endPoint() As Double
Dim line As Line
' Create horizontal centreline
startPoint = New Double() {basePt.X - length / 2, basePt.Y, basePt.Z}
endPoint = New Double() {basePt.X + length / 2, basePt.Y, basePt.Z}
line = workPart.Curves.CreateLine(startPoint, endPoint)
' Create vertical centreline
startPoint = New Double() {basePt.X, basePt.Y - length / 2, basePt.Z}
endPoint = New Double() {basePt.X, basePt.Y + length / 2, basePt.Z}
line = workPart.Curves.CreateLine(startPoint, endPoint)
' Create centreline in z axis
startPoint = New Double() {basePt.X, basePt.Y, basePt/Z - length / 2}
endPoint = New Double() {basePt.X, basePt.Y, basePt/Z - length / 2}
line = workPart.Curves.CreateLine(startPoint, end Point)
End Sub
End Class
The error is:
Code:
"Line 30 : Value of type 'NXOpen.Point3d' cannot be converted to '1-dimensional array of Double'.
Line 45 : Overload resolution failed because no accessible 'CreateLine' can be called with these arguments:
'Public Function CreateLine(startPoint As NXOpen.Point, endPoint As NXOpen.Point) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point'.
'Public Function CreateLine(startPoint As NXOpen.Point, endPoint As NXOpen.Point) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point'.
'Public Function CreateLine(startPoint As NXOpen.Point3d, endPoint As NXOpen.Point3d) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point3d'.
'Public Function CreateLine(startPoint As NXOpen.Point3d, endPoint As NXOpen.Point3d) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point3d'.
Line 50 : Overload resolution failed because no accessible 'CreateLine' can be called with these arguments:
'Public Function CreateLine(startPoint As NXOpen.Point, endPoint As NXOpen.Point) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point'.
'Public Function CreateLine(startPoint As NXOpen.Point, endPoint As NXOpen.Point) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point'.
'Public Function CreateLine(startPoint As NXOpen.Point3d, endPoint As NXOpen.Point3d) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point3d'.
'Public Function CreateLine(startPoint As NXOpen.Point3d, endPoint As NXOpen.Point3d) As NXOpen.Line': Value of type '1-dimensional array of Double' cannot be converted to 'NXOpen.Point3d'.
"
From my understanding, it has something to do with the incompatibility of data types between the two functions.