Quantcast
Channel: NX Journaling - .NET programming
Viewing all 67 articles
Browse latest View live

Can you register the NXOpen DLL?

$
0
0

Hey everyone,

I am hoping somebody might be able to tell me if I can register the NXOpen DLL? There is a utility in Visual Studio called regasm.exe. I believe it is short for register assembly. Essentially what it does is, it creates a COM Library (component library) that can be used for Microsoft Office Applications to reference the DLLs in there coding environments. Obviously this would be most useful in Excel. I am not sure if this can be done though. Any thoughts?


Open a specific component in an assembly.

$
0
0

Hello,

I would need help to develop a code that would open a specific component in an assembly. The code would pass all the components that are open in an NX session. He will have to find the component that has the attribute (String) '' MASTER = YES ''. Once the part is found, NX will have to open it "Make Display Part".

If the code does not find a component with the attribute (String) '' MASTER = YES '', an error message should appear and do nothing. Also, an error message should also appear if it finds more than one component with this attributes and doing nothing.

I want to create a code similar to the '' Workpiece '' and '' Cavity Layout '' command from MoldWizard.

Thank you !

Release a Winform From NX Environment When Exit

$
0
0

My program are simple, the release file is a main.dll contains
(1) A .NET library class (*.dll) to call a Winform (Form1)
(2) Winform (Form1) with Exit Button

I would like NX release my main.dll one I hit the Exit Button on Form1

The issue:
+ If I include the GetUnloadOption in (1).NET linrary class, then it calls the Winform for a few seconds and everything is unloaded --> I cannot use the features on my Winform

+ If I include the GetUnloadOption in (2)Form1 (and even called it from Exit Button). NX still holds my Main.dll

Any idea to resolve this issue?

 Public Function GetUnloadOption(ByVal dummy As String) As Integer
         'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
  End Function
<code>

How to force all opening dialogs to be closed

$
0
0

How to force all opening dialogs (like the selection dialog) to be closed?
I just would like to have a function when it runs, it can detect all opening dialogs and close all of them. Any help would be appreciated.

Create an isometric view of a feature, VB.NET / Snap

$
0
0

What I would like to do is to create an isometric view of body(1) of an assembly which is visible on layer 101 at a ratio of 2:1 (This requires making all layers invisible except the 101).

I tried to record the journal but it is lengthy and returns too many errors when I edited some things.

Any help is appreciated.

Using VB Code

$
0
0

I have used Visual Studio 2015 in the past to write and compile NXOpen applications. The IntelliSense available in the IDE is very helpful. I am considering using VS Code to write (not compile) NXOpen applications but I am not sure if the NX namespace can be added to it when programming in Visual Basic. In Visual Studio you add a reference to the needed NX dlls and IntelliSense picks up the namespace. Any thoughts on this? Have any other IDEs been used just for editing journals that utilize IntelliSense?

Does anyone worked on creating a WinForm UI to select a point or curve in NX using C#?

$
0
0

Hi All,
Does anyone worked on selecting a point or curve in NX using winform UI in C#? I'm well aware of Block and UI styler and all the options. But as we have constrains using both the options, I need your help in creating a winform UI to select a point or curve in NX and pass it as a tag in code for further use. Any help will be appreciated. Thanks in advance.

Find component by component name with some name contains in assembly.

$
0
0

Dear experts,

any please suggest me any API for Finding component by component name with some name contains in assembly.


Need code to extracting bend coordinate or control point coordinates in excel

$
0
0

I want a VB.Net code (In VB) to get the Stock/Routing bend or control point coordinate in excel sheet. Can anyone help me out.

XDocument for XML functions

$
0
0

I am attempting to write a journal using VB which incorporates XDocument to export an XML file. When I write the journal in Visual Studio, the XDocument is valid. I have tried: Imports System.xml, System.xml.linq, and System.xml.linq.xdocument. But when I run the journal, I get a syntax error: Type 'XDocument' is not defined.

