Command to pause a Journal

Hello,

I have developed some macros to delete specific portions of a drawing.
Then I am triggering these macros from a journal based on the sheet size.
After the macro is run I need a IGS exported with sheet size suffixed at the end (eg: 132345_A0.igs).

But the problem is the IGS creation is triggered before the macro is complete. I need the journal to wait for a stipulated amount of time let's say 30 Seconds.

I have tried using the thread.sleep. But this also stops the processing of the macro (The entire NX thread is paused).

Is there any possible way that the journal be edited so that it waits for the macro execution to be complete and then proceed further.

Thank you in advance for you support. You can find the code below

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.Threading

Module NXJournal
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Declare Sub MACRO_playback_from_usertool Lib "libugui" Alias "?MACRO_playback_from_usertool@@YAXPEBD@Z" (ByVal lpName As String)
Sub Main (ByVal args() As String)

lw.Open()

Dim displayPart As NXOpen.Part = theSession.Parts.Display

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

Dim drawingSheet1 As NXOpen.Drawings.DrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet

Dim drawingSheetBuilder1 As NXOpen.Drawings.DrawingSheetBuilder = Nothing
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(drawingSheet1)

Dim height As Integer = (drawingSheetBuilder1.Height)
Dim length As Integer = (drawingSheetBuilder1.Length)

If (height=841) then

MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A0_VW.macro")

End If

If (height=594) then

MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A1_VW.macro")

End If

If (height=420) then

MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A2_VW.macro")

End If

If (height=841) then

Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 4) & "_A0.igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

End If

If (height=594) then

Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 4) & "_A1.igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

End If

If (height=420) then

Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 4) & "_A2.igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

End If

End Sub

Sub ExportIges(ByVal partToExport As Part, ByVal exportFileName As String)

Dim IGES_DIR As String = theSession.GetEnvironmentVariableValue("IGES_DIR")
Dim igesFile As String
igesFile = IO.Path.Combine(IGES_DIR, "igesexport.def")

If Not IO.File.Exists(igesFile) Then
Throw New Exception("igesexport.def file not found")
Return
Else
'lw.WriteLine("IGES definition file found at: " & igesFile)
End If

Thread.Sleep(30000)
Dim igesCreator1 As IgesCreator
igesCreator1 = theSession.DexManager.CreateIgesCreator()

With igesCreator1
.ExportFrom = IgesCreator.ExportFromOption.ExistingPart
.SettingsFile = igesFile
.ExportModelData = False
.ExportDrawings = True
.MapTabCylToBSurf = True
.BcurveTol = 0.0508
.IdenticalPointResolution = 0.001
.MaxThreeDMdlSpace = 10000.0
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Annotations = True
.ObjectTypes.Structures = True
.ObjectTypes.Solids = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.ObjectTypes.Csys = True
.MaxLineThickness = 2.0
.SysDefmaxThreeDMdlSpace = True
.SysDefidenticalPointResolution = True
.FileSaveFlag = False
.LayerMask = "1-256"
.DrawingList = ""
.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined"

End With

Dim nXObject2 As NXObject
nXObject2 = igesCreator1.Commit()

igesCreator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

End Sub

End Module

Calling a macro from a journal is possible, but unsupported. For better control over what happens when, I'd suggest using only journal commands. Write a journal that does the same thing as the macro then incorporate that code into your main journal.

Thank you for your suggestion. But the issue is that when I try to record a journal for the same functions it is recording the actual entities (specific note and lines). The macros are recorded to remove the frame of the drawing (It has to select specific regions based on co-ordinates).

Can you please let me know how this can be implemented in the Journal.

A sample macro for A1 sheet size is copied below


