NanGlase Posted Friday at 03:18 PM Posted Friday at 03:18 PM (edited) Please, someone help me. I thought my program was in its final stages, but it is not. I used AutoCAD 2002 and 2007 during development, but when I tried to install it in AutoCAD 2021, this happened (see the picture). It prompts as if I need to edit the attributes one by one. Also, how can I eliminate the automatic prompts in the command line made by AutoCAD, while keeping the programmed prompts within the AutoLISP? (defun c:nancsv ( / fname dummy pts newline blockName height x y base-point auto-numbering num) (princ "\nImport CSV/Text File by: Nan Glase (2025-01-04)") ; (princ "\nEnter \"NANCSV\" to run.") ; (defun csv->lst ( str / pos ) (if (setq pos (vl-string-position 44 str)) ; (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2)))) ; (list str) ) ) ; Set the block name (setq blockName "Nan Glase") ; Prompt for text height (setq height (getreal "\nEnter text height [0.60]: ")) ; Prompt for text height ; If the user presses Enter without input (height is nil), set the default value to 0.60 (if (not height) (setq height 0.60) ) ; Apply the formula (value entered / 2) (setq height (/ height 2)) ; Divide the height by 2 ; Define acceptable inputs for Yes and No (setq yes-options '("" "Y" "y" "Yes" "yes" "YES")) (setq no-options '("N" "n" "No" "no" "NO")) ; Prompt for automatic point numbering in a loop until valid input is given (setq auto-numbering nil) (while (not (or (member auto-numbering yes-options) (member auto-numbering no-options))) (setq auto-numbering (getstring "\nAutomatic point numbering? (Yes/No): ")) ) ; Start numbering from 1 if automatic numbering is enabled (if (member auto-numbering yes-options) (setq num 1) (setq num nil) ; Set num to nil if automatic numbering is not enabled ) ; Open the CSV file (setq fname (open (getfiled "Import CSV/Text File" "d:\\" "csv;txt" 16) "R")) (setq dummy (read-line fname)) ; ; (while (setq newline (read-line fname)) (setq pts (csv->lst newline)) ; ; If automatic numbering is enabled, modify the first element in pts (if num (setq pts (cons (itoa num) (cdr pts))) ; ) ; Extract coordinates from the list (setq x (atof (nth 2 pts))) ; X coordinate from CSV (setq y (atof (nth 1 pts))) ; Y coordinate from CSV (setq base-point (list x y)) ; Create the base point list ; Insert the block reference with the specified base point (command "-insert" blockName ; base-point ; Use the base point defined above height ; Scale X (use the calculated height) height ; Scale Y (use the calculated height) 0 ; Rotation (nth 0 pts) ; column A from CSV (last pts) ; column E from CSV (nth 3 pts) ; column D from CSV ) ; Increment the number for the next point if automatic numbering is enabled (if num (setq num (1+ num)) ) ) ; Close the file after processing (close fname) ; Close the file ; Notify user that the process is complete (princ "\nProcess completed successfully!") ; Completion message (princ) ; End of the function ) ; (princ "\nImport CSV/Text File by: Nan Glase (2025-01-04)") (princ "\nEnter \"NANCSV\" to run Import CSV/Text File.") Nan Glase.dwg Edited Friday at 03:21 PM by NanGlase additional photo (csv) Quote
rlx Posted Friday at 04:29 PM Posted Friday at 04:29 PM (edited) classic case of setvar "ATTREQ" 0 at begin of routine? Same for setvar "CMDECHO" Edited Friday at 04:30 PM by rlx 1 Quote
BIGAL Posted Friday at 11:04 PM Posted Friday at 11:04 PM (edited) A few comments; Dont need CSV can read excel or Libre calc directly, search here for "Alan excel.lsp" it has lots of functions that you can use. Happy to discuss further. Yes or No, there is a Acet function "yes no", do a google, or you can use this radio buttons program which can be used in any code, there is a yes or no example at the top of the code. The other is to use a INITGET method. Multi radio buttons.lsp Ps why not add a point number in excel so easy to just do 1 & 2 column "A" then drag down to last cell. A Ps ps the code can update your excel re a point number adding to column "A". Edited Friday at 11:04 PM by BIGAL 1 Quote
NanGlase Posted Saturday at 01:29 AM Author Posted Saturday at 01:29 AM 2 hours ago, BIGAL said: A few comments; Dont need CSV can read excel or Libre calc directly, search here for "Alan excel.lsp" it has lots of functions that you can use. Happy to discuss further. Yes or No, there is a Acet function "yes no", do a google, or you can use this radio buttons program which can be used in any code, there is a yes or no example at the top of the code. The other is to use a INITGET method. Multi radio buttons.lsp Ps why not add a point number in excel so easy to just do 1 & 2 column "A" then drag down to last cell. A Ps ps the code can update your excel re a point number adding to column "A". Some of us use an RTK controller that exports survey data in a default CSV format without point numbering in column A, and others prefer to import it into AutoCAD with fewer attributes for a clearer drawing window. So I added an option for automatic numbering or not. Quote
GLAVCVS Posted Saturday at 10:12 AM Posted Saturday at 10:12 AM (edited) Don't use '(command "-insert"... ' Use the function I attached instead. Of course: this function assumes that the invoked block is already defined by the user and contains the attributes specified in the argument list. This, i think, will solve all your problems (defun insertBlk (nmBlk east north npt elev descr / fijAtributos insertaBlqAtrbs) (defun fijAtributos (vlaEntBlq nPto cota descripcion / attr-list attr-postion Attr_Object lisAtributos ) (setq lisAtributos (safearray-value (variant-value (vla-getattributes vlaEntBlq ) ) ) ) (VLAX-PUT-PROPERTY (nth 0 lisAtributos) "TextString" nPto) (VLAX-PUT-PROPERTY (nth 1 lisAtributos) "TextString" cota) (VLAX-PUT-PROPERTY (nth 2 lisAtributos) "TextString" descripcion ) ) (defun insertaBlqAtrbs (nombre pt_ins) (vla-InsertBlock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) (vlax-3d-point pt_ins) nombre 1 1 1 0 ) ) (setq vlaEntBlq (insertaBlqAtrbs nmBlk (list east north))) (fijAtributos vlaEntBlq npt elev descr) ) ;;;(insertBlk "Nan Glase" 400000 4500000 "1" "333.33" "My description") Edited Saturday at 10:27 AM by GLAVCVS 1 Quote
NanGlase Posted Saturday at 04:23 PM Author Posted Saturday at 04:23 PM 6 hours ago, GLAVCVS said: Don't use '(command "-insert"... ' Use the function I attached instead. Of course: this function assumes that the invoked block is already defined by the user and contains the attributes specified in the argument list. This, i think, will solve all your problems (defun insertBlk (nmBlk east north npt elev descr / fijAtributos insertaBlqAtrbs) (defun fijAtributos (vlaEntBlq nPto cota descripcion / attr-list attr-postion Attr_Object lisAtributos ) (setq lisAtributos (safearray-value (variant-value (vla-getattributes vlaEntBlq ) ) ) ) (VLAX-PUT-PROPERTY (nth 0 lisAtributos) "TextString" nPto) (VLAX-PUT-PROPERTY (nth 1 lisAtributos) "TextString" cota) (VLAX-PUT-PROPERTY (nth 2 lisAtributos) "TextString" descripcion ) ) (defun insertaBlqAtrbs (nombre pt_ins) (vla-InsertBlock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) (vlax-3d-point pt_ins) nombre 1 1 1 0 ) ) (setq vlaEntBlq (insertaBlqAtrbs nmBlk (list east north))) (fijAtributos vlaEntBlq npt elev descr) ) ;;;(insertBlk "Nan Glase" 400000 4500000 "1" "333.33" "My description") how to replace "-insert" function with that code? Quote
GLAVCVS Posted Saturday at 07:38 PM Posted Saturday at 07:38 PM (edited) (defun c:nancsv (/ fname dummy pts newline blockName height x y base-point auto-numbering num csv->lst insertBlk ) (princ "\nImport CSV/Text File by: Nan Glase (2025-01-04)") ; (princ "\nEnter \"NANCSV\" to run.") ; (defun csv->lst (str / pos) (if (setq pos (vl-string-position 44 str)) ; (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2)))) ; (list str) ) ) (defun insertBlk (nmBlk east north npt elev descr / fijAtributos insertaBlqAtrbs ) (defun fijAtributos (vlaEntBlq nPto cota descripcion / attr-list attr-postion Attr_Object lisAtributos ) (setq lisAtributos (safearray-value (variant-value (vla-getattributes vlaEntBlq ) ) ) ) (VLAX-PUT-PROPERTY (nth 0 lisAtributos) "TextString" nPto) (VLAX-PUT-PROPERTY (nth 1 lisAtributos) "TextString" descripcion) (VLAX-PUT-PROPERTY (nth 2 lisAtributos) "TextString" cota ) ) (defun insertaBlqAtrbs (nombre pt_ins) (vla-InsertBlock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) (vlax-3d-point pt_ins) nombre 1 1 1 0 ) ) (if (tblsearch "block" nmBlk) (progn (setq vlaEntBlq (insertaBlqAtrbs nmBlk (list east north))) (fijAtributos vlaEntBlq npt elev descr) ) (progn (alert (strcat "ERROR: Block \'" nmBlk "\' is NOT DEFINED")) (if fname (close fname)) (exit) ) ) ) ; Set the block name (setq blockName "Nan Glase") ; Prompt for text height (setq height (getreal "\nEnter text height [0.60]: ")) ; Prompt for text height ; If the user presses Enter without input (height is nil), set the default value to 0.60 (if (not height) (setq height 0.60) ) ; Apply the formula (value entered / 2) (setq height (/ height 2)) ; Divide the height by 2 ; Define acceptable inputs for Yes and No (setq yes-options '("" "Y" "y" "Yes" "yes" "YES")) (setq no-options '("N" "n" "No" "no" "NO")) ; Prompt for automatic point numbering in a loop until valid input is given (setq auto-numbering nil) (while (not (or (member auto-numbering yes-options) (member auto-numbering no-options) ) ) (setq auto-numbering (getstring "\nAutomatic point numbering? (Yes/No): " ) ) ) ; Start numbering from 1 if automatic numbering is enabled (if (member auto-numbering yes-options) (setq num 1) (setq num nil) ; Set num to nil if automatic numbering is not enabled ) ; Open the CSV file (setq fname (open (getfiled "Import CSV/Text File" "d:\\" "csv;txt" 16) "R" ) ) (setq dummy (read-line fname)) ; ; (while (setq newline (read-line fname)) (setq pts (csv->lst newline)) ; ; If automatic numbering is enabled, modify the first element in pts (if num (setq pts (cons (itoa num) (cdr pts))) ; ) ; Extract coordinates from the list (setq x (atof (nth 2 pts))) ; X coordinate from CSV (setq y (atof (nth 1 pts))) ; Y coordinate from CSV (setq base-point (list x y)) ; Create the base point list ; Insert the block reference with the specified base point ;;; (command "-insert" ;;; blockName ; ;;; base-point ; Use the base point defined above ;;; height ; Scale X (use the calculated height) ;;; height ; Scale Y (use the calculated height) ;;; 0 ; Rotation ;;; (nth 0 pts) ; column A from CSV ;;; (last pts) ; column E from CSV ;;; (nth 3 pts) ; column D from CSV ;;; ) (insertBlk blockName x y (if num (itoa num) "") (nth 3 pts) (last pts)) ; Increment the number for the next point if automatic numbering is enabled (if num (setq num (1+ num)) ) ) ; Close the file after processing (close fname) ; Close the file ; Notify user that the process is complete (princ "\nProcess completed successfully!") ; Completion message (princ) ; End of the function ) ; (princ "\nImport CSV/Text File by: Nan Glase (2025-01-04)") (princ "\nEnter \"NANCSV\" to run Import CSV/Text File.") Edited Saturday at 08:08 PM by GLAVCVS Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.