Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all 784 articles
Browse latest View live

How to change layer for non-collection objects

$
0
0

Hi, NXJournaling! Thank you very match for you helpfull page!
I need help again.. Look it please.

for example, to change the layer of curves we use the code

'create list variable for curves objectsDim mycurves As List(Of curve)=New List(Of curve)ForEach curve As curve In workPart.curves
            mycurves.Add(curve)Next
        workPart.Layers.MoveDisplayableObjects(8, mycurves.ToArray)

but for NXOpen.Annotations. objects.. it does not work.
Can you show example to change layer for all NXOpen.Annotations.DraftingSurfaceFinish objects in workpart?


Get Space Type form selected Pattern Feature

$
0
0

Hi,

I would like to let user select pattern feature and do something with it. But it is necessary to split code for SpaceType "Offset" and SpaceType "List". How do I get spaceType from selected Pattern Feature? I cabt find out how use GeometricUtilities.PatternSpacing.SpacingType to return value as String.

getting features of component in drafting

NX drawing simple/stepped section line

$
0
0

Hello there,
I am new to this forum. Nice work here and I need help. In NX drawing, the cross-sectional appearance name is "THIN". I want to change the appearance of all sections within the page to "NORMAL". The letters I want to change are next to arrows in cross-section. Do you have a journel for this, or can you help me to create one?

Get measure(mininum distance) with splines in group.

$
0
0

Hellow, I'm beginer and studying NXopen VB now.
I'm looking for the method to meausre between plane and curves in group(ex spline x66) which were made by dynamic section. and find out the minimum distance with curve.
- Group "Dynamic section"
-Group "Mysection"
-Group "Body 1"
- Spline x 66
-Group "Body 2"
- Spline x 23

How can I get the Journalidentifier for each spline in group?
- splines are non associate line

Your prompt reply will be appreciated.

Thanks.

Create component array

$
0
0

Hi guys,

I would appreciate help with component array script. This function is not supported by journal recorder so it's little more complicated for me. I want to create two types of component circular array - with equal pitch and with differential (variable) pitch. Function part of script is below.

'------------------------------------------------------------------------------
'Define component pattern
'------------------------------------------------------------------------------
Dim ComponentPatternNull As Assemblies.ComponentPattern = Nothing
Dim ComponentPatternBuilder1 As Assemblies.ComponentPatternBuilder
ComponentPatternBuilder1 = workPart.ComponentAssembly.CreateComponentPatternBuilder(ComponentPatternNull)
 
ComponentPatternBuilder1.PatternService.PatternType = GeometricUtilities.PatternDefinition.PatternEnum.Circular
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.NCopies.RightHandSide = "ZNP_mill"
 
 
'------------------------------------------------------------------------------
'Make component pattern
'------------------------------------------------------------------------------
 
Dim AddedComponents As Boolean
For Each SelectedComponents As TaggedObject In Components0
AddedComponents = ComponentPatternBuilder1.ComponentPatternSet.Add(SelectedComponents)
Next SelectedComponents
 
ComponentPatternBuilder1.PatternService.CircularDefinition.RotationAxis = axis1
 
If DiffPitchActive0 = False Then
 
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.PitchAngle.RightHandSide = "360/ZNP_mill"
 
 
Else
 
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpaceType = GeometricUtilities.PatternSpacing.SpacingType.List
 
Dim componentPatternSpacingsListItem1 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem1 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem1)
componentPatternSpacingsListItem1.SpacingExpression.RightHandSide = "DP_ANG1"
 
Dim componentPatternSpacingsListItem2 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem2 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem2)
componentPatternSpacingsListItem2.SpacingExpression.RightHandSide = "DP_ANG2"
 
Dim componentPatternSpacingsListItem3 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem3 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem3)
componentPatternSpacingsListItem3.SpacingExpression.RightHandSide = "DP_ANG3"
 
Dim componentPatternSpacingsListItem4 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem4 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem4)
componentPatternSpacingsListItem4.SpacingExpression.RightHandSide = "DP_ANG4"	
 
Dim componentPatternSpacingsListItem5 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem5 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem5)
componentPatternSpacingsListItem5.SpacingExpression.RightHandSide = "DP_ANG5"			
 
Dim componentPatternSpacingsListItem6 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem6 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem6)
componentPatternSpacingsListItem6.SpacingExpression.RightHandSide = "DP_ANG6"
 
