Hello everybody. Im quite new with the use of journals. I would like locate differente cylinders taking as input selected points. I know the function select points but I can not associate it with the cylinders. I took the cylinder code just recording the journal,but I suppose it is not the correct way.
Thank you in advance.
Yua.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UI
Module NXJournal
Sub Main(ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Insert->Design Feature->Cylinder...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullFeatures_Feature As Features.Feature = Nothing
If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If
Dim cylinderBuilder1 As Features.CylinderBuilder
cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
'cylinderBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
'Dim targetBodies1(0) As Body
'Dim nullBody As Body = Nothing
'targetBodies1(0) = nullBody
'cylinderBuilder1.BooleanOption.SetTargetBodies(targetBodies1)
cylinderBuilder1.Diameter.RightHandSide = "5.7"
cylinderBuilder1.Height.RightHandSide = "0.2"
cylinderBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
Dim targetBodies2(0) As Body
'targetBodies2(0) = nullBody
cylinderBuilder1.BooleanOption.SetTargetBodies(targetBodies2)
theSession.SetUndoMarkName(markId1, "Cylinder Dialog")
Dim unit1 As Unit
unit1 = cylinderBuilder1.Height.Units
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim pointFeature1 As Features.PointFeature = CType(workPart.Features.FindObject("POINT(3)"), Features.PointFeature)
Dim myPoints As Point
If SelectPoints("Select points", myPoints) = Selection.Response.Cancel Then
Return
End If
Dim point1 As Point = myPoints 'CType(pointFeature1.FindObject("POINT 1"), Point)
Dim nullXform As Xform = Nothing
Dim point2 As Point
point2 = workPart.Points.CreatePoint(point1, nullXform, SmartObject.UpdateOption.WithinModeling)
Dim axis1 As Axis
axis1 = cylinderBuilder1.Axis
axis1.Point = point2
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
Dim nXObject1 As NXObject
nXObject1 = cylinderBuilder1.Commit()
theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(markId1, "Cylinder")
Dim expression3 As Expression = cylinderBuilder1.Height
Dim expression4 As Expression = cylinderBuilder1.Diameter
cylinderBuilder1.Destroy()
workPart.Expressions.Delete(expression2)
workPart.Expressions.Delete(expression1)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Function SelectPoints(ByVal prompt As String, ByRef thePoints as Point) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = NXOpen.UF.UFConstants.UF_point_type
.Subtype = NXOpen.UF.UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
Thank you in advance.
Yua.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UI
Module NXJournal
Sub Main(ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Insert->Design Feature->Cylinder...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullFeatures_Feature As Features.Feature = Nothing
If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If
Dim cylinderBuilder1 As Features.CylinderBuilder
cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
'cylinderBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
'Dim targetBodies1(0) As Body
'Dim nullBody As Body = Nothing
'targetBodies1(0) = nullBody
'cylinderBuilder1.BooleanOption.SetTargetBodies(targetBodies1)
cylinderBuilder1.Diameter.RightHandSide = "5.7"
cylinderBuilder1.Height.RightHandSide = "0.2"
cylinderBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
Dim targetBodies2(0) As Body
'targetBodies2(0) = nullBody
cylinderBuilder1.BooleanOption.SetTargetBodies(targetBodies2)
theSession.SetUndoMarkName(markId1, "Cylinder Dialog")
Dim unit1 As Unit
unit1 = cylinderBuilder1.Height.Units
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim pointFeature1 As Features.PointFeature = CType(workPart.Features.FindObject("POINT(3)"), Features.PointFeature)
Dim myPoints As Point
If SelectPoints("Select points", myPoints) = Selection.Response.Cancel Then
Return
End If
Dim point1 As Point = myPoints 'CType(pointFeature1.FindObject("POINT 1"), Point)
Dim nullXform As Xform = Nothing
Dim point2 As Point
point2 = workPart.Points.CreatePoint(point1, nullXform, SmartObject.UpdateOption.WithinModeling)
Dim axis1 As Axis
axis1 = cylinderBuilder1.Axis
axis1.Point = point2
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
Dim nXObject1 As NXObject
nXObject1 = cylinderBuilder1.Commit()
theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(markId1, "Cylinder")
Dim expression3 As Expression = cylinderBuilder1.Height
Dim expression4 As Expression = cylinderBuilder1.Diameter
cylinderBuilder1.Destroy()
workPart.Expressions.Delete(expression2)
workPart.Expressions.Delete(expression1)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Function SelectPoints(ByVal prompt As String, ByRef thePoints as Point) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = NXOpen.UF.UFConstants.UF_point_type
.Subtype = NXOpen.UF.UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module