Code - Auto/Visual Lisp: [Select]:?:
(setq path "C:\\Users\\shrinand_bhedasgaonk\\Desktop\\stuff\\CAD Tools_1_3-18-2020\\Tools Electrical Automation\\block insert\\LegendDrawing.dwg") " " "\"" "W" "\"" " " "\"" "136.7826,17.7144,0.0000" "\"" " " "\"" "159.4299,-2.3621,0.0000" "\"" " " "\"" "\"" ")" ) ;_ end of strcat npfname ) ;_ end of write-line ) ;_ end of defun
Another one simple code with ObjectDbx:Code - Auto/Visual Lisp: [Select]
(defun import-block-def-and-insert (dwg-name block-name ins-params / adoc acad odbx def ext_def ref) ;| ;; imports and insert blocks to current dwg dwg-name : dwg filename with block block-name : block name ins-params : parameters for inserting block: '(("ins" . <>) ; insertion point . nil -> '(0. 0. 0.) ("rot" . <>) ; rotation angle. nil -> 0. ("x" . <>) ; x scale factor. nil -> 1. ("y" . <>) ; y scale factor. nil -> use x scale ("z" . <>) ; z scale factor. nil -> use y scale Call sample: (import-block-def-and-insert (getfiled "library file" "" "dwg" 4) "pik-ind-3d_section{0.7}" nil) (import-block-def-and-insert "C:\\Users\\shrinand_bhedasgaonk\\Desktop\\stuff\\CAD Tools_1_3-18-2020\\Tools Electrical Automation\\block insert\\LegendDrawing.dwg" "HCR22" (list (cons "ins" (getpoint "\nInsertion point : ")))) |; ) ;_ end of type ) ;_ end of = odbx ) ;_ end of vlax-make-variant ) ;_ end of vla-CopyObjects ) ;_ end of progn ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of if (if def (t '(0. 0. 0.)) ) ;_ end of cond ) ;_ end of vlax-3d-point block-name (t 1.) ) ;_ end of cond (t 1.) ) ;_ end of cond (t 1.) ) ;_ end of cond (t 0.) ) ;_ end of cond ) ;_ end of vla-insertblock ) ;_ end of setq ) ;_ end of progn ) ;_ end of defun ref ) ;_ end of defun ;| ;; example command (defun c:isfod (/ doc) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (import-block-def-and-insert "C:\\Users\\shrinand_bhedasgaonk\\Desktop\\stuff\\CAD Tools_1_3-18-2020\\Tools Electrical Automation\\block insert\\LegendDrawing.dwg" "HCR22" (list (cons "ins" (getpoint "\nInsertion point : "))) ) ;_ end of import-block-def-and-insert (vla-endundomark doc) (princ) ) ;_ end of defun |;
Another one simple code with ObjectDbx:Code - Auto/Visual Lisp: [Select]
(defun import-block-def-and-insert (dwg-name block-name ins-params / adoc acad odbx def ext_def ref) ;| ;; imports and insert blocks to current dwg dwg-name : dwg filename with block block-name : block name ins-params : parameters for inserting block: '(("ins" . <>) ; insertion point . nil -> '(0. 0. 0.) ("rot" . <>) ; rotation angle. nil -> 0. ("x" . <>) ; x scale factor. nil -> 1. ("y" . <>) ; y scale factor. nil -> use x scale ("z" . <>) ; z scale factor. nil -> use y scale Call sample: (import-block-def-and-insert (getfiled "library file" "" "dwg" 4) "pik-ind-3d_section{0.7}" nil) (import-block-def-and-insert "C:\\Users\\shrinand_bhedasgaonk\\Desktop\\stuff\\CAD Tools_1_3-18-2020\\Tools Electrical Automation\\block insert\\LegendDrawing.dwg" "HCR22" (list (cons "ins" (getpoint "\nInsertion point : ")))) |; ) ;_ end of type ) ;_ end of = odbx ) ;_ end of vlax-make-variant ) ;_ end of vla-CopyObjects ) ;_ end of progn ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of if (if def (t '(0. 0. 0.)) ) ;_ end of cond ) ;_ end of vlax-3d-point block-name (t 1.) ) ;_ end of cond (t 1.) ) ;_ end of cond (t 1.) ) ;_ end of cond (t 0.) ) ;_ end of cond ) ;_ end of vla-insertblock ) ;_ end of setq ) ;_ end of progn ) ;_ end of defun ref ) ;_ end of defun ;| ;; example command (defun c:isfod (/ doc) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (import-block-def-and-insert "C:\\Users\\shrinand_bhedasgaonk\\Desktop\\stuff\\CAD Tools_1_3-18-2020\\Tools Electrical Automation\\block insert\\LegendDrawing.dwg" "HCR22" (list (cons "ins" (getpoint "\nInsertion point : "))) ) ;_ end of import-block-def-and-insert (vla-endundomark doc) (princ) ) ;_ end of defun |;
Thanks kpblc for your valuable time and efforts. These codes are working great !. Happy to learn from all of you lisp masters.
Regards,
Vincent
File could be opened or read-only mode. ObjectDBX requires full access to file.
Actually I check is file read-only (using vl-file-systime function and check file attributes). And if it does - I copy file to %temp% folder, proceed it and then erase it.
Also you can use vl-catch-* functions to catch any kind of errors.