Notifications
Clear all

[Closed] dwg batch importer

I need to create a batch importer to merge 180 dwg objects in a single 3ds max scene. I want my imported objects to be named as the *.dwg are (default naming is “layer:0” …)

the second wish is to align their pivots to the lower/left/back corner.

here is sample dwg and final max scene for testing : download

Anyone could help?

9 Replies

Hi loran,

I’ve had this lying around for a while – it doesn’t deal with nested blocks in the dwgs so you need to explode everything in autocad before you import, also you need to set the import options first on a test file in the same session (no way around this as far as I know since you can’t directly set the import options in maxscript). If you want to set pivots then you need to insert some code in the selection loop or post-process everything after the import process is complete.

 
--get the folder for file imports
importdir = getSavePath import files
--specify import file type
files = getFiles (importdir+("\*.dwg"))
for i in files do
(
 --for each file in the folder do the following
 --import
 importFile i #noPrompt
 --NB. check the dialogue values first esp. weld threshold
 --uses the defaults from the import dialogue ie. the last values set
 --
 --select all the objects inc those already frozen in the scene
 max select all
 --get rid of those already frozen from the selection
 --ie.previously imported and grouped objects
 --since max selects objects regardless of their frozen state
 --in maxscript
 for s in selection do
  (
   if s.isFrozen == true do
   deselect s
  )
 --group these objects under the dwg name
 group selection name:(filenameFromPath i)
 --freeze them so that the next imported set can be isolated
 max freeze selection
 --deselect everything to clear selected frozen objects from the set.
 max select none
 --and repeat until all the files are done
)
max unfreeze all
--all unfrozen and ready for editing
--save the file
getMaxSaveFileName filename: "converted dwgs"
--

Alex

thanks!!
I don t really understand how this works. When I use your script, 2 separate files are grouped in the name of one of them.

forget about the pivot, I can do that with massive selection.
I found a script on scriptspot.com nammed “batchImporter”. It s correct but do not rename the object as the dwg.

I’m sure I could update that script to use the source file name as the object names as an option.

So do it please!

I found a question

If you have five dwg files, after impoter

You will find three groups , not five groups , why ?

I don t want no groups! one dwg = one object in the max scene

Ok I got it!
You have to manualy import a single file first to set the dwg import options.
the next import will keep this settings

Thx Alex!!

–get the folder for file imports
importdir = getSavePath import files
–specify import file type
files = getFiles (importdir+(“*.dwg”))

max select all
max freeze selection
max select none

for i in files do
(
–for each file in the folder do the following
–import
importFile i #noPrompt
–NB. check the dialogue values first esp. weld threshold
–uses the defaults from the import dialogue ie. the last values set

–select all the objects inc those already frozen in the scene
max select all
–get rid of those already frozen from the selection
–ie.previously imported and grouped objects
–since max selects objects regardless of their frozen state
–in maxscript
for s in selection do
(
if s.isFrozen == true do
deselect s
)
–group these objects under the dwg name
– group selection name:(filenameFromPath i)
selection.name = filenameFromPath i

–freeze them so that the next imported set can be isolated
max freeze selection
–deselect everything to clear selected frozen objects from the set.
max select none
–and repeat until all the files are done
)
max unfreeze all
–all unfrozen and ready for editing
–save the file
getMaxSaveFileName filename: “converted dwgs”

I have a utility I use for this:

www.joshuanewman.net/scripts/download/JNimportV1.3.zip

It wont rename your objects to the name of the file, but it will group different files together under the name of the file, and create a named selection set of the objects. It will also assign random colours. You can also use it to translate into another format (using the export option) or even use it to merge max files together.
what more could you want?!?!?
since you want the objects attached to one another, use ther named selection sets that are created for you. attaching so many objects together could create memory problems so i would import the fiels first, save it and then begin attaching.

J.

not work, it does import and it does make the selection sets. but it does not group the objest. the most important feature in your script, why?
please help