Dim componentPatternSpacingsListItem7 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem7 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem7)
componentPatternSpacingsListItem7.SpacingExpression.RightHandSide = "DP_ANG7"
 
Dim componentPatternSpacingsListItem8 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem8 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem8)
componentPatternSpacingsListItem8.SpacingExpression.RightHandSide = "DP_ANG8"
 
Dim componentPatternSpacingsListItem9 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem9 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem9)
componentPatternSpacingsListItem9.SpacingExpression.RightHandSide = "DP_ANG9"
 
Dim componentPatternSpacingsListItem10 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem10 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem10)
componentPatternSpacingsListItem10.SpacingExpression.RightHandSide = "DP_ANG10"
 
Dim componentPatternSpacingsListItem11 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem11 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem11)
componentPatternSpacingsListItem11.SpacingExpression.RightHandSide = "DP_ANG11"
 
Dim componentPatternSpacingsListItem12 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem12 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem12)
componentPatternSpacingsListItem12.SpacingExpression.RightHandSide = "DP_ANG12"
 
Dim componentPatternSpacingsListItem13 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem13 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem13)
componentPatternSpacingsListItem13.SpacingExpression.RightHandSide = "DP_ANG13"
 
Dim componentPatternSpacingsListItem14 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem14 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem14)
componentPatternSpacingsListItem14.SpacingExpression.RightHandSide = "DP_ANG14"
 
Dim componentPatternSpacingsListItem15 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem15 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem15)
componentPatternSpacingsListItem15.SpacingExpression.RightHandSide = "DP_ANG15"
 
Dim componentPatternSpacingsListItem16 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem16 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem16)
componentPatternSpacingsListItem16.SpacingExpression.RightHandSide = "DP_ANG16"
 
Dim componentPatternSpacingsListItem17 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem17 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem17)
componentPatternSpacingsListItem17.SpacingExpression.RightHandSide = "DP_ANG17"	
 
Dim componentPatternSpacingsListItem18 As GeometricUtilities.PatternSpacingsListItem
componentPatternSpacingsListItem18 = ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.CreatePatternSpacingsListItem()
ComponentPatternBuilder1.PatternService.CircularDefinition.AngularSpacing.SpacingsList.List.Append(componentPatternSpacingsListItem18)
componentPatternSpacingsListItem18.SpacingExpression.RightHandSide = "DP_ANG18"	
 
End If
 
nXObject1 = ComponentPatternBuilder1.Commit()
ComponentPatternBuilder1.Destroy()

Unfortunately, I have two problems with it:

1) Script creates component array without name, so when I check Assemblies->Components->Edit Component Array there is no array to edit. I suppose, that I have to set name somehow during creation of array, but how?

2) I case of differential pitch when I want to create array (count = ZNP_mill and angles according to expressions DP_ANG1-18) I use pattern spacing type = List, but it doesn't work. Script creates some array, but with equal 10° angle instead of variable angles according to expressions DP_ANGxx. It looks like component pattern builder is controlled by default setting for PatternService.CircularDefinition.AngularSpacing.PitchAngle.Value and not by PatternService.CircularDefinition.AngularSpacing.SpacingsList.

Selection external surface

$
0
0

Hello

Is there a method to select all external surfaces of a part / assembly?

At the moment i use a journal where i rotate the displayed part in different views and grab the visible faces. Often there are interferences / undercuts that are not selected properly. Is there a better selection method than mine or even a possibility to check whether surfaces are external?

Thank you and best regards

Date and Time

$
0
0

Below is part of a Program that is putting my date in as when the program was made thru NX, Is there something here that I can replace to make the time current of when the Program was ran.

attributePropertiesBuilder5.DateValue.DateItem.Day = DateItemBuilder.DayOfMonth.Day25

attributePropertiesBuilder5.DateValue.DateItem.Month = DateItemBuilder.MonthOfYear.Oct

attributePropertiesBuilder5.DateValue.DateItem.Year = "2017"

attributePropertiesBuilder5.DateValue.DateItem.Time = "00:00:00"

I do not need the Time Just The Date.


Measure mininum distance for two SEW bodyies

$
0
0

I'm studying the measure method for two SEW bodies. but there is error.
Who can please help me?
The goal is to measure the minimum distance between two SEW bodies.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module Module12222

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim obj1 As TaggedObject
Dim obj2 As TaggedObject

