slow .prt file after moving bodies around repetitively using NXopen
slow .prt file after moving bodies around repetitively using NXopen
(OP)
Hi everyone,
Please excuse my English, not a native speaker. Here is my problem.
I wrote a piece of automation code using NXopen (SNAP) to move the bodies around repetitively in a .prt file in order to pack them together in the tightest fashion. Through the course of which, the code will also generate the intersection part between bodies if any and delete it after volume calculation for overlapping control purpose. It usually took UG/NX several hours to finish 1,000 iterations give or take.
At first, it goes kind of fast, but it gets slower and slower down the stretch. And after the automated process is finished, the .prt file becomes incredibly slow regardless the operation even if I just want to rotate or zoom in. I tried part cleanup, tried to play with customer defaults but nothing helped so far. The only thing that worked was export the prt file as parasolid and import it back in to a new prt file, then everything goes back to normal. Any ideas folks? Thanks in advance!
My pc specs:
Intel Xeon E5620 @2.40Ghz 2.39Ghz (2 processors)
RAM 24GB
I'm using NX9 and Visual Studio 2015 to do the whole thing by the way.
Please excuse my English, not a native speaker. Here is my problem.
I wrote a piece of automation code using NXopen (SNAP) to move the bodies around repetitively in a .prt file in order to pack them together in the tightest fashion. Through the course of which, the code will also generate the intersection part between bodies if any and delete it after volume calculation for overlapping control purpose. It usually took UG/NX several hours to finish 1,000 iterations give or take.
At first, it goes kind of fast, but it gets slower and slower down the stretch. And after the automated process is finished, the .prt file becomes incredibly slow regardless the operation even if I just want to rotate or zoom in. I tried part cleanup, tried to play with customer defaults but nothing helped so far. The only thing that worked was export the prt file as parasolid and import it back in to a new prt file, then everything goes back to normal. Any ideas folks? Thanks in advance!
My pc specs:
Intel Xeon E5620 @2.40Ghz 2.39Ghz (2 processors)
RAM 24GB
I'm using NX9 and Visual Studio 2015 to do the whole thing by the way.





