alanjt Posted March 23, 2011 Posted March 23, 2011 ummmmm......hummmm......errrrrr......\scratch....... what? Put RM's lisp in a file.LSP, and put (RM:CSV->Layers "H:\\acad\\AutoCad Custom Support Folder\\Lisp Files\\ArchExist.csv") at the bottom (below everything). Quote
Nibster Posted March 23, 2011 Posted March 23, 2011 I think the current question is what is entered in the keyboard to run the routine? Isn't a (defun d:___ () ) missing? if L= line, R= rectangle, what does one type to run the posted lisp? Quote
alanjt Posted March 23, 2011 Posted March 23, 2011 I think the current question is what is entered in the keyboard to run the routine? Isn't a (defun d:___ () )[\code] if L= line, R= rectangle, what does one type to run the posted lisp?[/quote][code](defun c:GIMMIE (/) (RM:CSV->Layers "H:\\acad\\AutoCad Custom Support Folder\\Lisp Files\\ArchExist.csv") (princ)) Quote
MALICE Posted March 23, 2011 Posted March 23, 2011 Thank you alanjt! That is what I was missing. (both in the code and in knowledge) - If all you have is a hammer, everything looks like a nail. Quote
alanjt Posted March 23, 2011 Posted March 23, 2011 Thank you alanjt! That is what I was missing. (both in the code and in knowledge) - If all you have is a hammer, everything looks like a nail. No problem. You should look at the code I posted. It will allow you to just reference a drawing file and cut out a lot of typing. Quote
Lee Mac Posted March 23, 2011 Posted March 23, 2011 I think the current question is what is entered in the keyboard to run the routine? Isn't a (defun d:___ () ) missing? if L= line, R= rectangle, what does one type to run the posted lisp? Sometimes a subfunction offers more flexibility, since the user can create a multitude of wrapper functions to call it from, for example, another caller could be: (defun c:test nil (RM:CSV->Layers (getfiled "Select CSV File" "" "csv" "16")) (princ) ) Think of the 'RM:CSV->Layers' function as just another LISP function requiring a single argument (the CSV filename). Consider the '+' LISP function - this takes several numerical arguments (or parameters): (+ Arg1 Arg2 ... ArgN) An Example call could be: (+ 1 2 3) Return: 6 Now consider this defined subfunction: (defun Add2 ( x ) (+ x 2)) The above function takes a single numerical argument, 'x', and returns that number plus 2. We can call the above function like any other LISP function: (Add2 3) Returns: 5 Lee Quote
waders Posted March 23, 2011 Author Posted March 23, 2011 Okay I got this to work. Thanks for all this help. I couldn't ask for better service. Now next question. How do I Add the linetype import code in?? ;; Linetype check [color=blue];; <- Add linetype import code here, to avoid errors[/color] Quote
BIGAL Posted March 24, 2011 Posted March 24, 2011 I posted a reply last night but unfortuantely my internet stopped as I pressed submit. This may be usefull to others wondering how do I not hard code a layer name into a lisp/vba program. Any way I did something like you want but went a step further as we wrote a suite of programs and these were commercially available we had to allow the customer to use his layer names and colour and linetype. We also made a decision that the layers would be created dynamically only as required If you did not draw a wall then you had no wall layers. No need to load a 100 layers and then purge half of them back out again. Now how to do it (sorry no code its copyrighted) you read your csv file and create 3 variables layer1-name layer1-col layer1-lt for each line in the csv you end up with a lot of variables but it works. the example below is the bit of code cut out of every lisp routine ie sets layer name based on a lisp variable not a layer hard coded into the lisp program (setq lay_search roof--2) (setq lay_colour roof--2col) (setq l_type roof--2lin) (lay_miss) ; check for missing layers on the fly (defun lay_miss () within lay_miss it checks for layer name lay_search if not there creates with linetype and colour So if drawing roofs using the program it knows the name of your roof layers having read it from the csv file. You need an extra value in your csv file the name of your lisp variable For the serious programers this has the advantage that you can write a program once but have the output vary depending the clients drafting rules. Quote
pBe Posted March 24, 2011 Posted March 24, 2011 (edited) Guess I'm too late Anyways.... still using your original csv file format. inicated "y" (lowercase) if frozen blank if not (defun loadlayers ( csv / mLayer adoc layers ltype opf csv_lines ly_lst main_layer_list) ;;; sample by pBE ;;; (vl-load-com) (defun mLayer (lylst / Lnm nlt) (foreach ln lylst (setq Lnm (vl-catch-all-apply 'vla-add (list layers (car Ln)) ) ) (vla-put-color lnm (if (= (atoi (nth 2 ln)) 0) 7 (atoi (nth 2 ln)))) ([b]vla-put[/b]-description lnm (cadr ln)) (if (= nil (tblsearch "LTYPE" (setq nlt (nth 3 ln)))) (vla-add ltype nlt)) ([b]vla-put-[/b]linetype lnm nlt) (if (eq (nth 5 ln) "n") ([b]vla-put[/b]-Plottable lnm :vlax-false)) (if (eq (nth 6 ln) "y") ([b]vla-put[/b]-Freeze lnm :vlax-true)) ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) layers (vla-get-layers adoc) ltype (vla-get-linetypes adoc)) (vl-load-com) (setq opf ([b]open[/b] csv "r")) ([b]read-line[/b] opf) (while (setq csv_lines (read-line opf)) (while (setq parser (vl-string-search "," csv_lines)) (setq line_pr (substr csv_lines 1 parser) ly_lst (cons line_pr ly_lst) csv_lines (substr csv_lines (+ 2 (vl-string-search "," csv_lines))) ) ) (if (> (strlen csv_lines) 0) (setq ly_lst (cons csv_lines ly_lst))) (setq main_layer_list (cons (reverse ly_lst) main_layer_list) ly_lst nil) ) ([b]close[/b] opf) (mLayer main_layer_list) (princ) ) USAGE: (LOADLAYERS "D:\\Layer Creater\\ArchExist.csv") I opted not to check for existing layer, IMO company standards (if it is indeed a standard) is such because you need to adhere to it. so if by chance a user change a color.linetype on model space, running the routine will revert it back to its original,if theres any editing to be done with the layers might as well do it with VPLAYER Also i would suggest to the OP to standardized color as integers and not string (maybe thats why i had a hard time parsing the string ) just my 2 cents Edited March 24, 2011 by pBe Quote
okaloosa_manderson Posted February 13, 2012 Posted February 13, 2012 I was able to get this lisp to work perfectly with the exception of pulling the LWeight of the layer from the .csv to AutoCAD. Any Ideas where I went wrong? I used the code that pBe uploaded as a base and the original .csv edited with my layer names, descriptions, colors, ltype and plot (on or off). I tried setting the lineweight to mm, inches and just a number value in the cell but it still didn't pull it into AutoCAD. Any help is appreciated! Quote
fixo Posted February 14, 2012 Posted February 14, 2012 (edited) I see in this .csv file lineweights aren't added add them in appropriate column yourlsef, then run something like: ;;; thanks to pBE (defun loadlayers ( csv / mLayer adoc layers ltype opf csv_lines ly_lst main_layer_list) ;;; sample by pBE ;;; (defun mLayer (lylst / Lnm nlt) (foreach ln lylst (setq Lnm (vl-catch-all-apply 'vla-add (list layers (car Ln)) ) ) (vla-put-color lnm (if (= (atoi (nth 2 ln)) 0) 7 (atoi (nth 2 ln)))) (vla-put-description lnm (cadr ln)) (if (= nil (tblsearch "LTYPE" (setq nlt (nth 3 ln)))) (vla-add ltype nlt)) (vla-put-linetype lnm nlt) (vl-catch-all-apply 'vlax-put (list lnm 'lineweight (if (nth 4 ln)(atoi (nth 4 ln))))) (if (eq (nth 5 ln) "n") (vla-put-Plottable lnm :vlax-false)) (if (eq (nth 6 ln) "y") (vla-put-Freeze lnm :vlax-true)) ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) layers (vla-get-layers adoc) ltype (vla-get-linetypes adoc)) (setq opf (open csv "r")) (read-line opf) (while (setq csv_lines (read-line opf)) (while (setq parser (vl-string-search "," csv_lines)) (setq line_pr (substr csv_lines 1 parser) ly_lst (cons line_pr ly_lst) csv_lines (substr csv_lines (+ 2 (vl-string-search "," csv_lines))) ) ) (if (> (strlen csv_lines) 0) (setq ly_lst (cons csv_lines ly_lst))) (setq main_layer_list (cons (reverse ly_lst) main_layer_list) ly_lst nil) ) (close opf) (mLayer main_layer_list) (princ) ) ;;Autoload: (loadlayers "D:/Programming/Lisp/LAYERS/Layer Creater_NT/ArchExist.csv");<-- change a path here (vl-load-com) (princ) Your .csv file must be looking like this, lineweights are as integers: in the first line there is no linewieght, so this layer will be created with default lineweight settings, e.g.: A-ANNO,Architectural General Notes_ Key Notes,white,Continuous,,,A-ANNO-CLNG,Ceiling General Notes_ Key Notes,white,Continuous,53,, ETC ETC Edited February 14, 2012 by fixo code added Quote
okaloosa_manderson Posted February 14, 2012 Posted February 14, 2012 I used your code and created test.lsp and used the original ArchExist.csv file but inserted a few different variables into the existing columns to varify all columns were working. I still couldn't get the lineweight to pull in to AutoCAD with your .lsp code either. I have attached the two files that I used. Thank again for your imput! Also...I noticed you have to put \\ inbetween folders for your filename in order for it to function properly. (ie: C:\\documents and settings\\desktop\\*filename*.csv test.lsp ArchExist.csv Quote
fixo Posted February 14, 2012 Posted February 14, 2012 (edited) Your problem is on the decimals is not allowed in vlax-put function I used so you have to change: A-ANNO,Architectural General Notes_ Key Notes,122,Continuous,0.09,n,y on A-ANNO,Architectural General Notes_ Key Notes,122,Continuous,9,n,y and A-ANNO-CLNG,Ceiling General Notes_ Key Notes,123,Continuous,0.03,n, on A-ANNO-CLNG,Ceiling General Notes_ Key Notes,123,Continuous,30,n, as well as you are trying to add 0.03 see allowed values in lineweight combo in the layer toolbar say if you want use 0.53mm in this .csv file you have to use 53 without decimals see attached file, lisp code is from my post above ArchExist.csv Edited February 14, 2012 by fixo spell check Quote
okaloosa_manderson Posted February 14, 2012 Posted February 14, 2012 Works perfectly! I knew it was a user error and not a programmer error. I appreciate your help, sir! Quote
fixo Posted February 14, 2012 Posted February 14, 2012 Works perfectly! I knew it was a user error and not a programmer error. I appreciate your help, sir! You're welcome Happy coding Quote
waders Posted March 16, 2012 Author Posted March 16, 2012 Okay a little help need to fine tune this code again. A big thanks to everyone that posted to help me out last time. What my question is why isn't the LWeight's being read from my .csv file? I'm attaching the files see below. I was looking at "fixo" code on this post and his works but it's in "mm" & not in "inches" and it won't override all the setting on the layers if they already exist in the drawing. Any ideas? Anyone? Thanks archexist.lsp ArchExist.csv Quote
fixo Posted March 16, 2012 Posted March 16, 2012 I will try to help just tomorrow, some my own things happened Can you wait for? Quote
waders Posted March 16, 2012 Author Posted March 16, 2012 I will try to help just tomorrow, some my own things happenedCan you wait for? Yes, that would be fine. I'm not in a big hurry. Thanks Quote
fixo Posted March 16, 2012 Posted March 16, 2012 How about edited lisp see attached archexist-v.1.lsp Quote
waders Posted March 19, 2012 Author Posted March 19, 2012 How about edited lispsee attached Sorry didn't seem to fix it. 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.