Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UF
Imports NXOpen.UI
Module CreateSectionView
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim objParentView As DraftingView = Nothing
Dim objStartPoint As Point3d = Nothing
Dim objEndPoint As Point3d = Nothing
Dim objSectionViewLoc As Point3d = Nothing
If select_a_drawing_member_view(objParentView, "Select a parent view for the detail view") = Selection.Response.Ok Then
'Select the boundary point of the detail view circle
If select_screen_pos(objStartPoint, sPrompt:="Select a Start hinge point for the section view") = Selection.Response.Ok Then
If select_screen_pos(objEndPoint, sPrompt:="Select a End hinge point for the section view") = Selection.Response.Ok Then
'Select the location to place the detail view
If select_screen_pos(objSectionViewLoc, sPrompt:="Select a point to place the detail view") = Selection.Response.Ok Then
'Create the section View
FnCreateSectionView(workPart, objParentView, objStartPoint.X, objStartPoint.Y, objEndPoint.X, objEndPoint.Y, _
objSectionViewLoc.X, objSectionViewLoc.Y)
End If
End If
End If
End If
End Sub
Public Function FnCreateSectionView(ByVal objPart As Part, ByVal objParentView As DraftingView, _
ByVal dXStartPoint As Double, ByVal dYStartPoint As Double, _
ByVal dXEndPoint As Double, ByVal dYEndPoint As Double, _
ByVal dPosSectionVwX As Double, ByVal dPosSectionVwY As Double) As SectionView
Dim objSectionView As SectionView = Nothing
Dim objSectionViewBuilder As SectionViewBuilder = Nothing
Dim objSvt As SvtBuilder = Nothing
Dim objHingeLineBuilder As HingeLineBuilder = Nothing
'Hinge Line Direction
Dim dir As Direction = Nothing
Dim objStartPoint As Point = Nothing
Dim objEndPoint As Point = Nothing
Dim objSectionViewCreated As SectionView = Nothing
Dim unit1 As Unit = CType(objPart.UnitCollection.FindObject("MilliMeter"), Unit)
'If a null reference (Nothing in Visual Basic), then creates a section view
Try
objSectionViewBuilder = objPart.DraftingViews.CreateSectionViewBuilder(objSectionView)
'Section view tool builder
objSvt = objSectionViewBuilder.SectionViewTool
'Default Properties
objSvt.Orientation = False
objSectionViewBuilder.ViewPlacement.AlignmentMethod = ViewPlacementBuilder.Method.Infer
objSectionViewBuilder.ViewPlacement.AlignmentOption = ViewPlacementBuilder.Option.ToView
'Parent View
objSectionViewBuilder.ViewPlacement.AlignmentView.Value = objParentView
objSectionViewBuilder.ViewStyle.ViewStyleGeneral.AngleValue = 0.0
objSectionViewBuilder.ViewStyle.ViewStyleGeneral.Scale.Denominator = 1.0
objSectionViewBuilder.ViewStyle.ViewStyleGeneral.Scale.Numerator = 1.0
objSectionViewBuilder.ViewStyle.ViewStyleGeneral.Scale.ScaleType = ViewScaleBuilder.Type.Ratio
objSectionViewBuilder.ViewStyle.ViewStyleOrientation.HingeLine.ReverseDirection = False
objSectionViewBuilder.ViewStyle.ViewStyleOrientation.HingeLine.VectorOption = HingeLineBuilder.Hingeline.Defined
Dim expression5 As Expression
expression5 = objPart.Expressions.CreateSystemExpressionWithUnits(dXStartPoint.ToString, unit1)
Dim scalar1 As Scalar
scalar1 = objPart.Scalars.CreateScalarExpression(expression5, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
Dim expression6 As Expression
expression6 = objPart.Expressions.CreateSystemExpressionWithUnits(dYStartPoint.ToString, unit1)
Dim scalar2 As Scalar
scalar2 = objPart.Scalars.CreateScalarExpression(expression6, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
Dim expression7 As Expression
expression7 = objPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim scalar3 As Scalar
scalar3 = objPart.Scalars.CreateScalarExpression(expression7, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
objStartPoint = objPart.Points.CreatePoint(scalar1, scalar2, scalar3, SmartObject.UpdateOption.AfterModeling)
Dim expression8 As Expression
expression8 = objPart.Expressions.CreateSystemExpressionWithUnits(dXEndPoint.ToString, unit1)
Dim scalar10 As Scalar
scalar10 = objPart.Scalars.CreateScalarExpression(expression8, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
Dim expression9 As Expression
expression9 = objPart.Expressions.CreateSystemExpressionWithUnits(dYEndPoint.ToString, unit1)
Dim scalar11 As Scalar
scalar11 = objPart.Scalars.CreateScalarExpression(expression9, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
Dim expression10 As Expression
expression10 = objPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim scalar12 As Scalar
scalar12 = objPart.Scalars.CreateScalarExpression(expression10, Scalar.DimensionalityType.None, SmartObject.UpdateOption.AfterModeling)
objEndPoint = objPart.Points.CreatePoint(scalar10, scalar11, scalar12, SmartObject.UpdateOption.AfterModeling)
dir = objPart.Directions.CreateDirection(objStartPoint, objEndPoint, SmartObject.UpdateOption.AfterModeling)
objSectionViewBuilder.ViewStyle.ViewStyleOrientation.HingeLine.SpecifyVector = dir
objSectionViewBuilder.ViewStyle.ViewStyleOrientation.Ovt.AssociativeOrientation = False
objSectionViewBuilder.ViewUnfolded = True
'Place the Section View
Dim ObjSectVwPlacementPoint As Point3d = New Point3d(dPosSectionVwX, dPosSectionVwY, 0.0)
objSectionViewBuilder.ViewPlacement.Placement.SetValue(Nothing, objPart.Views.WorkView, ObjSectVwPlacementPoint)
Dim nXObject1 As NXObject
If objSectionViewBuilder.Validate Then
nXObject1 = objSectionViewBuilder.Commit()
objSectionViewCreated = CType(nXObject1, SectionView)
FnCreateSectionView = objSectionViewCreated
Else
FnCreateSectionView = Nothing
End If
objSectionViewBuilder.Destroy()
Catch ex As NXException
Dim lw As ListingWindow = Session.GetSession.ListingWindow
lw.Open()
lw.WriteLine(ex.Message)
lw.WriteLine(ex.StackTrace)
End Try
End Function
Function select_a_drawing_member_view(ByRef dwgview As Drawings.DraftingView, ByVal sPrompt As String)
Dim ui As UI = GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
Dim vw As TaggedObject = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectTaggedObject(sPrompt, _
sPrompt, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, vw, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
dwgview = CType(vw, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function select_screen_pos(ByRef loc As Point3d, Optional ByVal sPrompt As String = "Screen Position:") As Selection.Response
Dim resp As Selection.DialogResponse = Selection.DialogResponse.None
Dim localView As View = Nothing
UFSession.GetUFSession.Ui.SetCursorView(1)
resp = UI.GetUI.SelectionManager.SelectScreenPosition(sPrompt, _
localView, loc)
If resp <> Selection.DialogResponse.Back And _
resp <> Selection.DialogResponse.Cancel Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module