Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Combination of Journaling and Block Styler

Hi everyone,

I managed to create a code, which create a linked Body of a selected solid body. But I want to use my own selection mask. With the help of the UI Block Styler I created a funktional mask, but I can not combine both codes. I hope someone of you will find the mistake I am making.

I am working with NX10, and thats my code:

 

 

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.BlockStyler
Imports NXOpen.UF

'----------------------------------------------------------------------
'Represents Block Styler application class
'----------------------------------------------------------------------
Public Class BlockStyler160704_Auswahl_Kathodenplatte
'class members
Private Shared theSession As Session
Private Shared theUI As UI
Private theDlxFileName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private group0 As NXOpen.BlockStyler.Group ' Block type: Group
Private drawingArea0 As NXOpen.BlockStyler.DrawingArea ' Block type: Drawing Area
Private selection0 As NXOpen.BlockStyler.SelectObject ' Block type: Selection
'---------------------------------------------------------------
'Bit Option for Property: SnapPointTypesEnabled
'---------------------------------------------------------------
Public Shared ReadOnly SnapPointTypesEnabled_UserDefined As Integer = 1
Public Shared ReadOnly SnapPointTypesEnabled_Inferred As Integer = 2
Public Shared ReadOnly SnapPointTypesEnabled_ScreenPosition As Integer = 4
Public Shared ReadOnly SnapPointTypesEnabled_EndPoint As Integer = 8
Public Shared ReadOnly SnapPointTypesEnabled_MidPoint As Integer = 16
Public Shared ReadOnly SnapPointTypesEnabled_ControlPoint As Integer = 32
Public Shared ReadOnly SnapPointTypesEnabled_Intersection As Integer = 64
Public Shared ReadOnly SnapPointTypesEnabled_ArcCenter As Integer = 128
Public Shared ReadOnly SnapPointTypesEnabled_QuadrantPoint As Integer = 256
Public Shared ReadOnly SnapPointTypesEnabled_ExistingPoint As Integer = 512
Public Shared ReadOnly SnapPointTypesEnabled_PointonCurve As Integer = 1024
Public Shared ReadOnly SnapPointTypesEnabled_PointonSurface As Integer = 2048
Public Shared ReadOnly SnapPointTypesEnabled_PointConstructor As Integer = 4096
Public Shared ReadOnly SnapPointTypesEnabled_TwocurveIntersection As Integer = 8192
Public Shared ReadOnly SnapPointTypesEnabled_TangentPoint As Integer = 16384
Public Shared ReadOnly SnapPointTypesEnabled_Poles As Integer = 32768
Public Shared ReadOnly SnapPointTypesEnabled_BoundedGridPoint As Integer = 65536
Public Shared ReadOnly SnapPointTypesEnabled_FacetVertexPoint As Integer = 131072
'----------------------------------------------------------------
'Bit Option for Property: SnapPointTypesOnByDefault
'----------------------------------------------------------------
Public Shared ReadOnly SnapPointTypesOnByDefault_EndPoint As Integer = 8
Public Shared ReadOnly SnapPointTypesOnByDefault_MidPoint As Integer = 16
Public Shared ReadOnly SnapPointTypesOnByDefault_ControlPoint As Integer = 32
Public Shared ReadOnly SnapPointTypesOnByDefault_Intersection As Integer = 64
Public Shared ReadOnly SnapPointTypesOnByDefault_ArcCenter As Integer = 128
Public Shared ReadOnly SnapPointTypesOnByDefault_QuadrantPoint As Integer = 256
Public Shared ReadOnly SnapPointTypesOnByDefault_ExistingPoint As Integer = 512
Public Shared ReadOnly SnapPointTypesOnByDefault_PointonCurve As Integer = 1024
Public Shared ReadOnly SnapPointTypesOnByDefault_PointonSurface As Integer = 2048
Public Shared ReadOnly SnapPointTypesOnByDefault_PointConstructor As Integer = 4096
Public Shared ReadOnly SnapPointTypesOnByDefault_BoundedGridPoint As Integer = 65536

