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

print data on journal and drafting page

$
0
0

hello,

Can we print the data we want to display in the journal window or in the listing window on the letterhead paper?
Example: Can we print this dataset on the datum drawing in the B13 zone field in the cell we want in the tabular note?


Measure Length Journal

$
0
0

I am trying to create a journal that will output the lengths of 28 lines in a sketch. My ideal would be that it creates a text file with the data but I could work with just the summary measure window.

I tried to record one a few times but the Measure / Length function does not work...

Any help would be greatly appreciated.

Working Layer set to 100

$
0
0

Hello Experts

I need macro for set the working layer as a 100.

User will open the new drawing file & user run the macro
macro need to set the working layer as a 100.

Default working sheet in 1 layer.

Thank you
Reagrds
Naveen

Create Motion Envelope in NX 11

$
0
0

Is there anyway that I can create motion envelope in NX 11 using the existing arrangements. or simply using the move component option. Currently we have the options in Kinematics and sequence, Which both won't be useful for us (We have 4 bar mechanism and lot of pivots). The arrangements we are using a different automation method which will move components based Csys to Csys to based on expression and a basic sketch (We avoid kinematics to save time.) This below code I created for assembly arrangement creation using sketch, expression, CSYS, Table and component groups (Kinematics taking too long for each time update it saves me like 95% of time than kinematics).