How can I define an XDocument? Is it possible with NXOpen?

Drafting Application

$
0
0

Hi,
Happy New Year to all...

How to do the dimensioning using API ?
I tried running Journals, what I see that, it takes the reference of the curves and then creates the dimensions,

So does it mean, that I have Name all the edges in the model from which I need to take the dimensions ? ( sounds laborious)

or the other I can think of, is to make manual sketches in the model and put them in the Named views and then use those sketches in the drafting sheet, but still I have to Name the curves, Do I ?.
I could control the dimensions of the sketches with the same values which run the model.

I am bit confused on how to approach this feat.
any sort of guidance is much appreciated.

Thanks in advance.

Renaming NX feature

$
0
0

To rename datum features I've been trying to write a journal based upon information I've found on this forum.
I'm trying to rename a datum feature only when it has a specific attribute1 and rename it using an attribute2 that this datumplane already has.

This is the code I have until now:

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Const attributeTitle As String = "GSDDIR"
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each temp As TaggedObject In workPart.Datums
If TypeOf (temp) Is DatumPlane Then
Dim dPlane As DatumPlane = temp
'check for attribute
If dPlane.HasUserAttribute(attributeTitle,NXObject.AttributeType.String, -1) Then
dPlane.SetName("TEST")
End If
End If

Next
lw.Close()

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

I'm not so experienced with writing journals so any help is very much appreciated.

Journal to check drawing standards

$
0
0

is there any way to check drawing is created as per standards or not?

for example,
as per my custom standard
dimension text height should be 7 .
center mark parameters should be 5,3,5.
etc.....

i need to check these tasks by playing a macro.

Thanks in advance.

Problem with .net script - ApplicationSwitchImmediate

$
0
0

Hi All