#Region "Block Styler Dialog Designer generator code"
'----------------------------------------------------------------
'Constructor for NX Styler class
'----------------------------------------------------------------
Public Sub New()
Try

theSession = Session.GetSession()
theUI = UI.GetUI()
theDlxFileName = "160704_Auswahl_Kathodenplatte.dlx"
theDialog = theUI.CreateDialog(theDlxFileName)
theDialog.AddApplyHandler(AddressOf apply_cb)
theDialog.AddOkHandler(AddressOf ok_cb)
theDialog.AddUpdateHandler(AddressOf update_cb)
theDialog.AddInitializeHandler(AddressOf initialize_cb)
theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)

Catch ex As Exception

'---- Enter your exception handling code here -----
Throw ex
End Try
End Sub
#End Region

Public Shared Sub Main()
Dim theBlockStyler160704_Auswahl_Kathodenplatte As BlockStyler160704_Auswahl_Kathodenplatte = Nothing
Try

theBlockStyler160704_Auswahl_Kathodenplatte = New BlockStyler160704_Auswahl_Kathodenplatte()
' The following method shows the dialog immediately
theBlockStyler160704_Auswahl_Kathodenplatte.Show()

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
Finally
If theBlockStyler160704_Auswahl_Kathodenplatte IsNot Nothing Then
theBlockStyler160704_Auswahl_Kathodenplatte.Dispose()
theBlockStyler160704_Auswahl_Kathodenplatte = Nothing
End If
End Try
End Sub

Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
'Return CType(Session.LibraryUnloadOption.Explicitly, Integer)
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
' Return CType(Session.LibraryUnloadOption.AtTermination, Integer)
End Function
'------------------------------------------------------------------------------
' Following method cleanup any housekeeping chores that may be needed.
' This method is automatically called by NX.
'------------------------------------------------------------------------------
Public Shared Sub UnloadLibrary(ByVal arg As String)
Try

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'This method shows the dialog on the screen
'------------------------------------------------------------------------------
Public Sub Show()
Try

theDialog.Show

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'Method Name: Dispose
'------------------------------------------------------------------------------
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
End If
End Sub

'-------------------------------------------------------------------
'---------------------Block UI Styler Callback Functions------------
'-------------------------------------------------------------------

'-------------------------------------------------------------------
'Callback Name: initialize_cb
'-------------------------------------------------------------------
Public Sub initialize_cb()
Try

group0 = CType(theDialog.TopBlock.FindBlock("group0"), NXOpen.BlockStyler.Group)
drawingArea0 = CType(theDialog.TopBlock.FindBlock("drawingArea0"), NXOpen.BlockStyler.DrawingArea)
selection0 = CType(theDialog.TopBlock.FindBlock("selection0"), NXOpen.BlockStyler.SelectObject)

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'--------------------------------------------------------------------
'Callback Name: dialogShown_cb
'This callback is executed just before the dialog launch. Thus any value set
'here will take precedence and dialog will be launched showing that value.
'-------------------------------------------------------------------
Public Sub dialogShown_cb()
Try

'---- Enter your callback code here -----

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'---------------------------------------------------------------
'Callback Name: apply_cb
'---------------------------------------------------------------
Public Function apply_cb() As Integer
Dim errorCode As Integer = 0
Try

Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_Feature As Features.Feature = Nothing

Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)

Dim waveDatumBuilder1 As Features.WaveDatumBuilder
waveDatumBuilder1 = waveLinkBuilder1.WaveDatumBuilder

Dim compositeCurveBuilder1 As Features.CompositeCurveBuilder
compositeCurveBuilder1 = waveLinkBuilder1.CompositeCurveBuilder

Dim waveSketchBuilder1 As Features.WaveSketchBuilder
waveSketchBuilder1 = waveLinkBuilder1.WaveSketchBuilder