Option Strict Off
Imports System
Imports System.IOImports System.Windows.FormsImports System.DrawingImports System.Drawing.ImagingImports System.CollectionsImports System.Runtime.InteropServicesImports NXOpen
Imports NXOpen.GeometricUtilitiesImports NXOpen.UFImports NXOpen.AssembliesImports NXOpenUI
Imports System.Collections.Generic 
Module ArrangementUpdateNew
 
    Dim theSession As Session = Session.GetSession()Dim workPart As Part = theSession.Parts.WorkDim displayPart As Part = theSession.Parts.DisplayDim theUI As UI = UI.GetUIDim ufs As UFSession = UFSession.GetUFSessionDim lw As ListingWindow = theSession.ListingWindow 
 
    Sub Main()
        lw.Open()Dim i AsInteger=NothingDim j AsInteger=NothingDim k AsInteger=NothingDim ii AsInteger=NothingDim ij AsInteger=NothingDim ik AsInteger=NothingDim PrimeCsysList As List(Of CoordinateSystem)=New List(Of CoordinateSystem)Dim SecondaryCsysList As List(Of CoordinateSystem)=New List(Of CoordinateSystem)Dim GroupList As List(Of ComponentGroup)=New List(Of ComponentGroup)Dim FromOrigin()AsDouble=NothingDim FromXAxis()AsDouble=NothingDim FromYAxis()AsDouble=NothingDim ArrangementTable As Tag =NothingDim Cellvalue AsString=NothingDim numRows AsInteger=NothingDim numCols AsInteger=NothingDim rowTag As Tag =NothingDim colTag As Tag =NothingDim cellTag As Tag =NothingDim ArrangementName AsString=NothingDim VariablesTitle As List(OfString)=New List(OfString)Dim DelArrangementList As List(Of Arrangement)=New List(Of Arrangement) 
        Dim DefArrangementTag As Tag =Nothing
        ufs.Assem.AskDefaultArrangement(workPart.Tag, DefArrangementTag)Dim DefArrangement As Arrangement = Utilities.NXObjectManager.Get(DefArrangementTag)Dim Resp As MsgBoxResult =Nothing
        Resp =MsgBox("Default Arrangement is '"& DefArrangement.Name& _
               "' , Press Yes to continue the update or Press No to Exit", vbYesNo, "Default Arrangement")If Resp = MsgBoxResult.NoThenExitSubElseIf Resp = MsgBoxResult.YesThen'Delete all the existiing Arrangement in workpartForEach DelArrangment As Arrangement In workPart.ComponentAssembly.ArrangementsIfNot DelArrangment.Name= DefArrangement.NameThen
                    DelArrangementList.Add(DelArrangment)EndIfNextFor i =0To DelArrangementList.Count-1
                DelArrangementList(i).Delete(True)NextEndIf 
        Dim PartClean As PartCleanup
        PartClean = theSession.NewPartCleanup()
        PartClean.TurnOffHighlighting=True
        PartClean.DeleteUnusedObjects=True
        PartClean.DeleteUnusedExpressions=True
        PartClean.CleanupDraftingObjects=True
        PartClean.CleanupFeatureData=True
        PartClean.FixOffplaneSketchCurves=True
        PartClean.DeleteInvalidAttributes=True
        PartClean.CleanupMatingData=True
        PartClean.CleanupAssemblyConstraints=True
        PartClean.DeleteUnusedFonts=True
        PartClean.CleanupCAMObjects=True
        PartClean.DeleteBrokenInterpartLinks=True
        PartClean.CleanupRoutingData=True
        PartClean.CleanupFeatureData=True
        PartClean.DeleteVisualEditorData=True
        PartClean.DoCleanup()
        PartClean.DoCleanup()
        PartClean.DoCleanup()
        PartClean.Dispose() 
        'ArrangementOptions.IndividuallyPositioned and Position override for each assembliesTryDim Mycomponent As ComponentAssembly = workPart.ComponentAssembly
            UpdateArrangementPosition(Mycomponent.RootComponent, 0)Catch e As Exception
            lw.WriteLine("Assembly component Individually Postitioned Option failed : "& e.ToString)EndTry 
        TryDim Mycomponent As ComponentAssembly = workPart.ComponentAssemblyDim MyHideList As List(Of Component)=New List(Of Component)
            ComponentHide(Mycomponent.RootComponent, 0, MyHideList)Dim MyHideObj()As DisplayableObject = MyHideList.ToArray
            theSession.DisplayManager.BlankObjects(MyHideObj)
            workPart.ModelingViews.WorkView.FitAfterShowOrHide(NXOpen.View.ShowOrHideType.HideOnly)Catch ex As NXException
            lw.WriteLine("error 110")EndTry 
        'Collect all Component group detail and Template coordinate system detailsForEach Mygroup As ComponentGroup In workPart.ComponentGroupsIfTypeOf Mygroup Is ComponentGroup Then
                GroupList.Add(Mygroup)EndIfNext 
        ForEach MyCsys As CoordinateSystem In workPart.CoordinateSystemsIfTypeOf MyCsys Is CoordinateSystem ThenIfNot MyCsys.Name=""Then
                    PrimeCsysList.Add(MyCsys)EndIfEndIfNext 
        'Collect all the Details from Primary CSYS before applying the formula or Else for both Primary and secondary Csys will return the same valueDim FromOriginX AsDouble=NothingDim FromOriginY AsDouble=NothingDim FromOriginZ AsDouble=NothingDim FromOriginXx AsDouble=NothingDim FromOriginXy AsDouble=NothingDim FromOriginXz AsDouble=NothingDim FromOriginYx AsDouble=NothingDim FromOriginYy AsDouble=NothingDim FromOriginYz AsDouble=NothingDim Xcollection As List(OfDouble)=New List(OfDouble)Dim Ycollection As List(OfDouble)=New List(OfDouble)Dim Zcollection As List(OfDouble)=New List(OfDouble)Dim Xxcollection As List(OfDouble)=New List(OfDouble)Dim Xycollection As List(OfDouble)=New List(OfDouble)Dim Xzcollection As List(OfDouble)=New List(OfDouble)Dim Yxcollection As List(OfDouble)=New List(OfDouble)Dim Yycollection As List(OfDouble)=New List(OfDouble)Dim Yzcollection As List(OfDouble)=New List(OfDouble) 
        For i =0To PrimeCsysList.Count-1
            FromOriginX = PrimeCsysList(i).Origin.X
            FromOriginY = PrimeCsysList(i).Origin.Y
            FromOriginZ = PrimeCsysList(i).Origin.Z
            FromOriginXx = PrimeCsysList(i).Orientation.Element.Xx
            FromOriginXy = PrimeCsysList(i).Orientation.Element.Xy
            FromOriginXz = PrimeCsysList(i).Orientation.Element.Xz
            FromOriginYx = PrimeCsysList(i).Orientation.Element.Yx
            FromOriginYy = PrimeCsysList(i).Orientation.Element.Yy
            FromOriginYz = PrimeCsysList(i).Orientation.Element.Yz
            Xcollection.Add(FromOriginX)
            Ycollection.Add(FromOriginY)
            Zcollection.Add(FromOriginZ)
            Xxcollection.Add(FromOriginXx)
            Xycollection.Add(FromOriginXy)
            Xzcollection.Add(FromOriginXz)
            Yxcollection.Add(FromOriginYx)
            Yycollection.Add(FromOriginYy)
            Yzcollection.Add(FromOriginYz)Next 
        ' Read expression value from table for each arrangement and update the sketch to move the coordinates and update arrangementDim myTabularNoteTags AsNew List(Of Tag)If FindTabularNotes(myTabularNoteTags, workPart)=0Then'no tabular notes to processReturnEndIf 
        ForEach tableNote As Tag In myTabularNoteTags
            ufs.Tabnot.AskNmRows(tableNote, numRows)
            ufs.Tabnot.AskNmColumns(tableNote, numCols)
            ufs.Tabnot.AskNthRow(tableNote, 0, rowTag)
            ufs.Tabnot.AskNthColumn(tableNote, 0, colTag)
            ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
            ufs.Tabnot.AskCellText(cellTag, Cellvalue) 
            If Cellvalue ="Arrangements list"Then
                ufs.Tabnot.AskNthRow(tableNote, 1, rowTag)For j =1To numCols -1
                    ufs.Tabnot.AskNthColumn(tableNote, j, colTag)
                    ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
                    ufs.Tabnot.AskCellText(cellTag, Cellvalue)
                    VariablesTitle.Add(Cellvalue)Next 
                For i =2To numRows -1Step1
                    ufs.Tabnot.AskNthRow(tableNote, i, rowTag)Dim Variables As List(OfString)=New List(OfString)For j =0To numCols -1
                        ufs.Tabnot.AskNthColumn(tableNote, j, colTag)
                        ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
                        ufs.Tabnot.AskCellText(cellTag, Cellvalue)
                        Variables.Add(Cellvalue)Next 
                    ArrangementName = Variables(0)Dim MyArrangement As Assemblies.Arrangement=Nothing
                    MyArrangement = workPart.ComponentAssembly.Arrangements.Create(DefArrangement, ArrangementName)
                    lw.WriteLine("Creating "& ArrangementName.ToString)
                    MyArrangement.IgnoringConstraints=True
                    workPart.ComponentAssembly.RootComponent.SetUsedArrangement(MyArrangement)
                    workPart.ComponentAssembly.ActiveArrangement= MyArrangement
                    Variables.RemoveAt(0) 
                    For iii AsInteger=0To Variables.Count-1If Variables(iii).ToString="NA"Then
                            Variables(iii)="0"EndIfNext 
                    If VariablesTitle.Count= Variables.CountThenFor k =0To VariablesTitle.Count-1Try'This expression will move the base sketch and move the coordinate system to new locationDim markId1 As Session.UndoMarkId
                                markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Expression") 
                                Dim expression1 As Expression =CType(workPart.Expressions.FindObject(VariablesTitle(k)), Expression)
                                expression1.RightHandSide= Variables(k)
                                theSession.Preferences.Modeling.UpdateDelayed=True
                                theSession.Preferences.Modeling.UpdatePending=True 
                                Dim nErrs1 AsInteger
                                nErrs1 = theSession.UpdateManager.DoUpdate(markId1) 
                            Catch ex As NXException
                                lw.WriteLine(VariablesTitle(k)&":  "& ex.Message)EndTry 
                        Next 
                        ForEach MyCsys As CoordinateSystem In workPart.CoordinateSystems 
                            IfTypeOf MyCsys Is CoordinateSystem ThenIfNot MyCsys.Name=""Then
                                    SecondaryCsysList.Add(MyCsys)EndIfEndIfNext 
 
 
                        For ii =0To PrimeCsysList.Count-1Dim Movinggroup As ComponentGroup =NothingDim fromCsys As CoordinateSystem = PrimeCsysList(ii) 
                            FromOrigin ={Xcollection(ii), Ycollection(ii), Zcollection(ii)}
                            FromXAxis ={Xxcollection(ii), Xycollection(ii), Xzcollection(ii)}
                            FromYAxis ={Yxcollection(ii), Yycollection(ii), Yzcollection(ii)}'Comparing Dim toCsys As CoordinateSystem =NothingFor ij =0To SecondaryCsysList.Count-1If SecondaryCsysList(ij).Name= fromCsys.NameThen
                                    toCsys = SecondaryCsysList(ij)EndIfNext 
                            Dim toOrigin()AsDouble={toCsys.Origin.X, toCsys.Origin.Y, toCsys.Origin.Z}Dim toXAxis()AsDouble={toCsys.Orientation.Element.Xx, toCsys.Orientation.Element.Xy, toCsys.Orientation.Element.Xz}Dim toYAxis()AsDouble={toCsys.Orientation.Element.Yx, toCsys.Orientation.Element.Yy, toCsys.Orientation.Element.Yz} 
                            Dim mtx4Transform(15)AsDouble 
                            ufs.Mtx4.CsysToCsys(FromOrigin, FromXAxis, FromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform) 
                            'Extract the rotation matrix and the tranlsation vectorDim rotMatrix(8)AsDouble
                            ufs.Mtx4.AskRotation(mtx4Transform, rotMatrix)Dim transVec(2)AsDouble
                            ufs.Mtx4.AskTranslation(mtx4Transform, transVec) 
                            'Convert array of doubles to vector 3dDim translateVector As Vector3d =New Vector3d(transVec(0), transVec(1), transVec(2))'Convert array of doubles to Matrix3x3Dim rotationMatrix As Matrix3x3 = convertToMatrix3x3(rotMatrix) 
                            'Find which component group to move based on PrimarycsysDim Groupobjects()As NXObject =NothingTryFor ik =1To GroupList.Count-1If GroupList(ik).Name= fromCsys.NameThen
                                        Movinggroup = GroupList(ik)
                                        Groupobjects = Movinggroup.GetComponents'lw.WriteLine(Movinggroup.Name & ": Components Count: " & Groupobjects.Length.ToString)EndIfNextCatch ex As Exception
                                lw.WriteLine(ex.Message)GoTo NextGroup
                            EndTryTry'Move groups for each arrangement as per Primary to Secondary Csys moveDim componentPositioner1 As Positioning.ComponentPositioner
                                componentPositioner1 = workPart.ComponentAssembly.Positioner
                                componentPositioner1.ClearNetwork()
                                componentPositioner1.BeginMoveComponent()
                                componentPositioner1.PrimaryArrangement()= MyArrangement
                                Dim allowInterpartPositioning1 AsBoolean
                                allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioningDim network1 As Positioning.Network
                                network1 = componentPositioner1.EstablishNetwork()Dim componentNetwork1 As Positioning.ComponentNetwork=CType(network1, Positioning.ComponentNetwork)
                                componentNetwork1.NonMovingGroupGrounded=True
                                componentNetwork1.MoveObjectsState=True
                                componentNetwork1.RemoveAllConstraints()
                                componentNetwork1.SetMovingGroup(Groupobjects)Dim loaded1 AsBoolean
                                loaded1 = componentNetwork1.IsReferencedGeometryLoaded()
                                componentNetwork1.BeginDrag()
                                componentNetwork1.DragByTransform(translateVector, rotationMatrix)
                                componentNetwork1.EndDrag()
                                componentNetwork1.ResetDisplay()
                                componentNetwork1.ApplyToModel()
                                componentNetwork1.Solve()
                                componentPositioner1.ClearNetwork()Dim nErrs2 AsInteger
                                nErrs2 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
                                componentPositioner1.DeleteNonPersistentConstraints()
                                componentPositioner1.EndMoveComponent()Catch ex As NXException
                                lw.WriteLine(ex.Message)GoTo NextGroup
                            EndTry