Dim guess1(2) As Double
Dim guess2(2) As Double
Dim pt1(2) As Double
Dim pt2(2) As Double
Dim minDist As Double

Dim body1 As Features.Feature = CType(workPart.Features.FindObject("SEW(274)"), Features.Feature)
obj1 = body1

Dim body2 As Features.Feature = CType(workPart.Features.FindObject("SEW(275)"), Features.Feature)
obj2 = body2
theUfSession.Modl.AskMinimumDist(obj1.Tag, obj2.Tag, 0, guess1, 0, guess2, minDist, pt1, pt2)
lw.Open()
lw.WriteLine("minimum distance: "& minDist.ToString)

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

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Thanks.

JOURNAL TO CREATE MULTIPLE OFFSET MIDSURFACES

Associating multiple Views with respectively displayed Bodies

$
0
0

Hello everyone,

This is my first post although using this page as source for solutions to many of my problems.

I have the following Problem and am currently looking for a way to solve it:
I have multiple DItems (Drawings) in NX opened and loaded concurrently.
Each has a various amount of Views.
Each View displays a certain amount of bodies, which should all have an attribute "x" with the same value.
I intend to check, whether the displayed bodies in each View have the correct value(the name of the view) and if the number of bodies in said View is correct. I use Check-Mate to get tags for all bodies available

mqc_askEntitiesInLayer(mqc_parseLayerStrings( { "1" }, "-"),SOLID_BODY,true);

This is forwarded to Visual Basic code and stored in a List(Of Body), resulting in all loaded parts bodies concatenated into one list.

I get all Views using following code:

PublicFunction GetAllPartsViews(ByVal parts As PartCollection)As List(Of View)
        GetAllPartsViews =New List(Of View) 
        ForEach part As Part In parts
            Dim partViews As ViewCollection
            partViews = part.Views 
            ForEach view As View In partViews
                GetAllPartsViews.Add(view)NextNextEndFunction

For the next step I need to know which bodies are displayed in which View. I found the function  View.AskVisibleObjects(), but this can only be used, if the View is the current WorkView. As there is no View.Bodies or Body.Views I struggle with finding a way to associate the two.

label on parent

$
0
0

Hello there,
On drawing I need to write a code of how to select just the label on parent. The drawing note appears as a label on the page when TYPE / PLAIN is added and reflects all the changes for the label on parent view. Is there a way to separate them?

How to select all the sketches in one go

$
0
0

I have to make a journal which works like when I give it a run,
it automatically detects all the sketches and planes in the part navigator and asks to which layer these components should be moved in.

Like if you want to move all sketches in layer 10, then you have to write 10 in the program interface.
Similarly if you want to move all planes in some other layer (in same program) it can be done in one go.

Add textbox in Block UI Styler

$
0
0

I create a user form using Block UI Styler that has one double and one integer( two textboxes) then I exit the Block UI Styler.

Now I need to add one extra textbox to the same UI Styler.How do I re-open the same UI from NX so that I could add in the same design?

Regards,

How to distinguish SymbolicThread arc from other curves?

$
0
0

Hi!
For example I have a linked body with curves of symbolic thread. By a right button of mouse i do open Arc Properties menu, and at the General tab, i can see Feature Name: Symbolic Thread.
How programmatically to determine that this arc is a Symbolic Thread curve?
Arc.Name is blank, curve.Type is Arc - it dont helped me..


NXOpen.Matrix3x3 order

$
0
0

Hi everyone,

can you guys help me with the order of the NXOpen.Matrix3x3?

is it

xx xy xz
yx yy yz
zx zy zz

or

xx yx zx
xy yy zy
xz yz zz

?

I couldn't find any helpful information.

Thanks!

New file for drafting the Layer should be set a 100 working layer

$
0
0

Hello Experts

Good morning

Its possible to set a default layer for new file for drafting.
User will open drafting for create new file,i want working sheet should be in 100 layer.

Thank you
Reagrds
Naveen

Python intellisense

$
0
0

Hello everyone.

Anyone figured out how to use NXopen python APIs with auto complete?
How to set up visual studio, or pycharm or some other software to use APIs.

Visual studio would be the best choice, as it works great for VB.

Move component

$
0
0

When i try to use the code below to move or copy a component in an assembly,i will get an error message :
"Some or all selected objects were not transformed. Review limitations and check input."
Does anyone know what i did wrong?
Thank you!

Imports NXOpen
 
