I am working on some 2D tools (this is a small part that cleans up the data) and encountered a strange bug.
Making 2D of this tree takes in top view takes 4 seconds, and sorting the lines and deleting the short and joining the long lines takes an instant. BUT doing it together takes a loooong time… why?
Try this:
Make 2D of the tree and run this script.
Then remove the # and then select the block and run it again. See how slow it is? I have not been able to figure out why make2D in python causes this odd slow down.
import rhinoscriptsyntax as rs
#rs.Command("_-Make2D Layout=CPlane Properties=ByOutputLayers CreateHiddenLines=No ShowTangents=No CreateSceneSilhouette=No CreateClippingPlaneIntersections=No ShowViewRectangle=No GroupOutput=No Enter", False)
lines = rs.SelectedObjects()
shortLines = []
longLines = []
for line in lines:
if rs.CurveLength(line)<0.1:
shortLines.append(line)
else:
longLines.append(line)
rs.DeleteObjects(shortLines)
if len(longLines)>0:
result = rs.JoinCurves(longLines, delete_input=False)
rs.SelectObjects(result)
There is something strange going on, sometimes the make2d part of the script takes 70 or even 130 seconds too. So what is causing make2D to run slow within rs.Command() ?
On both my machines it takes around 68 seconds to run this script on the tree.3dm provided.
Make2D takes 3.6 seconds.
if I make2D first and then delete the rs.Command line from the script then sorting the lines takes 0.28 seconds.
So the entire operation should take less than 4 seconds, so why is Rhino stalling for 64 seconds?
I have Lands Design installed, but I can’t really see why that makes any difference on why this is slow in one operation, but not if ran as two.
Please test the following on the tree.3ds file:
import rhinoscriptsyntax as rs
import time
objects = rs.GetObjects("Select objects", preselect=True, select = True)
if objects:
startTime = time.time()
rs.Command("_-Make2D Layout=CPlane Properties=ByOutputLayers CreateHiddenLines=No ShowTangents=No CreateSceneSilhouette=No CreateClippingPlaneIntersections=No ShowViewRectangle=No GroupOutput=No Enter", False)
lines = rs.SelectedObjects()
shortLines = []
longLines = []
for line in lines:
if rs.CurveLength(line)<0.1:
shortLines.append(line)
else:
longLines.append(line)
rs.DeleteObjects(shortLines)
if len(longLines)>0:
result = rs.JoinCurves(longLines, delete_input=False)
rs.SelectObjects(result)
print round(time.time()-startTime,2)
Here are my times with your file and latest script code:
V7: _RunPythonScript
Time to Make2D was 3.79 seconds
4.12
V8: _RunPythonScript
Time to Make2D was 5.48 seconds
5.78
V8: _-ScriptEditor _Run
Time to Make2D was 5.51 seconds
6.02
I don’t have any 3rd party plug-ins loaded. My system is a Dell XPS laptop, btw.
Without it takes 3.58 seconds.
With it takes 68 seconds.
Now how can that cause that lag ONLY if I do the two tasks right after each other with in one script, but not if I do them in two scripts and run them just after each other?
Do you have any idea?
The reason I want to use rs.Command(“Make2d”) instead of scripting the entire thing is that “Make2D” is so much easier to use and code than to master Rhino.Geometry.HiddenLineDrawing.Compute on large files.
If memory serves me right then rs.LastCreatedObjects refers to everything that is created as the script runs, so when I make2D of more stuff within a script then that too ends up in the list.
Thanks, that works great in this situation. Edit: Ah, I wrote that to early. Once I incorperated that in more complex code I got the same lag again.
After make2d it hang and the process takes 108 seconds if Lands is loaded, but unloaded it takes just 3.3 seconds.
Hi @fsalla and @albert
can you take a look at this please?
Test the script in post 7 with the file in post 1 in this thread.
When Lands is not loaded the script takes less than 4 seconds, with lands loaded it takes 68 seconds.
I tested it and I got a slow performance having Lands Design loaded as well (it was faster in my case though, around 25 seconds having Lands Design loaded). I am reporting this issue and we will keep you updated with news.
Hi Holo,
I debugged it, and it looks like Lands Design is receiving a selection modified message for each short line you delete, causing the Lands Edit Panel selection tree to be updated for each short line deleted.
This happens because you have the lines selected when you delete them. You can avoid the problem in 2 ways:
not having the Lands Edit panel active when you run the script
unselecting the lines you are going to delete. I just tried to unselect all and it fixes the problem:
Dang, I wrote that too early. On my home machine with Lands 5.8.3.9064 I still get this issue if Lands is loaded. I think it must have been unloaded when I did those last tests… sorry about that.