Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Assembly Clearance Analysis Automation

[ Edited ]

I've been trying to automate the assembly clearance analysis process and sort filter through the results to remove obvious hard interferences(by component name) and touching interferences(occur regularly for us). I've got a journal recorded of running an analysis but nothing happens during playback. The api help doc has no documentation of the ClearanceSet, much less the documentation on sorting and interacting with the results. Does anyone have any experience with this or how to get around it? Not sure how to continue. 

 

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Analysis->Assembly Clearance->Perform Analysis
' ----------------------------------------------
Dim clearanceSet1 As Assemblies.ClearanceSet = CType(workPart.ComponentAssembly.ClearanceSets.FindObject("SET1"), Assemblies.ClearanceSet)

clearanceSet1.PerformAnalysis(Assemblies.ClearanceSet.ReanalyzeOutOfDateExcludedPairs.False)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

 

 

DHuskic Nx 9
14 REPLIES

Re: Assembly Clearance Analysis Automation

Did you have a look in the newset API Refenrece? I just looked in the NX10 API (.NET) and found quite some info.

Re: Assembly Clearance Analysis Automation

[ Edited ]

I was still running our older API. I downloaded and checked the newer versions and they do have a lot more information in the search results. Thank you for that suggustion. The pages aren't loading when I click display, have to figure this out then I should be able to proceed. 

DHuskic Nx 9

Re: Assembly Clearance Analysis Automation

I think this are security reasons. Maybe you have the file on a Network path. copy it to a local disk like C:\ an try from there.

Re: Assembly Clearance Analysis Automation

Right, I had it on my desktop. Tried the Nx10 and Nx9 API. I read somewhere that you might have to extract the chm files, but it didn't come in a zip. I compressed it and extracted it and it's working now. I'll start reading the documentation and post back with results for anyone else interested.
DHuskic Nx 9

Re: Assembly Clearance Analysis Automation

Looks like I'm having some trouble getting these tests to even run properly. From what I recorded, it needs a clearance set but I'm having trouble creating one via code. When I do create a clearance set manually and have the code reference that one, it won't finish the program and perform the analysis.
DHuskic Nx 9
Solution
Solution
Accepted by topic author DHuskic
‎12-04-2015 07:38 AM

Re: Assembly Clearance Analysis Automation

[ Edited ]

I just did some quick "journal recording" and it worked for me:

' NX 10.0.3.5
' Journal created by on Fri Dec 04 10:12:16 2015 Mitteleuropäische Zeit
'
Option Strict Off
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

' ----------------------------------------------
'   Menu: Analysis->Assembly Clearance->Clearance Set->New...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim nullNXOpen_Assemblies_ClearanceSet As NXOpen.Assemblies.ClearanceSet = Nothing

Dim clearanceAnalysisBuilder1 As NXOpen.Assemblies.ClearanceAnalysisBuilder
clearanceAnalysisBuilder1 = workPart.AssemblyManager.CreateClearanceAnalysisBuilder(nullNXOpen_Assemblies_ClearanceSet)

Dim expression1 As NXOpen.Expression
expression1 = clearanceAnalysisBuilder1.CreateClearanceZoneExpression("0.0")

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

expression1.Units = unit1

clearanceAnalysisBuilder1.SetDefaultClearanceZone(expression1)

clearanceAnalysisBuilder1.CalculationMethod = NXOpen.Assemblies.ClearanceAnalysisBuilder.CalculationMethodType.ExactifLoaded



theSession.SetUndoMarkName(markId1, "Clearance Analysis Dialog")

clearanceAnalysisBuilder1.ClearanceSetName = "SET2"

clearanceAnalysisBuilder1.ClearanceBetween = NXOpen.Assemblies.ClearanceAnalysisBuilder.ClearanceBetweenEntity.Components

clearanceAnalysisBuilder1.IsCalculatePenetrationDepth = True

Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Clearance Analysis")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Clearance Analysis")

Dim nXObject1 As NXOpen.NXObject
nXObject1 = clearanceAnalysisBuilder1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Clearance Analysis")

clearanceAnalysisBuilder1.Destroy()

Dim clearanceSet1 As NXOpen.Assemblies.ClearanceSet = CType(nXObject1, NXOpen.Assemblies.ClearanceSet)

clearanceSet1.PerformAnalysis(NXOpen.Assemblies.ClearanceSet.ReanalyzeOutOfDateExcludedPairs.False)

' ----------------------------------------------
'   Menu: Analysis->Assembly Clearance->Perform Analysis
' ----------------------------------------------
clearanceSet1.PerformAnalysis(NXOpen.Assemblies.ClearanceSet.ReanalyzeOutOfDateExcludedPairs.False)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Re: Assembly Clearance Analysis Automation

That is very similar to what I originally had when I first recorded it except for the 2 instances of the perform analysis call at the end of the journal, I only had one:

 

Dim clearanceSet1 As NXOpen.Assemblies.ClearanceSet = CType(nXObject1, NXOpen.Assemblies.ClearanceSet)

clearanceSet1.PerformAnalysis(NXOpen.Assemblies.ClearanceSet.ReanalyzeOutOfDateExcludedPairs.False)

' ----------------------------------------------
'   Menu: Analysis->Assembly Clearance->Perform Analysis
' ----------------------------------------------
clearanceSet1.PerformAnalysis(NXOpen.Assemblies.ClearanceSet.ReanalyzeOutOfDateExcludedPairs.False)

 

When I compiled a DLL with that code, I get a null referance error at the CreateClearanceAnalysisBuilder call. The documentation clearly states use a null value for creating a new clearance set.

 

Public Function CreateClearanceAnalysisBuilder(clearanceSet As NXOpen.Assemblies.ClearanceSet) As NXOpen.Assemblies.ClearanceAnalysisBuilder
 Member of NXOpen.Assemblies.AssemblyManager
Summary:
Creates a NXOpen.Assemblies.ClearanceAnalysisBuilder.

Parameters:
clearanceSet: NXOpen.Assemblies.ClearanceSet to be edited - may be a null reference (Nothing in Visual Basic) if creating a new Clearance Set.

Dim nullNXOpen_Assemblies_ClearanceSet As NXOpen.Assemblies.ClearanceSet = Nothing

Dim clearanceAnalysisBuilder1 As NXOpen.Assemblies.ClearanceAnalysisBuilder
clearanceAnalysisBuilder1 = workPart.AssemblyManager.CreateClearanceAnalysisBuilder(nullNXOpen_Assemblies_ClearanceSet)

 

When I ran a plain journal with your code, it executed succesfully but nothing happened. There's no way it ran the test within the time the journal editor window popped back up due to the large assembly I have open. What happened after you executed it? 

DHuskic Nx 9

Re: Assembly Clearance Analysis Automation

[ Edited ]

You are right, the second "PerformAnalysis" is not necessary.
If I run this code I get a new Clearance Set which I can view in the Clearance Browser.
I would have a closer look to "CollectionOneObjects" / CollectionTwoObjects" and "CollectionOneRange" / CollectionTwoRange" (properties of the builder) - maybe you have to define which object should be checked against what objects?

Re: Assembly Clearance Analysis Automation

[ Edited ]

Ahh I have to manually open the results. I didn't know showing the clearance browser was tied to a command on the toolbar. That's why I thought it wasn't working originally but it was just not showing the results automatically. Thank you for all of your help!

 

Next step is sorting filtering the list and interacting with the clearance browser results. I'll go do some tinkering and post back with my results. It might be easier to just not check the component-pairs that I am going to ignore anyways. 

DHuskic Nx 9