PublicClass MyProgram
 
    PublicSharedSub Main() 
        Dim theSession As Session = Session.GetSession()Dim lw As ListingWindow = theSession.ListingWindowDim selectedobj = Snap.UI.Selection.SelectObject("Select")
        selectedobj.AllowMultiple=True
        selectedobj.SetFilter(Snap.NX.ObjectTypes.Type.Component)
        selectedobj.Title="Select components"Dim selectcom, trans As Snap.NX.ComponentDim result As Snap.UI.Selection.Result= selectedobj.Show()If result.Response<> Snap.UI.Response.CancelAndAlso result.Response<> Snap.UI.Response.BackThenDim p = Snap.UI.Input.GetPosition("", "").PositionIf IsNothing(p)=FalseThenDim isCopy = Snap.UI.Input.GetChoice({"Move", "Copy"}, "", "", "", Snap.UI.Block.EnumPresentationStyle.RadioBox)Dim isCopyBool =CBool(isCopy)Dim xform As Snap.Geom.Transform= Snap.Geom.Transform.CreateTranslation(p.X, p.Y, p.Z)'For Each obj As Snap.NX.NXObject In result.Objects'    Try'        If isCopyBool Then'            selectcom = CType(obj, Snap.NX.Component)'            trans = selectcom.Copy(xform)''        Else'            selectcom = CType(obj, Snap.NX.Component)'            selectcom.Move(xform)'        End If'    Catch ex As Exception'        lw.WriteLine(ex.Message)'    End Try'    NextTry
                    selectcom =CType(result.Objects(0), Snap.NX.Component)
                    trans = selectcom.Copy(xform)Catch ex As Exception
                    lw.WriteLine(ex.Message)EndTryEndIfEndIfEndSub 
EndClass

Listing Window

$
0
0

Hello there,
I can excel the zone regions of datum feature symbols on the drawing page with the following journal. As an example DATUME is like on C5 on the page but I want to see this information in the listing window too. so I want to see the window instead of excel. How can I help you how to do it?

' VBA Script to extract all the dimensions in an NX part file to an MS Excel Spreadsheet.
' The details extracted are:

' Sheet No. | Zone | Description\Measurement Direction |

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations

Module ExportDimensionsAndAnnotations
'Declare global variables
Dim theSession as Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession

Sub Main()
' First read the active part file from NX.
' Then, loop through the sheets.
' Then, loop through the dimensions in the sheet
' Grab the zone, text, tolerance type, tolerance and the measurement direction for each.
' Grab the nearest annotation in that zone.
' Build an array or a dictionary (similar to JSON or Python's Dictionary class)
' Then, loop through the text in the document, and do the same steps, except for those that are inapplicable, of course.
' Ask for a savefile location.
' Create an Excel file in that location
' Open the Excel file.
' Write array to the excel file.

If IsNothing(theSession.Parts.Work) Then 'Error handling
MsgBox("This code requires an active part. Please open a drawing first and then try again.")
Exit Sub
End If
Dim workPart as Part
workPart = theSession.Parts.Work

Dim theUISession as UI = UI.getUI
Dim saveFileName as String
Dim saveDialog as New System.Windows.Forms.SaveFileDialog
Dim objExcel as Object
Dim objWorkbook as Object
Dim excelFileExists as Boolean = False
Dim objWorksheet as Object
Dim colSheetNumber as Integer = 1
Dim colZone as Integer = 2
Dim colDescrMatlDir as Integer = 3

Dim valueSheetNumber as String
Dim valueZone as String
Dim valueDescrMatlDir as String
Dim rowNumber as Integer = 1

