case wildcard problems

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2013
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\n"
default: format "% -- %\n" 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.
__________________
www.davetyner.com
 
  03 March 2013

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\n"
						false: format "% -- %\n" cfilter imp.name--addmodifier imp s
					)
			)
		)
	)


I hate this crap sometimes.
__________________
www.davetyner.com
 
  03 March 2013
wouldnt an if-then make more sense than a case here?
 
  03 March 2013
Originally Posted by lo: wouldnt an if-then make more sense than a case here?


Hi lo. Yes it does. I actually wound up with a for loop that removed items from the impobjs array. Thanks for your comment.
__________________
www.davetyner.com
 
  03 March 2013
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!
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
  03 March 2013
Originally Posted by LoneRobot: 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!
__________________
www.davetyner.com
 
  03 March 2013
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!
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
  03 March 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:55 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.