RE: slow .prt file after moving bodies around repetitively using NXopen
How big, in Megabytes, Is that file ?
How big is the Parasolid file [MB] in comparison ?
You could try File - export- part, to keep the feature tree/ associativity etc.
Regards,
Tomas
RE: slow .prt file after moving bodies around repetitively using NXopen
Thanks for your reply! I have 18 bodies in the .prt file which is given by our customer, imagine 18 irregular cylinders. In each iteration, the code will randomly choose one from 18 and perturb it (do either translation or rotation).
The size of the file is actually very small:
Parasolid file is around 4,175 kb
.prt file before execution is 3,500 kb
.prt file after execution (the slow one) is around 7,000 kb
After part cleanup the size of the .prt file comes down to around 3,800 kb but remains to be very slow.
I guess the slowness has something to do with all the intersections created during the process. But they are deleted once the volume of them are calculated. So I'm not sure what else I can do with them.
Regard,
Pei
RE: slow .prt file after moving bodies around repetitively using NXopen
This explains why you code gets slower and slower as the process proceeds.
However, it doesn't explain why model operations are slow after your code has finished executing. Since export/import of Parasolid data fixes the performance problem, it must be related to "features" in NX. Try making every object "dumb" by removing parameters or using the "Orphan" function in SNAP. This should get rid of any extraneous features that are slowing you down.
RE: slow .prt file after moving bodies around repetitively using NXopen
RE: slow .prt file after moving bodies around repetitively using NXopen
Thank you very much for your valuable input. I'll definitely give 'Orphan' function a try!
Here is a portion of my SNAP code which basically consists of three parts: first perturb a randomly chosen body, then calculate the distances between bodies, finally generates the intersections in order to calculate the total overlapping volume.
For p = 0 To pMax
'Randomly choose a NX.body and perturb---------------------------------------------------
Randomize()
random = {Rnd(), Rnd(), Rnd(), Rnd(), Rnd(), Rnd(), Rnd(), Rnd()}
j = System.Math.Floor((num2 * random(6) + num1 + 1)) 'choose which component to perturb
body_obj = obj(j) 'obj is an array of NX.body
massPro = MassProperties(body_obj)
trans = {(random(0) - 0.5), (random(1) - 0.5), (random(2) - 0.5)}
trans_large = {(6 * random(0) - 3), (6 * random(1) - 3), (6 * random(2) - 3)}
If random(7) > 0.5 Then
tr = Transform.CreateTranslation(trans)
Else
tr = Transform.CreateTranslation(trans_large)
End If
rt1 = Transform.CreateRotation(massPro.Centroid, axis1, 120 * (random(3) - 0.5))
rt2 = Transform.CreateRotation(massPro.Centroid, axis2, 120 * (random(4) - 0.5))
rt3 = Transform.CreateRotation(massPro.Centroid, axis3, 120 * (random(5) - 0.5))
trans_rev = {-(random(0) - 0.5), -(random(1) - 0.5), -(random(2) - 0.5)}
trans_large_rev = {-(6 * random(0) - 3), -(6 * random(1) - 3), -(6 * random(2) - 3)}
If random(7) > 0.5 Then
tr_rev = Transform.CreateTranslation(trans_rev)
Else
tr_rev = Transform.CreateTranslation(trans_large_rev)
End If
rt1_rev = Transform.CreateRotation(massPro.Centroid, axis1, -120 * (random(3) - 0.5))
rt2_rev = Transform.CreateRotation(massPro.Centroid, axis2, -120 * (random(4) - 0.5))
rt3_rev = Transform.CreateRotation(massPro.Centroid, axis3, -120 * (random(5) - 0.5))
obj(j).Move(tr)
obj(j).Move(rt1)
obj(j).Move(rt2)
obj(j).Move(rt3)
'Calculate the distances between bodies-------------------------------------------------
For r2 = 0 To j - 1
Dist(j, r2) = Distance(obj(j), obj(r2))
Next
If j < num Then
For r1 = j + 1 To num
Dist(r1, j) = Distance(obj(r1), obj(j))
Next
End If
scalarDistNew = 0
For r1 = num1 + 1 To num
For r2 = 0 To r1 - 1
If r2 > 0 Then
scalarDistNew += Dist(r1, r2) '* diaMatrix(r1, r2)
End If
Next
Next
'Generate intersections to calculate the total volume of overlapping then delete------------
For l2 = 0 To j - 1
flag = 0
Try
intersection = Create.Intersect(obj(j), obj(l2))
Catch ex As System.Exception
flag = 1
End Try
If flag = 0 Then
intersection.Delete()
intersection = Create.Intersect(obj(j), obj(l2))
Inter(j, l2) = Volume(intersection.Body)
scalarInter += Inter(j, l2)
intersection.Delete()
Else
Inter(j, l2) = 0
End If
Next
If j < num Then
For l1 = j + 1 To num
flag = 0
Try
intersection = Create.Intersect(obj(l1), obj(j))
Catch ex As System.Exception
flag = 1
End Try
If flag = 0 Then
intersection.Delete()
intersection = Create.Intersect(obj(l1), obj(j))
Inter(l1, l2) = Volume(intersection.Body)
scalarInter += Inter(l1, j)
intersection.Delete()
Else
Inter(l1, j) = 0
End If
Next
End If
scalarInterNew = 0
For l1 = num1 + 1 To num
For l2 = 0 To l1 - 1
scalarInterNew += Inter(l1, l2)
Next
Next
Next p
Regards,
Pei
RE: slow .prt file after moving bodies around repetitively using NXopen
When you transform a solid body, Is there a "move Object" created in the Part Navigator ?
When using the "Move Object" interactively, there is an option "associative" which will create "Move object" -features if checked.
Regards,
Tomas
RE: slow .prt file after moving bodies around repetitively using NXopen
The Part Navigator remains the same throughout even when the intersections are generated (probably because their type is boolean?). I think no feature will be generated when I move a solid body because otherwise I would end up having a ton of bodies on my screen...
RE: slow .prt file after moving bodies around repetitively using NXopen
RE: slow .prt file after moving bodies around repetitively using NXopen
It should maintain cleaner part and better performance.
RE: slow .prt file after moving bodies around repetitively using NXopen
Don't delete things one at a time. Every time you do a Delete, it causes an Update. So, in the latter part of your program, add the Intersection objects to a list, and then delete the list all at once by calling Snap.NX.NXObject.Delete(NXObject[]).
So, something like this:
CODE --> vb
But the rollback idea is even better. Before you start creating the intersection objects, call Snap.Globals.SetUndoMark. Then, after you're done call Snap.Globals.UndoToMark.
RE: slow .prt file after moving bodies around repetitively using NXopen
The rollback function worked out great. I used it to reverse the move as well
The process still gets slower and slower over time which seems like something I have to endure because moving objects around causes a lot of updates, but I've seen a lot of improvements speed-wise.
Thank you guys again.
Regards,
Pei