Ramees Posted August 13, 2015 Posted August 13, 2015 Hello CAD Wizards, I am pretty new to the idea of lisp. However I have been using autocad scripts to get my job done. So what I want to do is create a lisp function so that it reads the x , y coordinate and the point number from a csv or excel file and inserts an existing block with an attribute at that coordinate with the attribute taken the point number. Any help in writing this lisp is hugely appreciated. And let me say this again Im a noob to auto lisp Heres the excel file coo.xlsx The data is in the Format Point Xcor Ycor Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 Welcome to CADTutor new wizard. What is the name of your attributed block that SHOULD be existed into your drawing when you try my coming program ? Quote
Ramees Posted August 13, 2015 Author Posted August 13, 2015 Its is Block1 Can it be prompted from user if its not too much complex:notworthy: Because I have different types of blocks that needs to be inserted Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 Its is Block1Can it be prompted from user if its not too much complex:notworthy: Because I have different types of blocks that needs to be inserted Sure Give this a go and let me know . (defun c:test (/ _parse do sp bk bn f on st l) ;; Tharwat 13.08.2015 ;; (setq do (vla-get-activedocument (vlax-get-acad-object)) sp (vla-get-block (vla-get-activelayout do)) ) (cond ((not (and (setq bn (getstring t "\nSpecify name of the Attributed Block Name :" ) ) (/= bn "") (tblsearch "BLOCK" bn) ) ) (princ (strcat "\nEmpty value or Block name < " bn " > is not existed in current drawing !" ) ) ) ((setq f (getfiled "Select Excel file :" (getvar 'dwgprefix) "csv" 16 ) ) (setq on (open f "r")) (defun _parse (s / pos lst) (while (setq pos (vl-string-search ";" s 0)) (progn (setq lst (cons (substr s 1 pos) lst)) (setq s (substr s (+ pos 2) (strlen s))) ) ) (if (and s (/= s "")) (setq lst (cons s lst)) ) (setq lst (reverse lst)) ) (while (setq st (read-line on)) (if (and (setq l (_parse st)) (= (length l) 3) (setq bk (vla-insertblock sp (vlax-3d-point (read (cadr l)) (read (caddr l))) bn 1.0 1.0 1.0 0. ) ) ) (vla-put-textstring (car (vlax-invoke bk 'getattributes)) (car l) ) ) ) (close on) ) ) (princ) )(vl-load-com) Quote
Ramees Posted August 13, 2015 Author Posted August 13, 2015 Hmm Tried It but not working... It asks for the Block name and on giving the block name it asks to open the csv file. But on opening the file nothing happens:unsure: Heres the block if u want to test just in case 800.dwg And here is the script that i currently use to do this 800.scr Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 Save as the Excel file to format csv and try again. Quote
Ramees Posted August 13, 2015 Author Posted August 13, 2015 I tried with the csv file itself. Could you take a look at my script file and verify the lisp create command in the same order Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 I gave you a complete program and there is no need for any other scripts or so. 1- You should have the attributed block existed into your current drawing that you run the program on . 2- The Excil file should be in format csv. Quote
Ramees Posted August 13, 2015 Author Posted August 13, 2015 No I wasnt using the script And yes I tried with the csv file not excel file Is there a problem with how I am loading the lisp Here are the files i used coo.csv Test.lsp Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 The contents of the Excel file coo.csv that loaded in post #9 is not the same as the one you loaded in your first post format Go back to the program and replace the semicolon ( ; ) with comma ( , ) . (vl-string-search [color="#ff00ff"]";"[/color] s 0) To become like this . (vl-string-search [color="#ff00ff"]","[/color] s 0) Quote
Ramees Posted August 13, 2015 Author Posted August 13, 2015 YAAY!!!!! It Worked Sorry for the misuderstanding due to file. I converted it using excel itself. And Thank you soo Much:roll: Quote
Tharwat Posted August 13, 2015 Posted August 13, 2015 YAAY!!!!! It Worked Sorry for the misuderstanding due to file. I converted it using excel itself. And Thank you soo Much:roll: Nice, you are most welcome. 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.