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

Delete Curve by Name in NX 11

$
0
0

Hello,

I am trying to delete curve by searching its name.
I have used below code and it is working in NX 9 and NX 10 but it is not working in NX 11.
Can anyone please help me to find my mistake ?

 Sub Main   
 
        theSession = Session.GetSession()
        workPart = theSession.Parts.Work
        displayPart = theSession.Parts.Display
        Dim Curves As CurveCollection = workPart.Curves
        Dim bodyname As String = Line
 
        For Each oCurve As Curve In Curves
 
            If oCurve.Name = bodyname Then
 
 
                Dim markId1 As Session.UndoMarkId
                markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")
                Dim notifyOnDelete1 As Boolean
                notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
                theSession.UpdateManager.ClearErrorList()
 
 
                Dim nErrs1 As Integer
                nErrs1 = theSession.UpdateManager.AddToDeleteList(oCurve)
 
                Dim nErrs2 As Integer
                nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
                theSession.DeleteUndoMark(markId1, Nothing)
 
 
            End If
        Next
    End Sub

Encrypt vb code and run inside NX

$
0
0

Hi All,

I am new here. I have a question that, can we encrypt vb code inside .vb file & run inside NX.?

I know that we can compile vb file into .dll & run in NX. But is there any option to encrypt vb file there by disallowing others to edit the code.

Thanks in Advance..

Journal to remove leaders from all balloons but selected

$
0
0

I'm currently looking for a way to have a journal remove the leaders from all the balloons on a drafting sheet besides ones that I have selected. I create stacked balloons so only one leader is required per stack. The idea would be to run the journal, select the balloons with leaders to be exempted, and have the leaders on all of the remaining balloons be removed.

Moving a plane surface to round figure dimension

$
0
0

Hello All,

Is it possible to make a plane surface in round figure by selecting a surface?

Example- As off now I am using a point to point move option to make plane surface round figure ( in 5mm multiple ).Hence it is required for machining purpose so is it possible to make journal which will move the plane surface to nearest round figure dimension ( in 5mm multiple).

User interaction while using revolve or other NX operation

$
0
0

Hi! My experience with programming is limited, especially creating nx journals is a fresh topic for me. However I am trying to use inside my journal a default operation, like revolve or extrude, with user interaction - I mean specifying all settings and applying. After applying the journal should execute next steps (similarly like 'user entry' during recording macro). I have found no help on the Internet about this topic, so I would be very grateful for some tips

Standalone NX Open Scripting from External Script Files

$
0
0

I have been stuck some time trying to interface NX Open via external scripts that I have written. Here is an explanation of what I am trying to do:

I am currently designing classes and subroutines (in python) to automate NX assembly models which can edit the design variables and mass properties of the assembly. I have successfully written code snippets that generalize simple processes, such as translating and rotating objects, but the road block I am running into is the inability to import the NXOpen API into an external script which will run the desired class without opening NX at all. Every direction I go seems to be a dead end. I've tried editing my NXOpen environment variables to allow other python paths, and I've tried using the command "run_journal" only to realize I need the teamcenter installation to use this command which is out of our budget at the moment. In summary, I've been trying to run external files to execute NXOpen automation scripts outside of NX and cannot figure it out. I am willing to switch over to Java or VB if needed, but am not too sure how to do it in those languages as well.

If anyone has any insight or knowledge on this matter, any help would be greatly appreciated!

Thanks so much!
Sam

Need Help Improving Journal

$
0
0

Hello,

I have a journal I found that is working fairly well but there is one improvement I am trying to make to it. This journal is for PDF export of every component in an open assembly. The journal walks through the assembly makes the component displayed, Updates views, exports pdf of sheet if it exists, moves on to next component.

I would like to modify the journal to Hide all components after it makes a component displayed. Then update views, export pdf.

Any help would be greatly appreciated.

Thank you,
JS

Option Strict Off
Imports System
Imports System.IOImports System.Collections.GenericImports System.Windows.FormsImports NXOpen
Imports NXOpen.UFImports NXOpen.Assemblies 
 
