[Closed] case wildcard problems
the below code takes objects in a scene and formats a result based on the objects name. Only problem is it is not picking up the wildcard.
if chkSmooth.checked == true then
(
for ns = 1 to nsmooth.count do
(
local cfilter = ("*" + nsmooth[ns] + "*")
for imp in impobjs do
(
case imp.name of
(
(cfilter): format "Skip
"
default: format "% -- %
" cfilter imp.name--addmodifier imp s
)
)
)
)
Returns this:
STR – 3D-ELE-001-TDECK_CableTray
EQP – 3D-ELE-001-TDECK_CableTray
imported 3D-ELE-001-TDECK.dwg in 1.0
STR – 3D-STR-006-TDECK_Beam
STR – 3D-STR-006-TDECK_Horz Bracing
STR – 3D-STR-006-TDECK_Column
STR – 3D-STR-006-TDECK_Vert Bracing
STR – 3D-STR-006-TDECK_Handrail
EQP – 3D-STR-006-TDECK_Beam
EQP – 3D-STR-006-TDECK_Horz Bracing
EQP – 3D-STR-006-TDECK_Column
EQP – 3D-STR-006-TDECK_Vert Bracing
EQP – 3D-STR-006-TDECK_Handrail
I should not be seeing anything with the STR in it because of the wildcard. I have tried both matchpattern and case both don’t return the correct values. :banghead:
if chkSmooth.checked == true then
(
for ns = 1 to nsmooth.count do
(
local cfilter = "*" + nsmooth[ns] + "*" -- ("*" + nsmooth[ns] + "*")
for imp in impobjs do
(
case matchpattern imp.name pattern:cfilter of
(
true: format "Skip
"
false: format "% -- %
" cfilter imp.name--addmodifier imp s
)
)
)
)
I hate this crap sometimes.
Hi lo. Yes it does. I actually wound up with a for loop that removed items from the impobjs array. Thanks for your comment.
Hi Dave,
May I ask what the purpose of your pattern matching is for? If it is something that is identifiying objects for a smooth/subdivision operation you might want to consider flagging them with userproperties or appdata rather than resorting to string identification. Just my 2p!
Hello LR, thank you for replying. I am a big fan of your work!
As you deduced, I was trying to identify objects that get a smooth modifier and those that do not. My script went something like this:
-import dwg
-create array from incoming object names (dwg layer names)
-iterate through array and remove objects with a specified string in the name
-anything that is left gets the smooth modifier
Not sure how to do it any other way. The objects being imported are “dumb” for all intents and purposes so I am identifying them by string. I will have a look at userproperties and/or appdata. I’ve not used them before.
nSmooth = #(str,steel,beam)
if chkSmooth.checked == true then
(
for ns = 1 to nsmooth.count do
(
local cfilter = "*" + nSmooth[ns] + "*"
for imp = impobjs.count to 1 by -1 where matchpattern impobjs[imp].name pattern:cfilter == true do
(
deleteitem impobjs imp
)
)
if impobjs.count > 0 then for i = 1 to impobjs.count where impobjs[i].modifiers.count == 0 do addmodifier impobjs sm
)
Thank you LR!
Hi Dave,
No problem! Sounds like you’re doing it right, if you are getting this from the dwg import there’s no real way apart from using the string identifier. If the objects were max geo being merged in, you could use the userprop/appdata approach to identify them in the scene and act accordingly, but not in this case.
one possible way you could approach filtering these objects in your script could be to collect the items that you DO want into a new array, rather than looping through all the objects multiple times for each string pattern you are looking for, and then removing them. a bit like this :
smoothArr = for each in impobjs where not (matchpattern each.name pattern:"*str*" \
or matchpattern each.name pattern:"*steel*" \
or matchpattern each.name pattern:"*beam*") collect each
It does it in one hit this way!