Optimizing code

Hello
I am trying to optimize my code. Need to select a object class in a specific layer.
I am working with code that consists of two stages:
1: Selecting all objects in the layer.
2: Selecting splines from selected objects.

(
local allNodes = #(), theNodes = #()
for n in selection do (n.layer.nodes &theNodes ; join allNodes theNodes)
select allNodes
select(for obj in selection where classof obj.baseObject==line collect obj)
)

I am looking for a way to exclude the first part while keeping the result.
Any ideas on how to do this? Any help appreciated.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

(
	allNodes = #()
	for n in selection do 
	(
		n.layer.nodes &theNodes 		
		for obj in theNodes where classof obj.baseObject == line do
		(
			append allNodes obj
		)
	)
	select allNodes
)
jahman's picture

.

What if selection contains several nodes that belong to the same layer?
You'll have n^2 results in allNodes array if all selected nodes are lines and belong to the same layer

LayerManager.deleteLayerByName "layer #1"
layer_1 = LayerManager.newLayerFromName "layer #1"
 
for i=1 to 100 do layer_1.AddNode (line())
 
layer_1.select true
 
(
	::allNodes = #()
	for n in selection do 
	(
		n.layer.nodes &theNodes 		
		for obj in theNodes do
		(
			append allNodes obj
		)
	)
	select allNodes
 
	format ">>> %\n" allNodes.count
)


>>> 10000

miauu's picture

.

Yep, that is true. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.