With saveDialog
.DefaultExt = "xlsx"
.FileName = "Datum_GD&T data"
.Filter = "MS Excel Spreadsheets (*.xlsx)|*.xlsx|All Files (*.*)|*.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Select a file where you'd like to save the exported data."
End With
saveDialog.ShowDialog()
saveFileName = saveDialog.FileName
If saveFileName ="Exported Data" Then
MsgBox("You failed to select a save file. Exitting the macro.")
Exit Sub
End If
objExcel = CreateObject("Excel.Application")
if objExcel is Nothing Then
theUISession.NXMessageBox.Show("Error", theUISession.NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
Exit Sub
End If
If File.Exists(saveFileName) Then
excelFileExists = True
objWorkbook = objExcel.Workbooks.Open(saveFileName)
objWorksheet = objWorkbook.Sheets.Add
Else
objWorkbook = objExcel.Workbooks.Add
objWorkbook.saveAs(saveFileName)
objWorksheet = objWorkbook.Sheets(1)
End If

objWorksheet.cells(rowNumber, colSheetNumber).Value = "Sheet Number"
objWorksheet.cells(rowNumber, colZone).Value = "Drawing Zone"
objWorksheet.cells(rowNumber, colDescrMatlDir).Value = "Description Text \ Measurement Direction"

Dim theSheet as Drawings.DrawingSheet
For Each tempDim As Annotations.Gdt In workPart.Gdts
rowNumber = rowNumber + 1

theSheet = AskDrawingSheet(tempDim)
valueSheetNumber = getSheetNumber(theSheet).ToString
valueZone = getZone(theSheet, tempDim)

valueDescrMatlDir = tempDim.GetType.ToString
' Clean up the material direction.
valueDescrMatlDir = Replace(valueDescrMatlDir, "NXOpen.Annotations.","")

objWorksheet.cells(rowNumber, colSheetNumber).Value = valueSheetNumber
objWorksheet.cells(rowNumber, colZone).Value = valueZone
objWorksheet.cells(rowNumber, colDescrMatlDir).Value = valueDescrMatlDir
Next

For Each temp As Annotations.Gdt In workPart.Gdts

theSheet = AskDrawingSheet(temp)
valueSheetNumber = getSheetNumber(theSheet)
objWorksheet.cells(rowNumber, colSheetNumber).Value = valueSheetNumber
objWorksheet.cells(rowNumber, colZone).Value = getZone(theSheet, temp)

Next

objWorksheet.Columns("A:M").EntireColumn.AutoFit
objWorkbook.save()
objWorkbook.close()
objExcel.Quit()
objWorksheet = Nothing
objWorkbook = Nothing
objExcel = Nothing
MsgBox("Completed the extraction successfully! Check "& saveFileName & " for the data.")

End Sub

Function getSheetNumber(ByVal theSheet as Drawings.DrawingSheet) As String
' This function returns the number of a sheet given the DrawingSheet object.
Dim sheetNum as Integer
Dim theSheetBuilder as Drawings.DrawingSheetBuilder
theSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number
theSheetBuilder.Destroy()
Return sheetNum.ToString
End Function

Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet
Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUfSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUfSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUfSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUfSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUfSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

Function getZone(ByVal theSheet As Drawings.DrawingSheet, ByVal theAnnotation As Annotations.Annotation) As String
Dim borderBuilder As Drawings.BordersAndZonesBuilder
borderBuilder = theSession.Parts.Work.Drafting.BordersAndZonesObjects.CreateBordersAndZonesBuilder(theSheet.BordersAndZones)

Dim numHorizontalZones As Integer = (theSheet.Length - borderBuilder.LeftMargin - borderBuilder.RightMargin) / borderBuilder.HorizontalSize
Dim numVerticalZones As Integer = (theSheet.Height - borderBuilder.TopMargin - borderBuilder.BottomMargin) / borderBuilder.VerticalSize

'calculate zone wrt bottom left of drawing (ZoneOrigin.Topleft)
Dim Hcell As Double = (theAnnotation.AnnotationOrigin.X - borderBuilder.LeftMargin) / borderBuilder.HorizontalSize
Dim Vcell As Double = (theAnnotation.AnnotationOrigin.Y - borderBuilder.rightMargin) / borderBuilder.VerticalSize

Hcell = Math.Ceiling(Hcell)
Vcell = Math.Ceiling(Vcell)

Dim theZoneOrigin As Drawings.BordersAndZonesBuilder.ZoneOrigin = borderBuilder.Origin
borderBuilder.Destroy()

Dim verticalLetterNum As Integer
Dim verticalLetter As Char

Dim horizontalNum As Integer

If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.TopLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.Bottomleft Then
horizontalNum = Hcell
Else
'origin on left side
horizontalNum = numHorizontalZones - Hcell + 1
End If

If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.topright Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.bottomright Then
verticalLetterNum = Asc("A") + Vcell
verticalLetter = Chr(verticalLetterNum)

Else
'origin on the top
verticalLetterNum = Asc("A") + numVerticalZones - Vcell
verticalLetter = Chr(verticalLetterNum)

End If
Return verticalLetter & horizontalNum.ToString
End Function

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

Viewing all 784 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>