CGTalk is it smarter way for this ?
 08-09-2010, 06:51 PM #1 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia   Join Date: May 2007 Posts: 29 is it smarter way for this ? Hi I have been trying again do some maxscript stuff and come to part of script where i am looking for some variable inside array which is created from point3 values and i would like to know if is any better, faster and smarter way how deal with this. My biggest issue is that i cant find any other way how search inside this values only by converting them into new integer array which i don't think is very efficient. So what do you think can you make this easier ? Thanks my result Code: ``` a = 5 -- searching for value 5 c =#() d =#() b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search for j = 1 to b.count do ( c_temp = #() d_temp = #() for i = 1 to 3 do append c_temp (b[j][i] as integer) -- convert [] array into integer value append c c_temp d_temp = finditem c[j] a append d d_temp ) d ``` share quote
 08-09-2010, 07:04 PM #2 Bobo Krakatoa Guy   Borislav Petrov Product Specialist Thinkbox Software Vancouver, Canada   Join Date: Mar 2002 Posts: 5,320 MAXScript is expression-based, so using intermediate variables to store the various stages of calculations, while allowed and possible, are not always necessary. So you can reduce the whole searching part to a single complex expression: Code: ```a = 5 -- searching for value 5 b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search result = for j in b collect (finditem (for i = 1 to 3 collect j[i]) a)``` The result will be the same #(3,3,0), but with a lot less intermediate results. On the plus side, the code will run a bit faster if you are searching through a lot of Point3 values or if you execute the same code many times because intermediate variable allocations and memory management cost time. I tested your code vs. mine with 100,000 iterations and my timing was 7.688 seconds vs. 10.109 seconds for your code. On the negative side, the above expression might be a lot more difficult to digest if you are seeing it for the first time... __________________ Bobo Last edited by Bobo : 08-09-2010 at 07:07 PM. share quote
 08-09-2010, 07:20 PM #3 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia   Join Date: May 2007 Posts: 29 hehe yes this is exactly what I was talking about. Quick and efficient how I wanted. I just didn't know the right words Thanks Bobo share quote
 08-09-2010, 07:58 PM #4 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,182 has to be a bit faster: Code: ``` a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (finditem #(p[1],p[2],p[3]) a) ``` or ... it looks ugly but it's 3.5 times faster and 15 times less of memory leaking (vs original code): Code: ``` a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (if p[1] == a then 1 else if p[2] == a then 2 else if p[3] == a then 3 else 0) ``` so, the smart way is not charming sometime. Last edited by denisT : 08-09-2010 at 09:50 PM. share quote
 08-11-2010, 03:53 PM #5 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia   Join Date: May 2007 Posts: 29 Hi DenisT I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array how I used in my example array and I must maybe mention that. But anyway thanks for another option how deal with collecting stuff quicker and efficient. Cheers share quote
08-11-2010, 06:56 PM   #6
denisT
MAX Doctor

portfolio
Denis Trofimov
CA, USA

Join Date: Jul 2009
Posts: 9,182
Quote:
 Originally Posted by Thorn444 Hi DenisT I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array ... Cheers

I guess that Point3 value has 3 members...

Last edited by denisT : 08-11-2010 at 11:08 PM.

 08-11-2010, 06:56 PM #7 CGTalk Moderation Lord of the posts   Join Date: Sep 2003 Posts: 1,066,481 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. share quote

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- CGSociety Art Gallery     Expose12 Call For Entries Gallery     Thrust CG Society's Challenge Gallery     CG Award Gallery     Featured 3D     Featured 2D     Featured Videos     Latest Entries Main Forums     News         Press Releases and Media     General Discussion     The Chatter Box     Recruitment     Education     Best from the Web Sponsored Challenges and Awards     Meet the Artists     Site of the Month Work in Progress and Critique     WIP Studio Professional Feedback     WIP/Critique: 3D     WIP/Critique: 2D         Speedpaints & Sketchbooks     WIP/Critique: Animation     Collaborative Team Projects Community Challenges     Modeling Challenge         Member Model Collection     Rigging Challenge     Sketch Challenge         Member SKETCH Collection     FXWARS Challenge         Member FXGallery     Animation Challenge         Past Sessions Archive     Lighting Challenges     Digital Matte Painting Challenge General Techniques     Concept Art     Modeling     Lighting and Shaders     Texturing and Surfacing     Character Rigging     Animation     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Compositing and Editing     Art Techniques and Theories Forum     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Science and Tech     Paleo Art and Anatomical Reconstruction     3D Printing and Scanning Realtime     Virtual Reality     Game Engine Software Specific Forums     Adobe Photoshop and Corel Painter     Autodesk 3ds max         3dsMax SDK and MaxScript         3dsMax Tutorials & Tips         3dsMax Resources         Plugins & Add-ons         Particle Flow     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Autodesk MotionBuilder     Autodesk Mudbox     Maxon Cinema 4D         Cinema 4D Resources     Autodesk Softimage         XSI: Programming         ICE: Interactive Creative Environment     NewTek Lightwave 3D         LW Resources         LW Tutorials     Blender     Pixologic ZBrush     Side Effects Houdini     The Foundry Modo         The Foundry Time Travel Challenge     Luxion KeyShot     E-on Software Vue     Quixel     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion Development and Hardware     Graphics Programming     Technical and Hardware CGTalk Support Forums     FAQ     CGSociety Support Forum     Suggestions
Miscellaneous

All times are GMT. The time now is 06:39 PM.