ScriptSpot home

Forum topic · General Scripting

How to make script where applys fn() or script on several selected objects?

By Nikolay Litvinov · 2014-01-12

Description

Hi frends!
Forexample is not works:


(
for obj in (selection as array) do
	(
		PolyToolsSelect.NumericEdge false
		obj.EditablePoly.ConvertSelection #Border #Vertex
		obj.weldThreshold = 0.001
		obj.EditablePoly.weldFlaggedVertices ()
		subobjectLevel = 3
	)
)

This script is works only with single object
Please help.
Thanks.

Comments (8)
Nikolay Litvinov

Thanks guys for answers

Nikolay Litvinov

here's the solution


(
for obj in (selection as array) do
	(
                select obj
		PolyToolsSelect.NumericEdge false
		obj.EditablePoly.ConvertSelection #Border #Vertex
		obj.weldThreshold = 0.001
		obj.EditablePoly.weldFlaggedVertices ()
		subobjectLevel = 3
	)
)
Reply to Nikolay Litvinov
Branko Živković

Do you know that this is "worst case scenario" solution.
Come on man, you can do this better I'm sure. :)

Reply to Branko Živković
Branko Živković

Anyway ...

fn weldBorderVerts objs thresh:.001 = if objs.count != 0 do
(
local moOpenEdges = meshop.getOpenEdges, poOpenEdges = polyop.getOpenEdges
local moVertByEdge = meshop.getVertsUsingEdge, poVertByEdge = polyop.getVertsUsingEdge
local moWeldVerts = meshop.weldVertsByThreshold, poWeldVerts = polyop.weldVertsByThreshold
max create mode
with redraw off for o in objs do
(
case classof o of
(
(editable_poly):
(
o.weldThreshold = thresh
if not (edgelist = poOpenEdges o).isEmpty do (poWeldVerts o (poVertByEdge o edgelist))
)
(editable_mesh): (if not (edgelist = moOpenEdges o).isEmpty do (moWeldVerts o (moVertByEdge o edgelist) thresh))
)
)
)
weldBorderVerts selection

.

Now add few more lines for Editable Poly objects, so the weld threshold to be restored when te function finish its job. :)

Reply to Branko Živković
Branko Živković


fn weldBorderVerts objs thresh:.001 = if objs.count != 0 do
(
local moOpenEdges = meshop.getOpenEdges, poOpenEdges = polyop.getOpenEdges
local moVertByEdge = meshop.getVertsUsingEdge, poVertByEdge = polyop.getVertsUsingEdge
local moWeldVerts = meshop.weldVertsByThreshold, poWeldVerts = polyop.weldVertsByThreshold
max create mode
with redraw off for o in objs do
(
case classof o of
(
(editable_poly):
(
oldthresh = o.weldThreshold
o.weldThreshold = thresh
if not (edgelist = poOpenEdges o).isEmpty do (poWeldVerts o (poVertByEdge o edgelist))
o.weldThreshold = oldthresh
)
(editable_mesh): (if not (edgelist = moOpenEdges o).isEmpty do (moWeldVerts o (moVertByEdge o edgelist) thresh))
)
)
)
weldBorderVerts selection