NextGroup:
                        Next 
                    Else
                        lw.WriteLine("Table has missing Parameters or Parameter Title count and Value count not matching")EndIfNext 
            EndIfNext 
        workPart.ComponentAssembly.RootComponent.SetUsedArrangement(DefArrangement)
        workPart.ComponentAssembly.ActiveArrangement= DefArrangement
 
        Dim NewArrangementsList As List(Of Arrangement)=New List(Of Arrangement)ForEach NewArrangment As Arrangement In workPart.ComponentAssembly.ArrangementsIfNot NewArrangment.Name= DefArrangement.NameThen
                NewArrangementsList.Add(NewArrangment)EndIfNext 
        TryDim SuppressGroup As ComponentGroup =CType(workPart.ComponentGroups.FindObject("SUPPRESSED"), ComponentGroup)Dim ArrangementListForSuppress()As Arrangement = NewArrangementsList.ToArrayDim errorList1 As ErrorList
            errorList1 = workPart.ComponentAssembly.SuppressComponents(SuppressGroup.GetComponents, ArrangementListForSuppress)
            errorList1.Dispose()Catch ex As NXException
            lw.WriteLine("Suppress: "& ex.Message)EndTry 
        TryDim Mycomponent As ComponentAssembly = workPart.ComponentAssemblyDim MyHideList As List(Of Component)=New List(Of Component)
            ComponentHide(Mycomponent.RootComponent, 0, MyHideList)Dim MyHideObj()As DisplayableObject = MyHideList.ToArray
            theSession.DisplayManager.UnblankObjects(MyHideObj)
            workPart.ModelingViews.WorkView.FitAfterShowOrHide(NXOpen.View.ShowOrHideType.ShowOnly)Catch ex As NXException
            lw.WriteLine("error 366")EndTry 
    EndSub 
    Function convertToMatrix3x3(ByVal mtx AsDouble())As Matrix3x3
        Dim mx As Matrix3x3
        With mx
            .Xx= mtx(0).Xy= mtx(1).Xz= mtx(2).Yx= mtx(3).Yy= mtx(4).Yz= mtx(5).Zx= mtx(6).Zy= mtx(7).Zz= mtx(8)EndWith 
        Return mx
 
    EndFunctionFunction FindTabularNotes(ByRef theTabNotes As List(Of Tag), ByVal Mypart As Part)AsInteger 
        Dim tmpTabNote As NXOpen.Tag= NXOpen.Tag.NullDim type AsIntegerDim subtype AsInteger 
        Do
            ufs.Obj.CycleObjsInPart(Mypart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)If tmpTabNote = NXOpen.Tag.NullThenContinueDoEndIfIf tmpTabNote <> NXOpen.Tag.NullThen
                ufs.Obj.AskTypeAndSubtype(tmpTabNote, type, subtype)If subtype = UFConstants.UF_tabular_note_subtypeThen
                    theTabNotes.Add(tmpTabNote)EndIfEndIfLoop Until tmpTabNote = NXOpen.Tag.NullReturn theTabNotes.Count 
    EndFunction 
    Sub UpdateArrangementPosition(ByVal comp As Component, ByVal indent AsInteger) 
        ForEach child As Component In comp.GetChildren()If child.GetChildren.Length<>0Then' lw.WriteLine(child.Name)TryDim nullAssemblies_Component As Assemblies.Component=Nothing
                    child.EstablishPositionOverride(nullAssemblies_Component)Dim MyObj(0)As NXObject
                    MyObj(0)= child
                    Dim assembliesParameterPropertiesBuilder1 As AssembliesParameterPropertiesBuilder = workPart.PropertiesManager.CreateAssembliesParameterPropertiesBuilder(MyObj)
                    assembliesParameterPropertiesBuilder1.Arrangements= Assemblies.AssembliesParameterPropertiesBuilder.ArrangementOptions.IndividuallyPositionedDim NxObject1 As NXObject
                    NxObject1 = assembliesParameterPropertiesBuilder1.Commit()
                    assembliesParameterPropertiesBuilder1.Destroy()Catch ex As NXException
                    lw.WriteLine("Failed To Position Override")EndTryElseTryDim nullAssemblies_Component As Assemblies.Component=Nothing
                    child.EstablishPositionOverride(nullAssemblies_Component)IfNot child.GetPositionOverrideType.ToString()="Explicit"Then
                        child.EstablishPositionOverride(nullAssemblies_Component)EndIfDim MyObj(0)As NXObject
                    MyObj(0)= child
                    Dim assembliesParameterPropertiesBuilder1 As AssembliesParameterPropertiesBuilder = workPart.PropertiesManager.CreateAssembliesParameterPropertiesBuilder(MyObj)
                    assembliesParameterPropertiesBuilder1.Arrangements= Assemblies.AssembliesParameterPropertiesBuilder.ArrangementOptions.IndividuallyPositionedDim NxObject1 As NXObject
                    NxObject1 = assembliesParameterPropertiesBuilder1.Commit()
                    assembliesParameterPropertiesBuilder1.Destroy()Catch ex As NXException
                    lw.WriteLine("Failed To Position Override")EndTryEndIf
            UpdateArrangementPosition(child, indent +1)NextEndSub 
    Sub ComponentHide(ByVal comp As Component, ByVal indent AsInteger, ByRef Hidelist As List(Of Component)) 
        ForEach child As Component In comp.GetChildren()If child.GetChildren.Length<>0Then' lw.WriteLine(child.Name)Try
                    Hidelist.Add(child)Catch ex As NXException
                EndTryElseTry
                    Hidelist.Add(child)Catch ex As NXException
                EndTryEndIf
            ComponentHide(child, indent +1, Hidelist)NextEndSub 
    PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately 
    EndFunctionEndModule

