ModelCompare function API called UF_MODL_model_compare

Hello Folks,

I have following error while debugging ModelCompare function in both NX 10 & 11 Environment. Can anyone help me to solve this error and I didn't understand what the meaning of "an RM Object has an unsuitable OM class."

ERROR:

System.Exception: An RM object had an unsuitable OM class for this situation bei NXJournal.MyModelCompare(ListingWindow iListWindow, Part& iPart1, Part& ipart2) in

C:\Users\AppData\Temp\NXJournals6996\journal.vb:Zeile216.


foo = "bar";
baz = "foz"

Function MyModelCompare(ByVal iListWindow As ListingWindow, ByRef iPart1 As Part, ByRef iPart2 As Part) As ComparePartMapData

Try

Dim intPart1Tag As NXOpen.Tag = iPart1.Tag 'Tag derived from input part1
Dim oBody_Eids_Part1 As Tag = CType(vbNull, NXOpen.Tag)
'Dim oPartTransform1 As Double()
Dim intPart2Tag As NXOpen.Tag = iPart2.Tag
Dim oBody_Eids_Part2 As NXOpen.Tag = CType(vbNull, NXOpen.Tag)
'Dim oPartTransform2 As Double()

'iListWindow.WriteLine(TypeName(nxMappingData))
iListWindow.WriteLine("Part1 Tag: " & CStr(intPart1Tag))
iListWindow.WriteLine("oBody_Eids_Part1: " & CStr(oBody_Eids_Part1))
iListWindow.WriteLine("intPart2Tag: " & CStr(intPart2Tag))
iListWindow.WriteLine("oBody_Eids_Part2: " & CStr(oBody_Eids_Part2))

Dim theUFSession As UFSession = Nothing

Try
theUFSession = UFSession.GetUFSession()
If Not theUFSession Is Nothing Then
ilistWindow.WriteLine("Session Tag: " + CStr(theUFSession.Tag.ToString))
Else
iListWindow.WriteLine("Session is nothing!")
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try

'Initialize nx CompareMapdata

Dim nxMappingData As ComparePartMapData
theUFSession.Modl.InitializeCompareData(nxMappingData)

iListWindow.WriteLine("NX identical parts value = " + CStr(nxMappingData.identical_parts))
iListWindow.WriteLine(nxMappingData.part1.edges.num_entities.ToString)

iListWindow.WriteLine("UF Session derived!")
Dim a_mtx4Identity(15) As Double
theUFSession.Mtx4.Identity(a_mtx4Identity)

Dim oModl As UFModl = Nothing
Try
oModl = theUFSession.Modl
Catch ex1 As Exception
iListWindow.WriteLine("Unable to get Modl object!")
End Try

'Try
' theUFSession.Modl.FreeCompareData(nxMappingData)
'Catch ex1 As Exception
' Throw New Exception("Error with FreeCompareData3!")
'End Try

Dim dblTolerance As Double = 0.001
Try

oModl.ModelCompare(intPart1Tag,
oBody_Eids_Part1,
a_mtx4Identity,
intPart2Tag,
oBody_Eids_Part2,
a_mtx4Identity,
True,
CompareAccuracy.CompCoarse,
dblTolerance,
CompareIdenticalfaceRule.CompAlledges,
CompareChangeduniquefaceRule.CompNonidenticalsfChanged,
False,
nxMappingData)

Catch ex1 As Exception
Throw New Exception(ex1.message.Tostring)
End Try

Return nxMappingData
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function

According to the API docs, you should probably be using the .ModelCompare3 method. Try .ModelCompare3 and see if you get the same error.

Thanks a lot for suggestions but I already tried with ModelCompare3 method by using nxCompareOption but didn't work at all have same error.
If have any other solution then please let me know.

The code below worked for me. Note that I opened 2 revisions of an existing part that I had on hand; in the Main sub it loops through the open parts looking for these particular parts. This was to quickly get references to parts for testing; at the very least you will need to change the names of the parts before running this journal. The code was written/tested on NX 9.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "model compare")

lw.Open()

Dim compPart1 As Part
Dim compPart2 As Part

For Each tempPart As Part In theSession.Parts
'lw.WriteLine(tempPart.Leaf)
If tempPart.Leaf = "00020-sld.b" Then
compPart1 = tempPart
End If

If tempPart.Leaf = "00020-sld.e" Then
compPart2 = tempPart
End If
Next

If IsNothing(compPart1) OrElse IsNothing(compPart2) Then
lw.WriteLine("one or both parts = nothing")
Return
Else
lw.WriteLine("compPart1: " & compPart1.Leaf)
lw.WriteLine("compPart2: " & compPart2.Leaf)
End If

Dim theCompareData() As UFModl.ComparePartMapData3 = Nothing
theCompareData = MyModelCompare(compPart1, compPart2)

'lw.WriteLine("compare data length: " & theCompareData.Length.ToString)

