I'm starting with NXopen, and even after I read the getting started pdf online I'm still struggling.
I'm trying to create a comand to edit several CAM operations I selected manualy, instead of modifying each one by one. The objective is to delete the body selection of those operations and select a new one.
I'm not even sure what code would be easier between making a looping on a string of all the selection, or if I try to edit the selection directly (don't even know if it's possible tho).
I tried to record a journal but I'm not advanced enought to understand everything because the code is way more dense than in themanual, and the few things I tried to change only lead to errors.
I'm working with NX 1972 or 1968, not sure of the exact number, it's not the very last version but the previous one.
And we use VB language in our company.
If anyone have an advice on how to process or I don't know, whatever that could help.
Thanks
Hello, so now that I'm at work I can say I'm working on NX 1973, and post the result :
' NX 1973
' Journal created by baguette on Tue Aug 3 12:07:57 2021 Paris, Madrid (heure d’été)
'
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 surfaceContour1 As NXOpen.CAM.SurfaceContour = CType(workPart.CAMSetup.CAMOperationCollection.FindObject("OP2_FIN-RAIDISSEUR_5"), NXOpen.CAM.SurfaceContour)
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Editer OP2_FIN-RAIDISSEUR_5")
Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Départ")
Dim surfaceContourBuilder1 As NXOpen.CAM.SurfaceContourBuilder = Nothing
surfaceContourBuilder1 = workPart.CAMSetup.CAMOperationCollection.CreateSurfaceContourBuilder(surfaceContour1)
theSession.SetUndoMarkName(markId2, "Boîte de dialogue Axe Outil Fixe - [OP2_FIN-RAIDISSEUR_5]")
Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Départ")
Dim geometrySetList1 As NXOpen.CAM.GeometrySetList = Nothing
geometrySetList1 = surfaceContourBuilder1.PartGeometry.GeometryList
theSession.SetUndoMarkName(markId3, "Boîte de dialogue Géométrie de pièce")
Dim taggedObject1 As NXOpen.TaggedObject = Nothing
taggedObject1 = geometrySetList1.FindItem(0)
Dim geometrySet1 As NXOpen.CAM.GeometrySet = CType(taggedObject1, NXOpen.CAM.GeometrySet)
' ----------------------------------------------
' Début dialogue Géométrie de pièce
' ----------------------------------------------
geometrySetList1.Erase(0, NXOpen.ObjectList.DeleteOption.Delete)
Dim geometrySet2 As NXOpen.CAM.GeometrySet = Nothing
geometrySet2 = surfaceContourBuilder1.PartGeometry.CreateGeometrySet()
geometrySetList1.Append(geometrySet2)
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
partLoadStatus1 = workPart.LoadThisPartFully()
partLoadStatus1.Dispose()
Dim selectionIntentRuleOptions1 As NXOpen.SelectionIntentRuleOptions = Nothing
selectionIntentRuleOptions1 = workPart.ScRuleFactory.CreateRuleOptions()
Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Départ")
Dim surfaceContour2 As NXOpen.CAM.SurfaceContour = CType(nXObject1, NXOpen.CAM.SurfaceContour)
Dim surfaceContourBuilder2 As NXOpen.CAM.SurfaceContourBuilder = Nothing
surfaceContourBuilder2 = workPart.CAMSetup.CAMOperationCollection.CreateSurfaceContourBuilder(surfaceContour2)
theSession.SetUndoMarkName(markId8, "Boîte de dialogue Axe Outil Fixe - [OP2_FIN-RAIDISSEUR_5]")
' ----------------------------------------------
' Début dialogue Axe Outil Fixe - [OP2_FIN-RAIDISSEUR_5]
' ----------------------------------------------
Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Axe Outil Fixe - [OP2_FIN-RAIDISSEUR_5]")
theSession.DeleteUndoMark(markId9, Nothing)
Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Axe Outil Fixe - [OP2_FIN-RAIDISSEUR_5]")
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = surfaceContourBuilder2.Commit()
This is the record of me doing those exact things :
-start recording
-selecting the CAM operation with left click
-right click on it
-edit
-clicking OK on the popup saying all instances will be modified
-idk the exact words for this one (in french for me) but it's the second line, under the geometry choice, maybe it is body selection
-delete the selection by left clicking the cross
-select the new body
-left click on OK to close the body selection
-left click on OK to close the CAM operation window
-stop recording
So as I say the code is somehow hard for me to understand, but the idea would be to change the operation clicked for a list aiming selected operations before playing the journal I guess ?
I saw that I have to remove the fact that the journal is linked to the specifics paramters of the clicked operation so it will become usable in a general way for any operation selected, have I a few changes to do to get there or do I have to rewrite a lot of things ?
I'm really clueless about where to start to be honest, I don't even know if it's the best solution.
Maybe some smaller codecould be more effective but I don't have enought knowledge.
So I cleaned my code as much I can, I think even if there's still some useless stuff it won't be a big deal
Now I should make all this code as a function, use a list to gather the selected CAM operations I want to modify and loop the function on each name ?
I'm thinking about something looking like that :
Code:
Dim namelist As New List
Dim Name As String
Do
name=GetName(SelectedTags)
namelist.Add(name)
Loop Until name=" "
For each namelist
Function geomchange
End Function
I took this idea from the VB section of the getting started guide
Is it a legal way to go ?
I'm sorry it's probably obvious and annoying to deal with beginner stuff like this but I didn't find anything on changing geometries, it's often about names, colors, speeds...
And nothing as well on editing several things like multiple operations on the tree.
Hello
And to be more precise about that, the workpiece contains a lot of operations, and something like a half of those operations are based on specific geometries that are made on purpose for each of them
So not all the operations should be modified, I think it's something like 100 operations that I have to change
And I have as rule to not change anything else
I'm actually lost somewhere between guides, videos and whatever I could find
It's really hard to understand what syntax to use, it looks like no one ever had to do this, there's litteraly nothing I could find about editing something else than feed or spindle speeds in CAM operations