Open Latest Revision of a Part from TcE

$
0
0

Is there anything wrong in following Method I am trying, I am not getting any output with this. *I am using NX 11.

Dim PartNo AsString="XXXXX"Dim Parttag As Tag =Nothing
            ufs.Ugmgr.AskPartTag(PartNo, Parttag)Dim RevCount AsInteger=NothingDim RevisionsTag()As Tag =NothingDim LatestRevision AsString=Nothing 
            If Parttag <> NXOpen.Tag.NullThen
                ufs.Ugmgr.ListPartRevisions(Parttag, RevCount, RevisionsTag)
                ufs.Ugmgr.AskPartRevisionId(RevisionsTag(UBound(RevisionsTag)), LatestRevision)Else
                lw.WriteLine(PartNo &": Unable to Open the Correct Revision of the Part")EndIfMsgBox(LatestRevision)
            theSession.Parts.SetNonmasterSeedPartData("@DB/"& PartNo &"/"& LatestRevision)Dim basePart1 As BasePart =NothingTryDim partLoadStatus1 As PartLoadStatus =Nothing
                basePart1 = theSession.Parts.Open("@DB/"& PartNo, partLoadStatus1)
                partLoadStatus1.Dispose()Dim partLoadStatus2 As PartLoadStatus =NothingDim status1 As PartCollection.SdpsStatus
                status1 = theSession.Parts.SetDisplay(basePart1, False, True, partLoadStatus2)
                partLoadStatus2.Dispose()Catch exc As NXException
                lw.WriteLine(exc.Message)EndTry