Module Module1
 
    Dim theSession As Session = Session.GetSession 
    Sub Main() 
        If IsNothing(theSession.Parts.Display)Then
            MessageBox.Show("Active Part Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)ReturnEndIf 
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open() 
        Dim workPart As Part = theSession.Parts.Work 
        Dim myAsmInfo AsNew NXJ_Assembly_info
        myAsmInfo.Part= workPart
 
        Dim myPdfExporter AsNew NXJ_PdfExporter
        myPdfExporter.PickExportFolder() 
        myPdfExporter.Part= workPart
        Try
            myPdfExporter.Commit()Catch ex As NXException
 
        EndTry 
        ForEach tempPart As Part In myAsmInfo.AllUniqueParts
            myPdfExporter.Part= tempPart
 
            ChangeDisplayPart(tempPart) 
            Try
                myPdfExporter.Commit()Catch ex As Exception
                MessageBox.Show("Error:"& ControlChars.CrLf& ex.GetType.ToString&" : "& ex.Message, "PDF export error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
            EndTry 
        Next 
        ChangeDisplayPart(workPart)
        myPdfExporter =Nothing 
 
    EndSub 
    Sub ChangeDisplayPart(ByVal newPart As Part) 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Change Display Part") 
        Dim partLoadStatus1 As PartLoadStatus
        Dim status1 As PartCollection.SdpsStatus
        status1 = theSession.Parts.SetDisplay(newPart, False, False, partLoadStatus1) 
        partLoadStatus1.Dispose() 
    EndSub 
EndModule

Delete Component From Model and From Folder

$
0
0

Hello all,
I am looking for a way to select components in an assembly and then not only delete them from the model but also delete them from the computer. Something along the lines of selecting multiple components, hitting delete, have a confirmation window to confirm your action, if yes is selected the components are deleted from the model and from their respective file locations on the computer.

Thank you for your time.


Getting an Attribute from a part file from its drawing owning part

$
0
0

Hi,

I would like to sync the part's attribute the the drawings attribute using a journal.

Is there any code that will let me do that using a journal.

Thanks in advance,

Stan

Regarding collection of Datums information in drafting

$
0
0

Hi,
I tried a macro for collecting information of total number of Datums in Drafting.
The problem is I am getting output for PMI Datums in modelling mode and for Drafting mode I am not getting the output.
Please go through the below code and help me out.

Option Strict Off
Imports System
Imports NXOpen
Module IDSymbol_info
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myIdBuilder As Annotations.DraftingDatumFeatureSymbolBuilder
If workPart.Annotations.Datums.ToArray.Length = 0 Then
lw.WriteLine("No ID symbols found in current work part")
Return
End If
For Each tempID As Annotations.DraftingDatum In workPart.Annotations.Datums
myIdBuilder = workPart.Annotations.Datums.CreateDraftingDatumFeatureSymbolBuilder(tempID)
lw.WriteLine("origin: "& myIdBuilder.Origin.OriginPoint.ToString)
lw.WriteLine("upper text: "& myIdBuilder.Letter.ToString)
lw.WriteLine("arrow type: "& tempID.GetLineAndArrowPreferences.FirstArrowType.ToString)
lw.WriteLine("stub length: "& tempID.GetLineAndArrowPreferences.StubLength.ToString)
lw.WriteLine("")
Next
End Sub
End Module

Thanks in advance.

Regards,
Ravi

Move assembly components in structure including constraints

$
0
0

Hey,

NX seems to be unable to retain assembly constraints if you move a set of components in the assembly structure. In my opinion it should be able to retain the constraints that are still valid in the new location.

Is it possible to write a script that takes the currently selected components, asks for a new location in the tree, selects all common assembly constraints and moves the components and constraints (or recreates them in the new location)?

Thanks for any help in this matter.

Regards,
Daniel

View Triad Modification through Journal

$
0
0

Hi,

Is it possible to modify (Increase) the size of the View triad for the current session. I basically want to export images to Power point in standard views (ISO, FRONT, LEFT and TOP). I want the direction to be shown in the Images. With default Triad it is too small to see in the Power point.

How to pass my current monitor view as input parameter for Mapping Functions

$
0
0

I would like to find the location of all the Parts available in an Assembly on my monitor screen. After doing my research/asking for guidance, I was able to get someone told me these functions could help me do it. I tried to search for example of how to use NXOpen.View because I need to pass aView as View to input parameter of the function but I could not really find an example.

How can I declare my current monitor view of the assembly as View in order to pass it these Function inputs?

Function MapView2Abs(ByVal aView As View, ByVal loc As Point3d)Dim vmx As Matrix3x3 = aView.MatrixDim vw()AsDouble={0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}Dimabs()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim mx(11)AsDoubleDim irc AsIntegerDim c()AsDouble={loc.X, loc.Y, loc.Z} 
        ufs.Trns.CreateCsysMappingMatrix(vw, abs, mx, irc)
        ufs.Trns.MapPosition(c, mx) 
        MapView2Abs =New Point3d(c(0), c(1), c(2))EndFunction 
    Function Reverse(ByVal forward As Point3d)
        Reverse =New Point3d(-forward.X, -forward.Y, -forward.Z)EndFunction 
    Function MapAbs2View(ByVal aView As View, ByVal loc As Point3d)Dim vmx As Matrix3x3 = aView.Matrix 
        Dim origin_abs As Point3d = MapView2Abs(aView, Reverse(aView.Origin)) 
        Dim vw()AsDouble={origin_abs.X, origin_abs.Y, origin_abs.Z, _
                              vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}Dimabs()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim mx(11)AsDoubleDim irc AsIntegerDim c()AsDouble={loc.X, loc.Y, loc.Z} 
        ufs.Trns.CreateCsysMappingMatrix(abs, vw, mx, irc)
        ufs.Trns.MapPosition(c, mx) 
        MapAbs2View =New Point3d(c(0), c(1), c(2))EndFunction

Get the distance between 2 Parts in an Assembly

NXOpen.UF.Disp.DisplayTemporaryText Example

$
0
0

I would like to "mark" some information on Parts in an Assembly in my active monitor view as shown in picture. The marking data is taken from Parts' attribute.

Currently, I am able to obtain the attributes and get the abs/view location. I am looking into the way to display "Part Number 1", "Part Number 2", and "Part Number 3"

An example:
http://i64.tinypic.com/25tapuf.jpg
This is assumed I only have 3 parts with Child.Name =
"Part Number 1"
"Part Number 2"
"Part Number 3"

After searching, I found that NXOpen.UF.Disp.DisplayTemporaryText may be able to help me achieve what I would like to have but there is no example

Parameters

view_tag as Tag,
which_views as UFDisp.ViewType,
text as String,
text_coord as Double,
ref_point as UFDisp.extRef,
color UFObj.DispProps,
char_size as Double,
hardware as Int32

Can anyone help me with an example how to use this function


Help with selecting faces please

$
0
0

Hi wonderful NXJ community!

Could someone please tell me what is wrong with what I am doing. I am trying to select faces and return them as an array. It should be simple. I am migrating from "selectTaggedObject" which is a single face to "selectTaggedObjects" which is an array (right?)

My code is this

Public Function SelectFaces(ByVal propt As String) As Face()
 
        Dim title As String = "Select faces"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask(0) As Selection.MaskTriple
        Dim selectedFaces() As Face = Nothing
 
        With selectionMask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        End With
 
        Dim responce1 As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(
            propt, title, scope, selAction, includeFeatures, keepHighlighted, selectionMask, selectedFaces)
 
        If responce1 = Selection.Response.Ok Then
            Return selectedFaces
        Else
            Return Nothing
        End If
 
 
    End Function

When debugging, this gives an error on the line with .selectTaggedObject( that says "Unable to cast object of type 'NXOpen.TaggedObject[]' to type 'NXOpen.Face[]'"

I don't understand. When I used the "selectTaggedObject" I passed in a variable of type Face for it to put what you selected into. Now i have a Face() and it should put all the faces you select into that array.

Am I missing something?

Pleeeeease help

PS. selectObjects says it has been superseded by selectTaggedObjects

Export Extracted Face

$
0
0

Hi,

i'm facing a problem with the export option in NXOpen:
I created an non associative "extracted face" from a body.
Now i want to create a new part which only contains this extraced face.
I tried two options but they both don't work:

1. Option:
...
Dim nXObject2 As NXOpen.NXObject
nXObject2 = extractFaceBuilder1.Commit()
Dim Extracted_Face As NXOpen.Features.ExtractFace = Nothing
Extracted_Face = CType(nXObject2, Features.ExtractFace)
Dim BodyTag(0) As Tag
BodyTag(0) = nXObject2.Tag
Dim String_test As String = "D:\00_Database\test_part.prt"
theUFSession.Ps.ExportData(BodyTag, String_test)

2. Option:
...
Dim nXObject2 As NXOpen.NXObject
nXObject2 = extractFaceBuilder1.Commit()
Dim myOptions As UF.UFPart.ExportOptions
myOptions.params_mode = UF.UFPart.ExportParamsMode.MaintainAllParams
myOptions.new_part = True
Dim Name As String = "D:\00_Database\test_part.prt"
Dim BodyTag(0) As Tag
BodyTag(0) = nXObject2.Tag
theUFSession.Part.ExportWithOptions(Name, 1, BodyTag, myOptions)

I hope you can tell me whats my mistake with these options or an third option which works for my problem.

Thanks!

Johannes

How to Let NX Know the Starts and Stops for Centerline Length Measurement

$
0
0

I asked a question on some ideas how to do the measurement to get the distance between the 2 components on an assembly file a few days ago. I did some study on some of the issues and I would like to understand some of the possible ways to let the program knows when to start and to stop a measurement.

In my example, how can I let the program know the left housing is a starting point, and the right housing is stopping point? There are multiple branches.

Example image: http://i67.tinypic.com/262bl1e.png
Previous question: http://www.nxjournaling.com/content/get-distance-between-2-parts-assembly

Code for moving same part files to different positions using a text file

$
0
0

Hi

I have an assembly file with 4 parts of same name as (1.prt).I would like move them using a Text file where i have 4 lines as such denoting their respective positions in X,Y and Z.

100,0,0
-8000,1000,0
1000,1000,0
1000,1000,0

I am missing by the code a small bit linking the text file with the component,meaning when first line of the text file is read it has to move the 1 out of 4 parts by 1000,0,0 and so on.

please find the below code and kindly do the changes to it.

For i As integer = 0 To numsel-1
selobjs = theUI.SelectionManager.GetSelectedObject(i)

line = ReadLine(j+1, allLines)

Dim strings As String() = line.Split(",")
pt3.x = Double.Parse(strings(0))
pt3.y = Double.Parse(strings(1))
pt3.z= Double.Parse(strings(2))

workPart.ComponentAssembly.MoveComponent(selobjs,pt3, RotMat3)
Next

The problem with the above code it is just reading the first line and moving all the selected parts(4 Nos)by 1000,0,0.
But i need only the 1st one to be moved by 1000,0,0 and the second one by -8000,1000,0...

Please suugest

Delete All From Layer At The Assembly Level

$
0
0

I have a journal written that when run will ask the user to input a layer number and then delete all objects from that layer (based on code from this site). The journal works fine in a single assembly. The problem I am running into is when I run the journal in a file with multiple sub-assemblies it will only delete objects from the layer in the top most level (Objects on the selected layer in subs are not deleted). Any suggestions?

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
 
Module Module1
 
    Sub Main()
 
        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim theUISession As UI = UI.GetUI
        Dim answer As String = ""
        Dim myInt As Integer
 
        Do
            answer = NXInputBox.GetInputString("Enter a layer number", "Layer To Be Deleted?", " ")
            'if cancel is pressed, exit sub
            If answer = "" Then Exit Sub
        Loop Until Integer.TryParse(answer, myInt)
 
        theUISession.NXMessageBox.Show("Delete From Layer", NXMessageBox.DialogType.Information, "All objects will be deleted from layer: " & myInt.ToString)
 
        '&&&&& layer number to delete objects from
        Dim layerToDelete As Integer = myInt
 
        If displayPart Is Nothing Then
            'no part to work on
            Exit Sub
        End If
 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
 
        Dim notifyOnDelete1 As Boolean
        notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
 
        theSession.UpdateManager.ClearErrorList()
 
        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(workPart.Layers.GetAllObjectsOnLayer(layerToDelete))
 
        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
 
 
    End Sub
 
 
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module
Viewing all 787 articles
Browse latest View live