lw.WriteLine("identical parts: " & theCompareData(0).identical_parts.ToString)
lw.WriteLine("")
lw.WriteLine("part 1: " & compPart1.Leaf)
lw.WriteLine(" number of faces: " & theCompareData(0).part1(0).faces(0).num_entities.ToString)
lw.WriteLine(" average face deviation: " & theCompareData(0).part1(0).faces(0).entity_info(0).avg_deviation.ToString)
lw.WriteLine(" number of edges: " & theCompareData(0).part1(0).edges(0).num_entities.ToString)
lw.WriteLine(" average edge deviation: " & theCompareData(0).part1(0).edges(0).entity_info(0).avg_deviation.ToString)

lw.WriteLine("")

lw.WriteLine("part 2: " & compPart2.Leaf)
lw.WriteLine(" number of faces: " & theCompareData(0).part2(0).faces(0).num_entities.ToString)
lw.WriteLine(" number of edges: " & theCompareData(0).part2(0).edges(0).num_entities.ToString)

lw.Close()

End Sub

Function MyModelCompare(ByRef iPart1 As Part, ByRef iPart2 As Part) As UFModl.ComparePartMapData3()

Try
Dim intPart1Tag As NXOpen.Tag = iPart1.Tag
Dim oBody_Eids_Part1 As Tag = Tag.Null
Dim intPart2Tag As NXOpen.Tag = iPart2.Tag
Dim oBody_Eids_Part2 As NXOpen.Tag = Tag.Null

'Initialize NX CompareMapdata
Dim nxMappingData() As UFModl.ComparePartMapData3 = Nothing
'theUfSession.Modl.InitializeCompareData(nxMappingData)

'Initialize NX compare options
Dim myCompareOptions As UFModl.CompareOptions = Nothing
myCompareOptions.accuracy = UFModl.CompareAccuracy.CompCoarse
myCompareOptions.compare_feat_and_exp = False
myCompareOptions.continue_if_examine_geom_fails = False
myCompareOptions.identical_face_rule = UFModl.CompareIdenticalfaceRule.CompAlledges
Dim dblTolerance As Double = 0.001
myCompareOptions.tolerance = dblTolerance

Dim a_mtx4Identity(15) As Double
theUfSession.Mtx4.Identity(a_mtx4Identity)

Try
theUfSession.Modl.ModelCompare3(iPart1.Tag, oBody_Eids_Part1, a_mtx4Identity,
iPart2.Tag, oBody_Eids_Part2, a_mtx4Identity,
myCompareOptions, nxMappingData)
Catch ex1 As Exception
Throw New Exception(ex1.Message.ToString)
End Try

Return nxMappingData
Catch ex As Exception
lw.WriteLine(ex.ToString)
Return Nothing
End Try

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thank you so much for the code and also work well in NX10 & 11 both. I suppose to made mistakes in writing vbNULL instead of you mentioned Tag.NUll. Please correct me if I wrong.

I have a question regarding string

"lw.WriteLine(" number of faces: " & theCompareData(0).part1(0).faces(0).num_entities.ToString"

Is that size of array or regarding to NX API??

"I suppose to made mistakes in writing vbNULL instead of you mentioned Tag.NUll. Please correct me if I wrong."

I doubt that the use of vbNull vs. Tag.Null was the root of the issue. A careful reading of my code will reveal that I used .ModelCompare3 and ComparePartMapData3. The API reference indicates that this method and data type should be used with NX 3 and later. It does not explicitly state that .ModelCompare has been obsoleted or deprecated, but it appears there are issues when trying to use it with a .net language.

-------------------------------------------------

"I have a question regarding string

"lw.WriteLine(" number of faces: " & theCompareData(0).part1(0).faces(0).num_entities.ToString"

Is that size of array or regarding to NX API??"

The .ModelCompare3 method returns an array of ComparePartMapData3. This struck me as odd since the map data contains structures for part1 and part2. I'm not sure why you would need an array since it seems you only need a single object. There may be a perfectly good reason why it is the way it is; but that would be a question for the API developers.

Sorry but i just want to know that there is any reason behind that you write zero like (0) in every string.

The ComparePartMapData3 results are returned as arrays within arrays. Why? I do not know. The syntax {array name}(0) accesses the first element of the array ({array name}(1) would be the second element, {array name}(2) the third and so on). This is necessary to access the information within the returned results.

Thanks a lot for such kind support and now i understood very well.....

Hiii,

Can you please suggest me if I am wrong to the right code for comparing features & expressions. While run to your suggested code compare all other things but not showing the result of features and expression.
Code :

lw.WriteLine(" Expressions : " & theCompareData(0).part1(0).expressions(0).num_entities.ToString)
lw.WriteLine(" Expressions : " & theCompareData(0).part2(0).expressions(0).num_entities.ToString)
lw.WriteLine(" features : " & theCompareData(0).part1(0).features(0).num_entities.ToString)
lw.WriteLine(" features : " & theCompareData(0).part2(0).features(0).num_entities.ToString)

Result:

compPart1: EXHAUSTPIPE_001
compPart2: EXHAUSTPIPE_002
identical parts: False
number of faces Part1: 3
number of faces Part2: 8
number of edges Part1: 2
number of edges Part2: 16
Expressions : 0
Expressions : 0
features : 0
features : 0

Try setting the compare_feat_and_exp options to True. In the code posted above it is set to False.

myCompareOptions.compare_feat_and_exp = True

I already found out this correction but Thanks a lot for suggestions.!!!!