datum feature symbol

Multiplication

$
0
0

Hello there,
I draft 3d poins belonging to the piece from the drafting page to the part corners as a journal note. But when I get these values, I want to multiply the value of axis "Y" by two. is there a way to add this to the code below?
Could you help me very urgently?

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpenUI
Imports NXOpen.UF

Module Comp_Name_xyzposition
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim wp As Part = s.Parts.Work()

Sub Main()
Dim mode1() As Integer = {0, 0}
Dim pointDisplayMode As Integer = 0
Dim response2 As Integer = Nothing
'Dim response1 As Integer = Nothing
Dim objectpoint(2) As Double
Dim text1(3) As String
Dim cursor As Point3d

Dim dwgview As Drawings.DraftingView = Nothing
select_a_drawing_member_view(dwgview)

Start0:

' Get number of decimal places to also determine xy lablel size
Dim decimalplaces As Integer=2

Start1:
dwgview.Expand()
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
response2 = ufs.Ui.PointSubfunction("Select Point for Label", mode1, pointDisplayMode, objectpoint)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
wp.Views.UnexpandWork()
'If response1 = 1 Then GoTo Start0
'If response1 = 2 Then GoTo End1

Dim response1 As Selection.DialogResponse = SelectScreenPos(cursor)
If response1 <> Selection.DialogResponse.Pick Then
Return
End If

Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing

Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = wp.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)