CURSOR_EVENT 1001 7,1,205,1 ! begin_drag, mb1/0+0, , dh
CPOS -1.0,595.0,0
CPOS -1.0,595.0,0
CURSOR_EVENT 1001 5,1,101,5 ! two_pt, mb1/0+0, , rs
CPOS -1.0,595.0,0
CPOS_WV 1001,842.0,583.8,0
MENU, 0, UG_EDIT_DELETE UG_GATEWAY_MAIN_MENUBAR < Delete> ## !
CURSOR_EVENT 1001 7,1,205,1 ! begin_drag, mb1/0+0, , dh
CPOS 842.0,595.0,0
CPOS 842.0,595.0,0
CURSOR_EVENT 1001 9,1,0,0 ! term_drag, mb1/0+0, , nn
CURSOR_EVENT 1001 7,1,205,1 ! begin_drag, mb1/0+0, , dh
CPOS 842.0,595.0,0
CPOS 842.0,595.0,0
CURSOR_EVENT 1001 5,1,101,5 ! two_pt, mb1/0+0, , rs
CPOS 842.0,595.0,0
CPOS_WV 1001,830.9,-1.0,0
MENU, 0, UG_EDIT_DELETE UG_GATEWAY_MAIN_MENUBAR < Delete> ## !
CURSOR_EVENT 1001 7,1,205,1 ! begin_drag, mb1/0+0, , dh
CPOS 842.0,-1.0,0
CPOS 842.0,-1.0,0
CURSOR_EVENT 1001 5,1,101,5 ! two_pt, mb1/0+0, , rs
CPOS 842.0,-1.0,0
CPOS_WV 1001,-1.0,10.1,0
MENU, 0, UG_EDIT_DELETE UG_GATEWAY_MAIN_MENUBAR < Delete> ## !
CURSOR_EVENT 1001 7,1,205,1 ! begin_drag, mb1/0+0, , dh
CPOS -2.0,595.0,0
CPOS -2.0,595.0,0
CURSOR_EVENT 1001 5,1,101,5 ! two_pt, mb1/0+0, , rs
CPOS -2.0,595.0,0
CPOS_WV 1001,20.5,-2.0,0
CURSOR_EVENT 1001 7,545,205,1 ! begin_drag, mb1/0+22, , dh
CPOS -24.4288156362681,284.331620428752,0
CPOS -23.6610350561924,275.118253467844,0
CURSOR_EVENT 1001 5,545,103,6 ! two_pt, mb1/0+22, , rd
CPOS -24.4288156362681,284.331620428752,0
CPOS_WV 1001,15.4957745276664,4.09170870113496,0
MENU, 0, UG_EDIT_DELETE UG_GATEWAY_MAIN_MENUBAR < Delete> ## !

You can use below method to select the drawing objects based on the co-ordinates.

Change P1 and P2 point values. P1 is the upper left point of rectangle and P2 is the bottom right point of the rectangle. This program go thru the each displayable objects in the current drawing sheet and gets the bounding box of objects using ASKBOUNDINGBOX. Askboundingbox will return below output.
[0] - minimum x value
[1] - minimum y value
[2] - minimum z value
[3] - maximum x value
[4] - maximum y value
[5] - maximum z value
as we are in drawing we can eliminate z values.
[0] and [1] values are passed to Tp1 point variable and [3] and [4] values are passed to Tp2 point variable.
Using Rectangle.Contains method program finds whether both points are inside or outside of given area. if both points are inside then those objects will be added to the selection.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Drawing
Module Module1

Sub Main()

Dim ugs As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession
Dim workpart As Part = ugs.Parts.Work
Dim lw As ListingWindow = ugs.ListingWindow
Dim SelObj As New List(Of NXObject)

Dim p1 As New System.Drawing.Point(390, 610) 'Upper left point
Dim p2 As New System.Drawing.Point(710, 410) 'Bootom Right point

Dim x As Integer = Math.Min(p1.X, p2.X)
Dim y As Integer = Math.Min(p1.Y, p2.Y)
Dim w As Integer = Math.Abs(p1.X - p2.X)
Dim h As Integer = Math.Abs(p2.Y - p1.Y)
Dim rect As New Rectangle(x, y, w, h)

Dim box(5) As Double
lw.Open()

For Each myObj As DisplayableObject In workpart.DrawingSheets.CurrentDrawingSheet.View.AskVisibleObjects

ufs.Modl.AskBoundingBox(myObj.Tag, box)
Dim Tp1 As New System.Drawing.Point(box(0), box(1))
Dim Tp2 As New System.Drawing.Point(box(3), box(4))
If rect.Contains(Tp1) And rect.Contains(Tp2) Then
'lw.WriteLine("Object Tag: " & myObj.Tag)
'lw.WriteLine("Object Type: " & myObj.GetType.ToString)
'lw.WriteLine("BOX: " & box(0) & ":" & box(1) & ":" & box(2) & ":" & box(3) & ":" & box(4) & ":" & box(5))
'lw.WriteLine("")
SelObj.Add(myObj)
End If
Next

For Each tobj As DisplayableObject In SelObj
tobj.Highlight()
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

I'm not familiar with using macro in journal, but at least you can run Thread.Sleep asynchronously and wait for the sleep. This will not block the thread.
The code below will print 1 and 2 first, and will wait for t1 to finish,
then print 3.

Console.WriteLine(1);
var t1 = Task.Factory.StartNew(()=>{
Thread.Sleep(5000);
});
Console.WriteLine(2);
t1.Wait();
Console.WriteLine(3);
Console.ReadKey();