make money

Award Winning Plant Industry Community

MAXScript: Improve Viewport Performance with the DWG to 3DS Max Block Cleaner

AKA Optimize Your 3DS Max/Design Scene!!

AKA One Of The Most Important Things To Do After Importing DWG Files Into 3DS Max/Design

Importing DWG CAD files efficiently is one of 3DS Max’s many bright spots. Unfortunately, the import will bring across some junk that will, depending on the complexity of your scene, significantly slow down your viewport. I use this script to clean up those files. In my experience, the difference in viewport/render performance after running this is significant.

This utility compliments my DWG Batch Importer script nicely. However, you don’t need that utility for this one to work.

The User Interface


DWG CAD Cleaner Interface
[/frame_left]

Part 1: Installation

1. Download the script or copy the source code from below.
2. Open 3DS Max/Design > Maxscript > Editor
3. Press CTRL+N if the window is not blank and paste the code into the new window
4. Press CTRL+S to save the file
5. Press CTRL + E to execute the code, you will see the above dialog box

Part 2: Usage

There are only two checkboxes and both cannot be selected at the same time.

Delete objects checkbox

This will delete all objects that have been deemed unworthy and/or match the criteria of “garbage”

Move to layer checkbox

This will move all objects that have been deemed unworthy to a new layer called “To Delete”. Use this to review the objects that will be deleted before you delete them. Basically this is a safety net in case you don’t trust me OR some objects are being deleted by mistake. Trust me. :)


	/* ########################################
	Version: v0.1
	DWG Garbage Scrubber; 
	modified/written by Dave Tyner (http://www.davetyner.com)
	Feel free to modify script functions for your needs. You can also expand the Script in any way you like,
	just please leave this original statement untouched.
	
	Copyright (C) 2013 Dave Tyner
	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
	files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, 
	merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished 
	to do so, subject to the following conditions:
	The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
	THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	##########################################	*/
		
try(destroyDialog Rollout001)catch() 

 Rollout Rollout001 "Delete CAD Block Objects" 
	 ( 
	 subrollout Subrollout001 "Scrub CAD Blocks" height:300 
	 ) 

	 Rollout Rollout002 "Scrub CAD Blocks" 
	 ( 
		 group "Options" 
		 ( 
			-- edittext txtEditText001 "TextBox" align:#left width:225 
			 --spinner spnSpinner001 "Spinner" range:[1,100,1] type:#integer align:#left width:50 
			 checkbox chkDelete "Delete objects" checked:true
			 checkbox chkMoveToLayer "Move objects to new layer"
			 button btnButton001 "CLEAN" 
			 label lblLabel001 align:#center 
			 progressbar doit_prog color:red 
		 ) 
		 
		on chkDelete changed state do
		(
			if not chkMoveToLayer.checked then chkMoveToLayer.checked= true else chkMoveToLayer.checked = false
		)
		
		on chkMoveToLayer changed state do
		(
			if not chkDelete.checked then chkDelete.checked = true else chkDelete.checked = false
		)
		
		 on btnButton001 pressed do 
			 (

					fn deleteObjectsFromLayer arr=(
						
						LayerManager.newLayerFromName "To Delete"
						for a in arr do (layermanager.getlayer (layermanager.count-1)).addnode a
							
					)	
					
					startobjects = objects.count
					thedel=#()
				 
						objs = for o in geometry collect o
						
						lblLabel001.text = "Processing " + objs.count as string + " objects in scene"
						
						if objs.count>0 then
						(					
								for i = 1 to objs.count do  -- iterate through all geometry in the scene 
								(
								objs[i].controller=prs() --set the objects controller to Position/Rotation/Scale
									
								if objs[i].parent != undefined then objs[i].parent = undefined
								doit_prog.value = 100.*i/objs.count	
								)
										
									for sp in objects where classof sp == splineshape do append thedel sp --delete splines
									for o in geometry where classof o == LinkComposite do converttomesh o --convert BLOCKS to meshes
									for o in geometry where classof o == LinkComposite do append thedel o --Delete Block objects (non geometry, viewport killer)
									for o in objects where classof o == NURBSCurveshape do append thedel o --Delete Curve shapes if they exist
						)

						if chkMoveToLayer.checked == true then deleteObjectsFromLayer thedel			
						count = thedel.count
						if chkDelete.checked == true then delete thedel
						lblLabel001.text = (count as string) + " objects have been modified"
			 ) 

	 ) 
	 createdialog Rollout001 400 200 

	 addsubrollout Rollout001.Subrollout001 Rollout002 rolledup:false
	 
	 



Example scene: Before and After





Thanks to forum user JohnHolder for the test scene!

[frame_left ]

DOWNLOAD SCRIPT

[/frame_left]

Tags: , , , , , , , , ,

About the Author

About the Author: Dave Tyner is a 3DS Max 2013 Certified Professional working as a visualization artist for one of the worlds largest EPC firms. dave@davetyner.com @davetyner3D www.davetyner.com .

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

There Are 3 Brilliant Comments

Trackback URL | Comments RSS Feed

  1. Francisco says:

    Hello! It’s a really cool script. But i have a problem. when a open a Dwg in 3ds max and apply your script its just exclude everything, May you help me?
    More one time, Congratulations!

    • dave says:

      Thank you Francisco! This probably means that none of your objects are splines, link composites, or nurbs curves. Do you see any objects with the name “$Block” something?

  2. Aziz says:

    Sir,

    it`s very cool, i am also working on AutoCAD 3d and currently started work on 3Ds Max.
    for me its very easy to create the required object on 3d and hard to work on 3ds max.
    how to import the objects from 3d Autocad to 3ds max.
    i have done one dryer project in 3ds max and uploaded on Youtube named: Dubai municipality 3ds max.
    kindly see and comments.
    Aziz

Post a Comment

Your email address will not be published. Required fields are marked *

Top