I made a little script to create two Printscreens, for this I have to switch application. ( Because I don't know how to select / show the MCS for our Front and Backside programm)

I start the script always from manufacturing.

If I change inside the script to an another application than manufacturing I get a error message:

NXOpen.NXException: NX error status: 896084

If I go back manually to manufacturing and rerun the script it works fine. Does anybody have an Idea?

With best regards
Bizu

'' V2.0 19.12.2017 / SBe'	Creates a jpg from top and bottom view of the actual partfile''Option Strict Off  
Imports System  
Imports System.IOImports NXOpen  
Imports NXOpen.UF 
Module Printscreen   
 
    Sub Main(ByVal args()AsString) 
        Dim theSession As Session = Session.GetSession()Dim ufs As UFSession = UFSession.GetUFSession()Dim workPart As Part = theSession.Parts.WorkDim partName AsString= Path.GetFileNameWithoutExtension(workPart.FullPath)Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature=Nothing 
		Dim displayPart As NXOpen.Part= theSession.Parts.Display 
	'directory to output jpegs, change as neededDim outputDirectory AsString="L:\USERS\cam\"Dim strPartJpg AsString="" 
        IfNot Directory.Exists(outputDirectory)ThenMsgBox("The specified directory does not exist, journal will now exit", MsgBoxStyle.Exclamation, outputDirectory &" not found")ExitSubEndIfTry	
		theSession.ApplicationSwitchImmediate("UG_APP_GATEWAY")Catch
		theSession.ApplicationSwitchImmediate("UG_APP_MANUFACTURING")EndTry 
	Try	
		theSession.ApplicationSwitchImmediate("UG_APP_GATEWAY")Catch
		theSession.ApplicationSwitchImmediate("UG_APP_GATEWAY")EndTry 
	' Top view
		workPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Top, NXOpen.View.ScaleAdjustment.Fit)Dim scaleAboutPoint1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)Dim viewCenter1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)
			workPart.ModelingViews.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint1, viewCenter1) 
 
	' Wireframe 
		workPart.ModelingViews.WorkView.RenderingStyle= NXOpen.View.RenderingStyleType.StaticWireframe
		workPart.Views.Refresh() 
	' create Y-AxisDim datumAxisBuilder1 As NXOpen.Features.DatumAxisBuilder
		datumAxisBuilder1 = workPart.Features.CreateDatumAxisBuilder(nullNXOpen_Features_Feature)
		datumAxisBuilder1.Type= NXOpen.Features.DatumAxisBuilder.Types.YcAxisDim nXObject1 As NXOpen.NXObject
		nXObject1 = datumAxisBuilder1.Commit()Dim datumAxisFeature1 As NXOpen.Features.DatumAxisFeature=CType(nXObject1, NXOpen.Features.DatumAxisFeature)
		datumAxisFeature1.SetName("Y") 
	' create X-Axis plusDim datumAxisBuilder2 As NXOpen.Features.DatumAxisBuilder
		datumAxisBuilder2 = workPart.Features.CreateDatumAxisBuilder(nullNXOpen_Features_Feature)
		datumAxisBuilder2.Type= NXOpen.Features.DatumAxisBuilder.Types.XcAxisDim nXObject2 As NXOpen.NXObject
		nXObject2 = datumAxisBuilder2.Commit()Dim datumAxisFeature2 As NXOpen.Features.DatumAxisFeature=CType(nXObject2, NXOpen.Features.DatumAxisFeature)
		datumAxisFeature2.SetName("+X")
		datumAxisFeature2.Highlight 
 
	workPart.WCS.Visibility=False 
	' Export Jpeg Front'workPart.ModelingViews.WorkView.Fit()
        strPartJpg = partName &"_"&"v"&".jpg"  
        strPartJpg = Path.Combine(outputDirectory, strPartJpg)  
        ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.white)  
		datumAxisFeature2.Unhighlight
		datumAxisFeature2.HideBody 
	' create X-Axis minusDim datumAxisBuilder3 As NXOpen.Features.DatumAxisBuilder
		datumAxisBuilder3 = workPart.Features.CreateDatumAxisBuilder(nullNXOpen_Features_Feature)
		datumAxisBuilder3.Type= NXOpen.Features.DatumAxisBuilder.Types.XcAxis
		datumAxisBuilder3.IsAxisReversed=TrueDim nXObject3 As NXOpen.NXObject
		nXObject3 = datumAxisBuilder3.Commit()Dim datumAxisFeature3 As NXOpen.Features.DatumAxisFeature=CType(nXObject3, NXOpen.Features.DatumAxisFeature)
		datumAxisFeature3.SetName("-X")
		datumAxisFeature3.Highlight 
	' Rotate view 180° around Y-Axis Dim origin1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)Dim vector1 As NXOpen.Vector3d=New NXOpen.Vector3d(0.0, 1.0, 0.0)
		workPart.ModelingViews.WorkView.Rotate(origin1, vector1, 180.0)'workPart.ModelingViews.WorkView.Fit()
		workPart.Views.Refresh() 
 
	' Export Jpeg Back
        strPartJpg = partName &"_"&"r"&".jpg"  
        strPartJpg = Path.Combine(outputDirectory, strPartJpg)  
        ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.white) 
	'Shaded + Home view
		workPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Trimetric, NXOpen.View.ScaleAdjustment.Fit)
		workPart.ModelingViews.WorkView.RenderingStyle= NXOpen.View.RenderingStyleType.ShadedWithEdges
		datumAxisFeature3.Unhighlight
		datumAxisFeature3.HideBody
		datumAxisFeature1.HideBody 
	theSession.ApplicationSwitchImmediate("UG_APP_MANUFACTURING") 
	' delete datum axisDim markId1 As Session.UndoMarkId
		markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete") 
		Dim notifyOnDelete1 AsBoolean
		notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
		theSession.UpdateManager.ClearErrorList()Dim objects1(2)As NXOpen.NXObject
			objects1(0)= datumAxisFeature1
			objects1(1)= datumAxisFeature2
			objects1(2)= datumAxisFeature3
 
		Dim nErrs1 AsInteger
		nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1) 
		Dim nErrs2 AsInteger
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1) 
    EndSub 
 
	PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 
	'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination 
    EndFunction 
