ScriptSpot

Forum topic · General Scripting

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

By Nik · 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)

Nik · 2014-01-14

Thanks guys for answers

here's the solution

Nik · 2014-01-13


(
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
	)
)

barigazy · 2014-01-13

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

barigazy · 2014-01-13

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

.

miauu · 2014-01-13

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

barigazy · 2014-01-13

Hey Kostadin, how are you?

miauu · 2014-01-13

Busy. :)
I hope you are well.

barigazy · 2014-01-13


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