Notifications
Clear all

[Closed] matchpattern help

Hello,
I have a edittext in the rollout named modname and i want to match the pattern name of the modifier in the objects scene and delete it. For example, if i want to delete the “UV as HSL Gradient With Midpoint” modifier (which has a loooonng name) i have to write the whole name as it is (case sensitive). So i am trying to just write the first letters to match the modifier name and delete it.
Let’s say if i will write down in the edittext just “uv as”, i assume the script will find the modifier name and delete it.

This code works fine if i’ll write the entire modifier name (case sensitive on):


for o in objects do for m = o.modifiers.count to 1 by -1 where o.modifiers[m].name == (modname.text as string) do deleteModifier o m

This is what i am trying to achieve but not working:


on del click do
(
local txt = (modname.text as string)
local pattern = txt
for o in objects do for m = o.modifiers.count to 1 by -1 where o.modifiers[m].name == (matchpattern txt pattern:(pattern) ignoreCase:false) do deleteModifier o m
-- print pattern
)

Can someone help me on this to understand what i am doing wrong?

7 Replies

matchPattern returns bool

Yap, but still i don’t know how to solve it out…

Note that you are also defining the pattern same as the input string, so it will always match.


(
    
    try destroydialog ::RO_DELETE_MODIFIERS catch()
    rollout RO_DELETE_MODIFIERS "" width:192 height:96
    (
        editText edt_pattern "Name:"                   pos:[8, 8] width:176
        checkbox chk_case    "Case Sensitive"          pos:[8,32] width:176
        button   bt_delete   "Find & Delete Modifiers" pos:[8,56] width:176 height:32
        
        /*
            input str = "UV as HSL Gradient With Midpoint"        
            
            Pattern Examples:
                "uv as*"
                "UV*"
                "*HSL*"
        */
        
        on bt_delete pressed do
        (
            pattern = edt_pattern.text
            ignoreCase = not chk_case.checked
            
            undo "Delete Modifiers" on
            (
                for j in objects do
                (
                    for k = j.modifiers.count to 1 by -1 do
                    (
                        if matchpattern j.modifiers[k].name pattern:pattern ignoreCase:ignoreCase do
                        (
                            deletemodifier j j.modifiers[k]
                        )
                    )
                )
            )
        )
    )
    createdialog RO_DELETE_MODIFIERS
    
)

Thank you, PolyTools!
I did a small modification for the pattern variable.

 pattern = edt_pattern.text + "*" 

For instance of you have TurboSmooth as modifier you can type just “tur” and delete it.

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

I just did it more generic, so you could use any pattern. But in your case you will use it in a specific way, so what you did is correct.

Yap. I replied because i was thinking it will help someone who is interested about this.
Thank you again PolyTools.

EDIT:
I will post here the complete script for those who are interested.
The script will delete modifiers based on the option that user will selected:

  1. from all objects present in scene. [mass]
  2. from selection.
    Just type the first letters of the modifier name you want to delete. Eg. “at” for “Attribute Holder”

try destroydialog ::RO_DELETE_MODIFIERS catch()
rollout RO_DELETE_MODIFIERS "" width:192 height:96
(
   editText     edt_pattern           "Name:"                     pos:[8, 8] width:176
   radiobuttons rbt_option   labels:#("scene","selection")        pos:[8,32] width:176
   button       bt_delete             "Find & Delete Modifiers"   pos:[8,56] width:176 height:32
   
   Fn delMod option= (
         pattern = edt_pattern.text + "*"
         undo "Delete Modifiers" on (
            for o in option do for m = o.modifiers.count to 1 by -1 do 
            (if matchpattern o.modifiers[m].name pattern:pattern ignoreCase:true do deletemodifier o o.modifiers[m])
         )   
         edt_pattern.text = ""
   )      
   on bt_delete pressed do (
         case rbt_option.state of (
               1: delMod objects 
               2: delMod selection
         )
   )
)
createdialog RO_DELETE_MODIFIERS

there is alternative way to delete modifiers:


-- by class type
while (m = $.modifiers[skin]) != undefined do deletemodifier $ m

-- by name
while (m = $.modifiers[#skin]) != undefined do deletemodifier $ m
while (m = $.modifiers["skin"]) != undefined do deletemodifier $ m