EndModule

write into attributes

$
0
0

Hello,
I have a filter that returns tags of some entities. I want to assign cetain texts to their attributes. Is there any example that shows how to perform this?
Thanks...


weight calculations journal

$
0
0

Hi,

I'm trying to write a journal for weight calculations.
In the past I was able to write some basic journals with great help from this forum. This time what I'm trying to achieve is a bit more complicated and I'm struggling to get started. Would be great if someone wants to give me some tips!

This is what I want to achieve:
I want to iterate through an assembly and, for each sheetbody get the centroid (geometric center) and the area and write them to a list.

Centroid: can be obtained using the command "mass using curves and sheets" using the thin shell option. Recording this action in a journal unfortunately gives me nothing to work with.

Area: can be optained using the face analyses command.

This info I want to use for some basic calculations:
mass (area*density_attribute*thickness_attribute) each sheetbody has its own attribute

Total COG (sum (mass*cog))/total mass

My goal is to get a results log containing:
Mass for each NX_part
Mass for the NX_ASM
COG for each NX_part
COG for the NX_ASM

First I want to get it to work fo a single part and then make it work on assembly level.

Any directions are very much appreciated!

Script fail if I click on Stop in Work In Progress dialog

$
0
0

I have a script which pause while it shows a message box.
MsgBox("Continue?")
But after a second it also shows the "Work in Progress" dialog with a Stop button.
Everything works well if I don't touch the Stop button.
But if I hit Stop the script fails.
How can I avoid this?

BR Gunnar

Does anyone worked on creating a WinForm UI to select a point or curve in NX using C#?

$
0
0

Hi All,
Does anyone worked on selecting a point or curve in NX using winform UI in C#? I'm well aware of Block and UI styler and all the options. But as we have constrains using both the options, I need your help in creating a winform UI to select a point or curve in NX and pass it as a tag in code for further use. Any help will be appreciated. Thanks in advance.

How to run an other .VB code ?

$
0
0

Hi,

For NX, I want to centralize several codes that I created for template import in an single button (code).

So, for the import of an "A" format, I have a code called "Import_A.vb" and it works very well. I have the same thing for the "B", "C", "D" and "E" formats.

I would like to make a code (start.vb) which opens a window with 5 choices in the form of a checkbox. If the user chooses the "A" format, then "Start.vb" will have to start "Import_A.vb" and "import_A.vb" will perform the import on format "A".

I do not need to make the file "import_A.vb", I need help to create the file "Start.vb".

You can help me ?

Best Regards!

find latest file in folder

$
0
0

I am trying to determine the latest file in a folder and it fails in NX but not as general vb.net program. What am I missing?

Option Strict Off
Imports System
Imports NXOpen

Imports System.Diagnostics

Module NXJournal
Sub Main ' (ByVal args() As String)
Dim dir = New System.IO.DirectoryInfo("c:\100")
Dim file = dir.EnumerateFiles("*.cls").
OrderByDescending(Function(f) f.LastWriteTime).
FirstOrDefault()
If file IsNot Nothing Then
Dim path = file.FullName
'' etc..
msgbox(path)

End If

Console.WriteLine("path=")

End Sub
End Module

Here is the error message I get in NX12:

=============================
System.MissingMemberException: Public member ‘OrderByDescending’ on type ‘FileSystemEnumerablelterator(Of
Filelnfo)’ not found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(StringMemberName, Boolean ReportErrors)
at MicrosoftVisualBasic.CompilerServices.NewLateßinding.QbjectLateGet(Object Instance, Type Type, String
MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at MicrosoftVisua I Basic.CompilerServices.NewLateBindingLateGet((Object Instance, Type Type, String MemberName,
Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at NXiournal.Main() in C:\Users\USERID1\AppData\Local\Temp\2\NXJournaIs564\journalO.vb:Iine 10
================================

Viewing all 67 articles
Browse latest View live