ScriptSpot

Forum topic · Scripts Wanted

Sweep modifier to selection . . .

By sketchupmaster · 2024-10-07

Description

Hello,

I am trying to add sweep modifier with custom builtin shape, length and width, pivot position
single object work . . . ok!

but when selection two or more shapes or editable spline getting error
can any one solve

Thanks,


(
if selection.count > 0 then
(
for obj in selection where isKindOf obj Editable_Spline or isKindOf obj Shape do
(
--modPanel.addModToSelection (sweep ()) ui:on
addModifier obj (Sweep())
$.modifiers[#Sweep].CurrentBuiltInShape = 2
$.modifiers[#Sweep][#Bar_Section].length = 0.002
$.modifiers[#Sweep][#Bar_Section].width = 0.002
$.modifiers[#Sweep][#Bar_Section].cornerRadius = 0
$.modifiers[#Sweep].PivotAlignment = 4
)
)
)

Comments (7)

Thanks you guys

sketchupmaster · 2025-01-01

yes both working good . . . .

thank you so much

barigazy · 2024-12-07

Another approach


mapped fn addModi node modi = (if isKindOf node Shape do addModifier node modi)
if (nodes = getCurrentSelection()).count > 0 do
(
    clearselection() ; max create mode
    modi = Sweep CurrentBuiltInShape:2 PivotAlignment:4
    addModi nodes modi ; select nodes[1]
    profile = modi[4].object
    profile.length = profile.width = .002	
    profile.cornerRadius = 0
)

Much better Approach

SimonBourgeois · 2024-12-08

Well done Barigazy :)
This approach is much faster when applied to a large amount of shapes.

Getting error . . .

sketchupmaster · 2025-01-01

getting error please check . .


-- Error occurred in anonymous codeblock; filename: ; position: 132; line: 3
-- No ""get"" function for undefined
-- MAXScript callstack:
-- thread data: threadID:2236
-- ------------------------------------------------------
-- [stack level: 0]
-- In anonymous codeblock; filename: ; position: 272; line: 6
-- Locals:
-- Profile: undefined
-- modi: sweep:Sweep
-- nodes: undefined
-- Externals:
-- addModi: Global:addModi : addModi()
-- ------------------------------------------------------
-- [stack level: 1]
-- called from top-level

nodes: undefined

SimonBourgeois · 2025-01-07

it seems that you don't have any valid node selected, "nodes= getCurrentSelection()", shouldn't return undefined.
you can use this, it will send a message instead of crashing, i've also changed how nodes array was built, it now filters only shape objects and i removed shape filtering in the mapped function as it is no longer needed,earlier version was crashing if a non shape object was selected:


(
mapped fn addModi node modi = (addModifier node modi)
if (nodes = for o in selection where iskindof o Shape collect o).count > 0 do
(
    clearselection() ; max create mode
    modi = Sweep CurrentBuiltInShape:2 PivotAlignment:4
    addModi nodes modi ; select nodes[1]
    profile = modi[4].object
    profile.length = profile.width = .002	
    profile.cornerRadius = 0
)
)

thanks Simon . .

sketchupmaster · 2025-01-09

Hello

will check and revert you
thanks

Hi,

SimonBourgeois · 2024-12-01


(
 if selection.count > 0 then
 (
	for obj in (selection as array) where isKindOf obj Shape do
  (
	modPanel.setCurrentObject obj
    addModifier obj (Sweep())
    obj.modifiers[#Sweep].CurrentBuiltInShape = 2
    obj.modifiers[#Sweep][#Bar_Section].length = 0.002
    obj.modifiers[#Sweep][#Bar_Section].width = 0.002
    obj.modifiers[#Sweep][#Bar_Section].cornerRadius = 0
    obj.modifiers[#Sweep].PivotAlignment = 4
  )
 )
)