text1(1) = "X " + objectpoint(0).ToString("F"& decimalplaces.ToString)
text1(2) = "Y " + objectpoint(1).ToString("F"& decimalplaces.ToString)

draftingNoteBuilder1.Text.TextBlock.SetText(text1)

draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim coordinates1 As Point3d = New Point3d(objectpoint(0), objectpoint(1), objectpoint(2))

Dim assocOrigin1 As Annotations.Annotation.AssociativeOriginData
Dim nullView As View = Nothing

Dim point1 As Point3d = New Point3d(cursor.X, cursor.Y,0.0)
draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)

Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()

draftingNoteBuilder1.Destroy()

GoTo Start1
End1:

wp.Preferences.ObjectPreferences.SetWidth(Preferences.PartObject.ObjectType.General, Preferences.PartObject.WidthType.NormalWidth)
End Sub

Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse

Dim view As NXOpen.View = Nothing
Dim letteringPrefs As LetteringPreferences = Nothing
'Dim userSymPrefs As UserSymbolPreferences = Nothing

Return ui.SelectionManager.SelectScreenPosition("Select X Label Position", view, pos)

End Function

Function select_a_drawing_member_view(ByRef dwgview As Drawings.DraftingView)

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 View = Nothing

Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Select a drawing member view", _
"Select a drawing member view", _
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.cancel

End If

End Function

End Module

Adding custom note (aftertext) to dimensions

$
0
0

Hello everybody, first of all, thanks for many useful macros, lessons i've got from here.

I created a journal that add a custom aftertext to selected dimension.
But i am still not so able to aply journal to multiple selection.
Or even better to search for dimensions with any kind of tolerance and then apply to all of them the custom after text.

This is my current situation. Any help?

' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
Imports System
Imports NXOpen
 
Module NXJournal
Sub Main (ByVal args() As String) 
 
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()
 
Dim linearDimensionBuilder1 As NXOpen.Annotations.LinearDimensionBuilder = Nothing
 linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(CType(theUI.SelectionManager.GetSelectedTaggedObject(0), Annotations.Dimension))
 
'for each aftertext as string in linearDimensionBuilder1.appendedtext.getafter(0)
Dim text(0) As String
text(0) = "<&70><+>   <+><&90>"
linearDimensionBuilder1.AppendedText.SetAfter(text)
'next
 
Dim nXObject1 As NXOpen.NXObject = linearDimensionBuilder1.Commit()
linearDimensionBuilder1.Destroy()
 
End Sub
End Module

export excel

$
0
0

Hello there,
I am exporting nx excel data with the following code. This code is sorted from top to bottom, but I want to sort horizontally from left to right. I did not try but I could not. can you be a helper?

'Visual Basic Script to extract all the dimensions in an NX part file to 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 ()

