Batch convert milometers to meters as drawing units

I tried to write a lisp but leave error "defconst", no idea how to solve because new in BricsCAD

		(defun c:MM2M (/ folder path scale-factor files)
		;; Define the scale factor from mm to m
		(setq scale-factor 0.001)
		
		;; Prompt user to select the folder containing the DWG files
		(setq folder (getfolder "Select folder with DWG files to convert"))
		
		;; If a folder was selected
		(if folder
			(progn
			;; Retrieve all DWG files in the selected folder
			(setq files (vl-directory-files folder "*.dwg" 1))
			
			;; Process each file
			(foreach path files
				;; Open each file
				(command "_.open" (strcat folder "\\" path))
				(princ (strcat "\nProcessing file: " path))
				
				;; Scale all entities in the drawing by 0.001
				(command "_.scale" "all" "" '(0 0 0) scale-factor)
				
				;; Save and close the file
				(command "_.qsave")
				(command "_.close")
				
				(princ (strcat "\nFile saved after conversion: " path))
			)
			)
			(princ "\nNo folder selected.")
		)
		
		;; Completion message
		(princ "\nAll files in the selected folder have been converted from mm to m.")
		(princ)
		)

Comments

  • Ok maybe a simple answer, once the code hits this line and opens a dwg that is the end of your lisp file, a lisp can not continue onto a new dwg, you can use a script and open a dwg, load a lisp and run it, use (yourfunctionname) as last line etc dont forget the C: if in defun name.

    (command "_.open" (strcat folder "\\" path))
    

    An alternative is because task is simple you can use OBDX, it modifies a dwg without opening it. Check out Lee-mac OBDX just google.

  • Rather than rescale the objects, you could reset set the units from unitless or millimetres to metres, so that 1 unit = 1 metre.

  • The real problem i found is that i need rescale line type, layouts, dimensions, and problably more things

  • Using Ltscale and in layouts the viewports Psltscale can help. Dimensions can have a scale factor so 2400 becomes 2.4, look at dimlfac.