Dim waveRoutingBuilder1 As Features.WaveRoutingBuilder
waveRoutingBuilder1 = waveLinkBuilder1.WaveRoutingBuilder

Dim wavePointBuilder1 As Features.WavePointBuilder
wavePointBuilder1 = waveLinkBuilder1.WavePointBuilder

Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder

Dim mirrorBodyBuilder1 As Features.MirrorBodyBuilder
mirrorBodyBuilder1 = waveLinkBuilder1.MirrorBodyBuilder

extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain

waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.BodyLink

extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain

extractFaceBuilder1.AngleTolerance = 45.0

waveDatumBuilder1.DisplayScale = 2.0

waveLinkBuilder1.CopyThreads = False

extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart

mirrorBodyBuilder1.ParentPartType = Features.MirrorBodyBuilder.ParentPart.OtherPart

theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker Dialog")

compositeCurveBuilder1.Section.DistanceTolerance = 0.01

compositeCurveBuilder1.Section.ChainingTolerance = 0.0095

extractFaceBuilder1.Associative = True

extractFaceBuilder1.MakePositionIndependent = False

extractFaceBuilder1.FixAtCurrentTimestamp = False

extractFaceBuilder1.HideOriginal = False

extractFaceBuilder1.InheritDisplayProperties = False

Dim selectObjectList1 As SelectObjectList
selectObjectList1 = extractFaceBuilder1.BodyToExtract

extractFaceBuilder1.CopyThreads = False

Dim body1 As Object = Nothing
Dim added1 As Boolean = False

body1 = selection0

added1 = selectObjectList1.Add(body1)

Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()

theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker")

waveLinkBuilder1.Destroy()

Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assign Name")

Dim extractFace1 As Features.ExtractFace = CType(nXObject1, Features.ExtractFace)

extractFace1.SetName("Kathodenplatte")
theSession.SetUndoMarkVisibility(markId5, "Assign Name", Session.MarkVisibility.Visible)

'---- Enter your callback code here -----

Catch ex As Exception

'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function

'----------------------------------------------------------------
'Callback Name: update_cb
'----------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try

If block Is drawingArea0 Then
'---- Enter your code here -----

ElseIf block Is selection0 Then
'---- Enter your code here -----

End If

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function

'-----------------------------------------------------------------
'Callback Name: ok_cb
'-----------------------------------------------------------------
Public Function ok_cb() As Integer
Dim errorCode As Integer = 0
Try

'---- Enter your callback code here -----
errorCode = apply_cb()

Catch ex As Exception

'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = errorCode
End Function

'-----------------------------------------------------------------
'Function Name: GetBlockProperties
'Returns the propertylist of the specified BlockID
'-----------------------------------------------------------------
Public Function GetBlockProperties(ByVal blockID As String) As PropertyList
GetBlockProperties = Nothing
Try

GetBlockProperties = theDialog.GetBlockProperties(blockID)

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function

End Class

2 REPLIES
Solution
Solution
Accepted by topic author Boebel
‎07-13-2016 06:25 AM

Re: Combination of Journaling and Block Styler

[ Edited ]

Hi Boebel!

 

So you managed some code (e.g. a journal) to create a linked body. Then you used the Block Styler to create a GUI (so the user can do some selections) and what you tried is to copy your code in the 'apply_cb' method.

 

So it's just a guess, but did you check the boolean 'added1'?

I think there can occur some type conversion problems, perhaps you can try the following:

 

Dim body1(0) As TaggedObject
body1 = selection0.GetSelectedObjects()
added1 = selecteObjectList1.Add(body1)

 instead of using

Dim body1 As Object = Nothing
body1 = selection0

 

Hope that helps!

 

Bye,

 

Flo

 

Re: Combination of Journaling and Block Styler

Hi Flo,

 

Thanks a lot! That was the missing piece.