Thursday, April 9, 2015

Correcting the Viewport color Display of imported AutoCAD drawings, when added into a Layer in 3ds Max

Correcting the Viewport color Display of imported AutoCAD drawings,
when added into a Layer in 3ds Max by Jamie Cardoso

viewport color

Often, imported AutoCad drawings lose their original colour once added into a new layer (using “Manage Layers” toolbar) in 3ds Max.   This “glitch” usually frustrates numerous users for a number of reasons, as colour coded drawings help to quickly understand the design and to easily “select by colour” any given layer/s of the relevant drawing in the 3Ds Max scene.    

After countless requests to post an article/tutorial on how to correct this problem, I have finally managed to put something together with help of a prolific script writer/ senior Visualiser/Photographer called David Venables.

David created a simple script to override the above mentioned problem!  I have had the pleasure to meet and continue work with David while at AVR London.

David Venables can also be contacted via Linked In Here.

Without further ado let us start by importing an AutoCAD file format (i.e. DWG) into 3Ds Max.  
import

dwg

With the DWG file imported into Max, the next step is to quickly create a simple script and apply it.

A- Click on the “MaxScript” button from the main toolbar, and choose the “Maxscript Editor” from the dropdown list, to open its dialog box.

B- Copy and paste the following text/script created by David, into the text field of the “Maxscript Editor” dialog:
     Fn ColourFromLayer =
(
                Local SelectionArr = (selection as array)
                Local myarr = #()
                for i in SelectionArr do append myarr i.wirecolor
                for i = 1 to SelectionArr.count do
                (
                                SelectionArr[i].colorByLayer = false
                                SelectionArr[i].wirecolor = myarr[i]
                )
)

maxscript

maxscript2

The next step is to “Evaluate” the script.

A- To do so, first open the “MaxScript Listener” dialog by pressing the “F11” key.
B-Next, select the “Maxscript Editor” dialog and press “Ctrl+E” to evaluate the script for any possible errors. Alternatively, simply go to “Tools” and choose the “Evaluate All” option from the dropdown list.

The “ColourFromLayer()” text should automatically appear in the text field of the “MaxScript Listener” dialog…without any red text errors.
Following that, select the entire imported drawing with the “Selection Region” tool.
listener

evaluate

color


To apply the script to the selected drawing, simply go to the text field of the “MaxScript Listener” dialog; ensure that a blinking vertical text bar is in front of the “ColourFromLayer()” text ,followed by pressing “Enter”. 

The “OK” text should appear, and the blinking vertical text bar should automatically jump below it…without any red text errors.

This is an indication that the script had been applied successfully.   

listener
To test whether or not the script will serve its purpose once the drawing is added into a new layer, first open the “Manage Layers” dialog by clicking on its button on the main toolbar.

While the drawing is still selected, create a new layer by simply clicking on its button in the “Manage Layers…” dialog. Also, re-name the layer. 

The entire content of the drawing should now be part of the newly created Layer, with the drawing’s original colours intact.  Press "Ctrl+D" to unselect everything in the 3ds Max Scene. 
manage layers

layer

If/when satisfied with the results, save the script by first selecting, right clicking and copying the “ColourFromLayer()OK” text from the “MaxScript Listener” dialog; followed by pasting it onto the “Maxscript Editor” dialog. Ensure the newly pasted text is below the existent ones.  
copy

color

Next, press “Ctrl+S” to save it as a *.mcr.* file format in an accessible shared location.

To quickly be able to deploy this script in future occasions, users often run it off the Max quad menu or as a toolbar button.
Too add it as a toolbar button, simply click on “Customize” main toolbar and choose the “Customize User Interface” option from the dropdown list.  

It's dialog should open. Under the “Toolbars” tab, create a new toolbar, by clicking on the “New” button.

In the “New Toolbar” dialog, name it accordingly and “OK” to close the dialog. A new toolbar button should automatically appear.  
customize

toolbars

customize

With the new toolbar button created, one can now close the “Customize User Interface” dialog.

Next, we are going to drag and drop the previously created script text in its entirety from the “Maxscript Editor” dialog into the newly created toolbar button.

button

An image button should automatically appear in the newly created toolbar.
To edit its appearance, simply right click on its image and choose to “Edit Button Appearance” from its pop up menu.

right click

The “Edit Macro Button” dialog should open. By default it is set to “Image Button”.

One can change it to “Text Button” type and name the “Label”, as well as the “Tooltip”. This action will allow users to see the name of the script on the button, as opposed to the previous default “Image button”. Once satisfied, “OK” to close the dialog.

color
Place the newly created toolbar close to the others, by simply clicking and holding on the top edge of its button; followed by dragging /placing it adequately.  

Finally, close and restart 3ds Max. The newly created toolbar button should now be visible/part of the main toolbar.   

To test whether the new toolbar is working or NOT, import a completely new drawing into 3ds Max.

Select the entire drawing as previously done and apply the script by simply clicking on the “ColourFromLayer” button created earlier.


apply script

Next, reselect the entire drawing and add it to a completely new layer as previously done.

As one can see: The drawing's original colours remained intact when added into a new layer...which is a clear indication that the new toolbar button worked as expected!

Tip: Adding a “#” before the layer name will ensure the newly created layer always stays on top of the list.  




I hope you have found this tutorial/article and the script useful!

0 comments:

Post a Comment

Live Translation!

Ads

Recent Posts!

Facebook Box

Popular Posts

Contact Form

Name

Email *

Message *

Powered by Blogger.