MIdsurface creation

Hello,

I tried to create a code for it to be created in the Midsurface layer 30 in the category study, but did not succeed. Could anyone help me?

Tks

M.

What version of NX?

Hello,

The version is 9.5

Tks in advance

Sorry... The version is 9

The following journal will try to create a midsurface feature using the first body found in the work part. It was made from a journal that was recorded in an inch part; the "thickness value" and "search distance" values may not apply to your situation. This is not a fully realized solution, but it illustrates how to change the work layer before creating a feature (and changing the work layer back when done).

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim oldWorkLayer As Integer = workPart.Layers.WorkLayer

'set work layer = layer 30
workPart.Layers.WorkLayer = 30

'create midsurface from first body found
Dim theBodies() As Body = workPart.Bodies.ToArray

Try
Dim nullFeatures_Feature As Features.Feature = Nothing

Dim midSurfaceByFacePairsBuilder1 As Features.MidSurfaceByFacePairsBuilder
midSurfaceByFacePairsBuilder1 = workPart.Features.CreateMidSurfaceByFacePairsBuilder(nullFeatures_Feature)

midSurfaceByFacePairsBuilder1.ThicknessValue.RightHandSide = "0.078"

midSurfaceByFacePairsBuilder1.SearchDistance.RightHandSide = "0.078"

midSurfaceByFacePairsBuilder1.UpdateOption = True

midSurfaceByFacePairsBuilder1.ValidateSelection(0)

midSurfaceByFacePairsBuilder1.SetupFacePairInContext(nullFeatures_Feature)

Dim added1 As Boolean
added1 = midSurfaceByFacePairsBuilder1.BodySelection.Add(theBodies(0))

midSurfaceByFacePairsBuilder1.ValidateSelection(0)

midSurfaceByFacePairsBuilder1.SetupFacePairInContext(nullFeatures_Feature)

Dim facepairs1() As Features.Feature
facepairs1 = midSurfaceByFacePairsBuilder1.CreateFacePair()

midSurfaceByFacePairsBuilder1.ValidateSelection(0)

midSurfaceByFacePairsBuilder1.SetupFacePairInContext(nullFeatures_Feature)

midSurfaceByFacePairsBuilder1.SetupFacePairInContext(nullFeatures_Feature)

Dim nXObject1 As NXObject
nXObject1 = midSurfaceByFacePairsBuilder1.Commit()

midSurfaceByFacePairsBuilder1.Destroy()

Catch ex As NXException

Finally
'reset work layer
workPart.Layers.WorkLayer = oldWorkLayer
End Try

lw.Close()

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

First, tks for your help!

My idea was simple. Would open the midsurface offset command window and wait for the user to choose the face. After selecting the face, ok midsurface the offset would create the window layer 30 in category study ever performed with the command of midsurface.

Menu: Insert->Surface->Midsurface->Offset...

Journal code does not manipulate dialog boxes for the user. In other words, a journal will not open a dialog and wait for user input then continue running.

Perhaps a macro would be better suited to your task...

I noticed that the lines of code can call the nx commands. I would like to make the offset screen midsurface only open ???

Journal code calls the NX commands directly, essentially bypassing the GUI. In the current versions of NX (as of this writing), I know of no way to reliably get a journal to interact with the existing NX dialog boxes.

If you have a block styler (or UI styler) license, you might be able to create a dialog box similar to the one used in the midsurface command. You would then have control of what happens in the dialog box.

And the CTYPE command? I recorded a journal and I noticed that this command is the last one.

The CType function is part of the .net framework, it converts one datatype to another (where possible).

https://msdn.microsoft.com/en-us/library/4x2877xb.aspx

Could anyone explain me?

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Offset Midsurface")

Dim thicken1 As Features.Thicken = CType(workPart.Features.FindObject("THICKEN_SHEET(1)"), Features.Thicken)

Dim face1 As Face = CType(thicken1.FindObject("FACE [THICKEN_SHEET(1) FACE [UNPARAMETERIZED_FEATURE(0) FACE 1]] {(1002.4832969953543,-288.5012130837504,1124.8014628311175) THICKEN_SHEET(1)}"), Face)

Dim nXObject1 As NXObject
Dim xform1 As Xform
xform1 = workPart.Xforms.CreateExtractXform(face1, SmartObject.UpdateOption.WithinModeling, False, nXObject1)

theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Visible)

theSession.DeleteUndoMark(markId1, Nothing)

theSession.CleanUpFacetedFacesAndEdges()

Tks in advance

What is your question?