Submitted by Muthuzz007 on Sat, 03/14/2020 - 06:07
Forums:
I would like to create a cylinder with user input.
cylindr dia =50
cylinder height = 10
user interaction : select position and vector.
can anybody help me?
I would like to create a cylinder with user input.
cylindr dia =50
cylinder height = 10
user interaction : select position and vector.
can anybody help me?
Create Cylinder
Hi, please find attached my code for creating a cylinder:
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Collections
Imports System.Maths
Module NXJournal
Public ufs As UFSession = UFSession.GetUFSession()
Public theUI As UI = ui.GetUI
Public theSession As Session = Session.GetSession()
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Public markId1 As Session.UndoMarkId
'###
Public title as String
Public perc as String
Public name as String
Public selobj As NXObject
Public cursor As Point3d
'---------------------
Public base_pt As Double() = New Double(2) {}
Public select3d as Point3D
Public bm As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointInferred
Public cancel As Boolean = False
Public dbl2(1) As Double
Sub Main
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Cylinder")
title="Select a Point"
If select_point(title, base_pt, bm) = UFConstants.UF_UI_OK
select3d = New Point3d(base_pt(0).ToString, base_pt(1).ToString, base_pt(2).ToString)
Else
Exit Sub
End If
Dim dia, height As Double
Dim datumAxis1 As DatumAxis
dbl2 = InputDoubles2("Input", "Cyl diameter:", "Cyl height:", 0, 0)
If cancel=True Then
cancel=False
End If
title="Select a DatumAxis"
If select_datum(selobj) = Selection.Response.Ok
If selobj.GetType.ToString ="NXOpen.DatumAxis" Then
datumAxis1 = CType(NXObjectManager.Get(selobj.tag), DatumAxis)
Else
Exit Sub
End if
Else
Exit Sub
End If
createCyl(select3d, dbl2(0), dbl2(1), datumAxis1)
End Sub
Function createCyl(ByVal pt3D As Point3D, dia As Double, height As Double, datumAxis1 As DatumAxis)
Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing
Dim cylinderBuilder1 As NXOpen.Features.CylinderBuilder
cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(nullNXOpen_Features_Feature)
cylinderBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create
cylinderBuilder1.Diameter.RightHandSide = Replace(dia.ToString,",",".")
cylinderBuilder1.Height.RightHandSide = Replace(height.ToString,",",".")
Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim pt As Point = workPart.Points.CreatePoint(pt3D)
Dim axis1 As NXOpen.Axis
axis1 = cylinderBuilder1.Axis
axis1.Direction = workPart.Directions.CreateDirection(datumAxis1, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
axis1.Point = pt
Dim nxObject1 As NXObject
nXObject1 = cylinderBuilder1.Commit()
Dim body1 As Body = CType(workPart.Bodies.FindObject(nXObject1.journalidentifier), Body)
cylinderBuilder1.Destroy()
Return body1
End Function
Function InputDoubles2(ByVal title As String, string1 As String, string2 As String, dbl1 As Double, dbl2 As Double)
Dim strPrompt2 As String = title
Dim strChoices2() As String = {string1, string2}
Dim DblChoices2() As Double = {dbl1, dbl2}
Dim resp2 As Integer
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
resp2 = ufs.Ui.GetInputDoubles(strPrompt2, strChoices2, 2, DblChoices2, 0)
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If resp2 = 1 or resp2 = 2 Then
cancel=True
Else
Return DblChoices2
End If
End Function
Function select_datum(ByRef selobj As NXObject) As Selection.Response
Dim theUI As UI = ui.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
"Select a Plane", title, _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function select_point(ByVal cue As String, ByRef base_pt As Double(), ByVal base_method As UFUi.PointBaseMethod) As Integer
Dim theUI As UI = ui.GetUI
Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null
Dim response As Integer = 0
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
ufs.Ui.PointConstruct(cue, base_method, point_tag, base_pt, response)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
bm = base_method
Return response
End Function
End Module
Not a design feature?
You seem to want to replicate the function of the simple Insert > Design Feature > Cylinder ?? Do you need some different behaviour from the default?