Import files recursively in to AutoCAD

When there is a huge number of drawing files of various format (*.igs,*.stp etc) to be imported to AutoCAD, it's a hectic job doing it manually. It might takes weeks to import all those files manually. Well, good news is Visual Lisp has a solution for that doing it recursively. We discuss how to recursively import drawing files of different format to AutoCAD. Very useful tool for,

  • Industrial Design (including part or component design, tool making , tooling, Assembly design )
  • Small Components repetitively used in drawings like bolts, fastners, ferrules etc
What formats supported?

A 3-D graphic file used by any CAD software. 3D image data is stored in an ASCII format in these files, following the drawing standards. The files that can be imported in to AutoCAD are,

"*.ste" "*.stp" "*.step" ".dxf" "*.iges" 
"*.igs" "*.fbx" "*.sat" "*.ipt" "*.iam" 
"*.model" "*.session" "*.CATProduct"  
"*.dgn" "*.ij" "*.prt" "*.asm*" "*.3dm" 
"*.sldprt" "*.asm" "*.sldasm" "*.g" 
"*.x_b" "*.x_t" 

SPONSORED


The Main Routine - C:SFIMPORT() function

The main function enables command 'sfimport' in AutoCAD and calls for other sub-routine funcitons.

(defun c:sfimport()
       (setq path (ale_browseforfolder "Select directory to get files:"))      
       (setq ftype "*.step") 
       (setq flist (getfolders path ftype T)); change nil to T to get sub folders
  (alert "\n\n  Click OK to continue SFImport..")
            (stepImportRecursive  flist)	    
  (princ)
)

Looking to purchase AutoCAD 2019 (5 Seats)?



Store AutoCAD Environment Variables

Even though we are going to use a new AutoCAD file, it's alway better to store the AutoCAD Environment Variables in the memory. Let's use a function to do this.

(defun setup ()
   (command "_.undo" "_begin")
   (setq *cmdecho (getvar 'cmdecho))
   (setq *osmode   (getvar 'osmode))
   (setq *blipmode (getvar 'blipmode))
   (setq *delobj   (getvar 'delobj))
   (setq *splframe (getvar 'splframe))
   (setq *gridmode (getvar 'gridmode))
   (setq *ucsicon  (getvar 'ucsicon))  
   (setvar 'cmdecho 0)
   (setvar 'osmode 0)
   (setvar 'blipmode 0)
   (setvar 'delobj 1)
   (setvar 'splframe 1)  ;; edges must be visible for faces to be selectable
   (setvar 'gridmode 0)  ;; avoids flicker 
   (command "_.regen")
   (if (< 16 (atoi (substr (getvar "acadver") 1 2))) (setq R17 T))
   (if R17 (setq *solidhist (getvar 'solidhist)))
   (if R17 (setvar 'solidhist 0))
   (setq olderror *error*)
   (setq *error* myerror)

   )
                     
Read Directory Structure and Files

Before beginning to import, the first step is to read the directory structure and file names and storing it in a list.

(setq	folders	(get_folders path)) 
Here, the function is get_folders and the parameter is path.

Sign up to GS United Technologies to read full & complete article, Signup to GSUTech

Comments

Hello! Looks like you’re enjoying the discussion, but you haven’t signed up for an account yet. When you create an account, we remember exactly what you’ve read, so you always come right back where you left off. You also get notifications, here and via email, whenever someone replies to you.
Improve this page by sending your comments to admin. All user submitted comments are subject to moderation & approval.

You may not be able to post a comment if you are not Signed in. Sign in to post comments.
User Comments
No Comments yet!

Resources

  • Read Directory
    Import folder may have complex directory structures. First step is to read and store the directory structure and files in memory.

  • Setup AutoCAD Variables
    Setup AutoCAD Environment variables like FILEDIA = 0

  • Drawing file types
    With this importer several types of drawing files can be imported in to AutoCAD.

  • On Facebook

  • Get certified with Microsoft Certifications, azure certification through Microsoft Learning or azure courses Learn more