If IsNothing (theSession.Parts.Work) Then 'Error handling
MsgBox ("This code requires an active part.
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 = 3
Dim colZone as Integer = 1
Dim colDescrMatlDir as Integer = 2

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

With saveDialog
.DefaultExt = "xlsx"
.FileName = & quot; Datum_GD & T data & quot;
.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. Exiting 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"

objworksheet.columns ( "A: Me"). entirecolumn.autofit
objworkbook.sav A ()
objworkbook.clos A ()
objexcel.quit ()
objWorksheet = Nothing
objWorkbook = Nothing
objExcel = Nothing
MsgBox ("Completed the extraction successfully! Check"& saveFileName & "for the data.")

End Sub

End Module

Subassy

$
0
0

i am struggling to get component at first level.

i have structure

Dwg
-Assy
-comp1
-comp2
-comp3
-subcomp1
-subsubcomp1
-subcomp2
-subcomp3
-comp4

through the associativity ia m able to get component, i need component at first level. suppose dimension is associated to subsubcomp1 i need comp3 as output & if it is comp2 then output will be comp2
I am struggling with recursuve here.
Thanks

spreadsheet excel

$
0
0

Hello there,
How do you write ROW or column data when you are exporting data with journal? I do not want to print the headers in the sub-subheadings to meet the information.

sample ;
datum A
zone B5
page_number 1

I want you to be on the excel page as above. but the data I get is as follows.

datum zone page_number
  A B5 1

This is what happens with the following code, but I do not want it.

can you help me?

'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 ()

If IsNothing (theSession.Parts.Work) Then 'Error handling
MsgBox ("This code requires an active part.
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 = 3
Dim colZone as Integer = 1
Dim colDescrMatlDir as Integer = 2

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

With saveDialog
.DefaultExt = "xlsx"
.FileName = & quot; Datum_GD & T data & quot;
.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. Exiting 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"

objworksheet.columns ( "A: M").entirecolumn.autofit
objworkbook.sav A ()
objworkbook.clos A ()
objexcel.quit ()
objWorksheet = Nothing
objWorkbook = Nothing
objExcel = Nothing
MsgBox ("Completed the extraction successfully! Check"& saveFileName & "for the data.")

End Sub

End Module

Get Created FacetedBody by Facet.STLImportBuilder

$
0
0

Hi Everybody,
I'm pretty new to NXopen API and I'm dealing with a problem using an Istance of workPart.FacetedBodies.CreateSTLImportBuilder() in order to import an .stl file in my part.
I haven't find example of this builder on forums and I can't understand how to obtain created FacetedBody, in order to set it's layer and color.

By the following code I can import the .stl file pointed by STLfileDIR, but using getObject I've the error that is not possible to cast the object to an Facet.FacetedBody ( and the same using a DisplayableObject)

Many thanks!

Public Sub ImportSTL()
 
Dim STLfileDIR As String = "/../"
Dim LayerSet As Integer = 99
 
Dim mySession As Session = Session.GetSession()
Dim workPart As Part = mySession.Parts.Work
Dim displayPart As Part = mySession.Parts.Display
 
Dim STLbuilder As Facet.STLImportBuilder
STLbuilder = workPart.FacetedBodies.CreateSTLImportBuilder()
STLbuilder.File = STLfileDIR
STLbuilder.AngularTolerance = Facet.STLImportBuilder.AngularToleranceTypes.Coarse
STLbuilder.FacetBodyType = Facet.STLImportBuilder.FacetBodyTypes.Nx
STLbuilder.STLFileUnits = Facet.STLImportBuilder.STLFileUnitsTypes.Millimeters
 
Dim nXObject1 As nxopen.NXobject
Dim facetedBody1 As Facet.FacetedBody
nXObject1 = STLbuilder.Commit()
facetedBody1 = STLbuilder.GetObject
STLbuilder.Destroy()
workPart.Layers.MoveDisplayableObjects(LayerSet, facetedBody1)
End Sub

CreateSmoothCurveStringBuilder

$
0
0

Hi,

I recorded a journal to smooth the curves. I used "Smooth Curve String" feature to smooth. The journal got recorded but when i tried to Play the journal, i am getting an error "License Error: License server system does not support this feature. [-18].

Can anyone help me to resolve?

Regards,

datum symbol letter

$
0
0

Hello there,
how can I export the letter of the data symbol to excel

DraftingDatum.Label)

draftingDatumFeatureSymbolBuilder1.Letter = "D"

Command to pause a Journal

$
0
0

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.UFImports NXOpen.UIImports NXOpen.UtilitiesImports System.IOImports System.Collections.GenericImports System.Windows.FormsImports System.Threading 
Module NXJournal
    Dim theSession As NXOpen.Session= NXOpen.Session.GetSession()Dim lw As ListingWindow = theSession.ListingWindowDim workPart As Part = theSession.Parts.WorkDim displayPart As Part = theSession.Parts.Display 
DeclareSub MACRO_playback_from_usertool Lib"libugui"Alias"?MACRO_playback_from_usertool@@YAXPEBD@Z"(ByVal lpName AsString)Sub Main (ByVal args()AsString) 
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 AsInteger=(drawingSheetBuilder1.Height)Dim length AsInteger=(drawingSheetBuilder1.Length) 
If(height=841)then 
MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A0_VW.macro") 
EndIf 
If(height=594)then 
MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A1_VW.macro") 
EndIf 
If(height=420)then 
MACRO_playback_from_usertool("O:\Documents\RPA\VW\Macros\A2_VW.macro") 
EndIf 
 
If(height=841)then 
Dim igesExportFileName AsString= displayPart.FullPath.Substring(0, displayPart.FullPath.Length-4)&"_A0.igs"Try       
		   ExportIges(displayPart, igesExportFileName) 
        Catch ex As Exception
            lw.WriteLine("Error: "& ex.Message)EndTry 
EndIf 
If(height=594)then 
Dim igesExportFileName AsString= displayPart.FullPath.Substring(0, displayPart.FullPath.Length-4)&"_A1.igs"Try
            ExportIges(displayPart, igesExportFileName) 
        Catch ex As Exception
            lw.WriteLine("Error: "& ex.Message)EndTry 
 
EndIf 
If(height=420)then 
Dim igesExportFileName AsString= displayPart.FullPath.Substring(0, displayPart.FullPath.Length-4)&"_A2.igs"Try
            ExportIges(displayPart, igesExportFileName) 
        Catch ex As Exception
            lw.WriteLine("Error: "& ex.Message)EndTry 
 
EndIf 
EndSub 
Sub ExportIges(ByVal partToExport As Part, ByVal exportFileName AsString) 
        Dim IGES_DIR AsString= theSession.GetEnvironmentVariableValue("IGES_DIR")Dim igesFile AsString
        igesFile = IO.Path.Combine(IGES_DIR, "igesexport.def") 
        IfNot IO.File.Exists(igesFile)ThenThrowNew Exception("igesexport.def file not found")ReturnElse'lw.WriteLine("IGES definition file found at: " & igesFile)EndIf 
        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" 
 
        EndWith 
        Dim nXObject2 As NXObject
        nXObject2 = igesCreator1.Commit() 
        igesCreator1.Destroy() 
                                theSession.CleanUpFacetedFacesAndEdges() 
 
    EndSub 
EndModule 
<vbnet>

Reset dropdown attribute to "NO VALUE"

$
0
0

Hello,

I have a NX template with a dropdown menue in the part properties. Once choosen Attributes demand a new value. If I try to set back an attribute, (write "" or "nothing" into it) will still keep the old value. I also tried to create a No Value Field.

Does anyone know how to set back an attribute permanently to the value: "No Value" ?

Thank you and best regards

Layer setting checklist for drawing file

$
0
0

Hi All

I am working on layer setting checklist for drawing file

User will run the macro,macro has to move the objects as per below mentioned requirements

datum feature = should be in 100th layer
balloon feature = should be in 101 layer
datum target = should be in 102 layer
surface symbol = should be in 103 layer
welding symbol = should be in 104 layer

I did for sketches and fcfs & notes its working fine
please support on other objects mentioned in above.

Thank you
Reagrds
patil

Remove all round faces / surfaces from the part / body

$
0
0

Hi, I was trying to remove all round/non planar faces from the body. There are no edge blend in the dumb solid part. But there are some round faces or fillet. Was trying to use below code. But I know it is wrong in below line:

 
If Not TypeOf (temp) Is NXOpen.Face Then 

I couldn't find a better way to select planar faces for nottype of . Anyone have any idea please?

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpenUI
 
Module NXJournal
    Sub Main(ByVal args() As String)
 
        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work
 
        Dim displayPart As NXOpen.Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
 
 
        ' ----------------------------------------------
        '   Menu: Edit->Delete...
        ' ----------------------------------------------
 
 
        Dim markId4 As Session.UndoMarkId
        markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "remove round and nonplaner faces")
 
        lw.Open()
 
        Dim Nonplanerfaces As New List(Of Face)
 
        For Each temp As NXOpen.Face In theSession.Parts.Work.Features
 
            If Not TypeOf (temp) Is NXOpen.Face Then
                'If TypeOf (temp) Is NXOpen.Features.EdgeBlend Then
                Nonplanerfaces.Add(temp)
            End If
        Next
 
        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(Nonplanerfaces.ToArray)
 
        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId4)
 
        lw.Close()
 
 
    End Sub
End Module

Select component (not .Highlight)

$
0
0

Hi,

we are trying to import component and immediately use move component command.

Move component is made by macro, it works if the any component is preselected.

The problem is selecting the componen in NXOpen.
We didn't have any success with SelectionManager and .Highlight is only visual representation...

Is it really impossible to select a component , so the .macro will recognize it?

Thank you

Enhanced selection limited between boundaries

$
0
0

Hello at all,

I was wondering whether it is possible to add a filter or something else for a selection to select all faces/lines or something else in a certain area/volume?

Or is it possible to simulate my mouse during a selection. I'm not a programmer, I hope I explained it well enough...

Best regards

Viewing all 783 articles
Browse latest View live


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