terra1982 Posted December 18, 2013 Posted December 18, 2013 Hello, Brand new here and running Carlson with Intellicad. Have just migrated from 18 years with Terramodel and am looking for a program to read a csv file and place the text in the open drawing. I have been doing my calculations in excel, export them into a csv file and have a macro that runs in Terramodel that will place the text. Looking to replicate this in AutoLISP. The format of the file is as follows: Layer, Text Style, Layout, X-cord, Y-cord, text value. The layers, text styles and layout are already defined in the template drawing. Very useful routine! Probally helpful to others as well. Thanks! Mark Quote
cwake Posted December 18, 2013 Posted December 18, 2013 I take it from your request that you can't simply copy and paste the data direct from the spreadsheet? You can do that several ways in AutoCAD, including as a table entity. Quote
satishrajdev Posted December 18, 2013 Posted December 18, 2013 I think You should create XYZ file with X-Y coords and text value..... Import that in Terramodel.... Terramodel is best software for this stuff... Why do you want routine??? BY the way Do you want to insert text value in cartographic format or plain text??? Quote
pBe Posted December 18, 2013 Posted December 18, 2013 I think You should create XYZ file with X-Y coords and text value..... Import that in Terramodel.... ... I have been doing my calculations in excel, export them into a csv file.. Makes me wonder what the RAW data looks like that you have to go thru excel.Maybe there's a way to cut the middleman and go straight to cad. It would be easier if is already in CSV format though. ....Terramodel is best software for this stuff... Why do you want routine??? Read... Looking to replicate this in AutoLISP . And the OP probably have a good reason unknown to most of us here. BY the way Do you want to insert text value in cartographic format or plain text??? Now if you really want to go with fancy stuff better throw in annotative properties to adjust with the scale of the map for printing. Quote
satishrajdev Posted December 18, 2013 Posted December 18, 2013 Makes me wonder what the RAW data looks like that you have to go thru excel.Maybe there's a way to cut the middleman and go straight to cad. It would be easier if is already in CSV format though. Terramodel really has good features to design data that why i guided him like that Quote
pBe Posted December 18, 2013 Posted December 18, 2013 Terramodel really has good features to design data that why i guided him like that I understand that satishrajdev, but again... Have just migrated from 18 years with Terramodel and am looking for a program to read a csv file and place the text in the open drawing... and Looking to replicate this in AutoLISP . So i'm guessing Terramodel is out of the question then. But i could be wrong Quote
terra1982 Posted December 18, 2013 Author Posted December 18, 2013 Can not just cut from excel into CAD. The text goes throughout the whole drawing. For example, the design flow of 330 gpd might be placed in 3 different places, the invert of the pipe in a nts profile and in a schedule of inverts, the clients name on 3 different sheets. I design septic systems for a living. I have a nice spread sheet in excel that does all the design calcs. I can set the bottom of a leach field and have the spread sheet calc all the inverts. (beg pipes, end pipes, top of stone, bottom of stone, d-box in and out, septic tank in and out). Being able to place these values any where in the drawing automaticaly is a huge time saver! Terramodel is out of the question. It is a great program for civil and surveyors. However, Trimble aquired them and does not produce any more updates. BTW, I started with Generic CAD 22 years ago and AutoCAD bought them. One update and then they abandoned the Generic CAD users. So, it is time to abandon Terramodel and move on... I had a TML (terramodel language) routine written to do this task for me 18 years ago and it runs perfect. I run the command it it instantly updates the drawing. I can change my template drawing at any time and just have to adjust the x-cord and y-cord in excel to have the text go to the proper place. Another nice feature would be to place a block instead of a text value at a specified x y coordinate. AutoLISP is a little beyond me capabilities(actually a lot). I looked at having excel write a dxf file but it looks like there is a lot of stuff in a dxf file. VBA does not run in Carlson with Intellicad engine. So, trying to find a way to do it with AutoLISP. I would be willing to compensate someone write it for me. Like I said it is a huge time saver for me. Thanks, Mark Quote
pBe Posted December 18, 2013 Posted December 18, 2013 ....I can change my template drawing at any time and just have to adjust the x-cord and y-cord in excel to have the text go to the proper place. Another nice feature would be to place a block instead of a text value at a specified x y coordinate. So, trying to find a way to do it with AutoLISP. I would be willing to compensate someone write it for me. Like I said it is a huge time saver for me. Thanks, Mark It is certainly doable, You mentioned on your first post.. ...to read a csv file and place the text in the open drawing. I have been doing my calculations in excel, export them into a csv file I assume the source data is already in CSV format, Yes? The format of the file is as follows:Layer, Text Style, Layout, X-cord, Y-cord, text value The layers, text styles and layout are already defined in the template drawing. Reading the CSV file is easy. Now that you have all the settings at the ready on your template, placing the "TEXT" or "BLOCK" if you prefer wouldn't be that hard. By "updating" you mean place the data on the drawing? or is that modify whats already there? I would be willing to compensate someone write it for me. Like I said it is a huge time saver for me. As for the compensation , there's quite a few forum members here offering their expertise [just click on the signature below the individual post]. But if you can wait a while somebody here will write it for you. IF its a rush job go ahead and exchange $ for services. A donation perhaps? its your call. pBe Quote
cwake Posted December 18, 2013 Posted December 18, 2013 Ahhh. I'm understanding you much better now and can see why what I suggested wouldn't work. It certainly could be done in AutoCAD. I'm unfamiliar with the use of LISP in Intellicad though. Are there any limitations? Or can you do everything as you would in AutoCAD? Quote
terra1982 Posted December 18, 2013 Author Posted December 18, 2013 Thanks for the welcome! The data is in csv. I wrote a macro in excel that exports my values to a csv. I can easily modify that if another format is better (space delimited) or more info is needed. Updating would be placing new values in the drawing. No need to replace or change existing. If i need to change something I delete by layer and run the import text function again. AutoLISP in Itellicadd is comparable. There might be a few odd ball things different but from what I see if it works in autocadd it will work in Intellicadd. Gladly donate or compensate, either works for me. Great utility for me and last item keeping me from migrating over from Terramodel. Thanks! Quote
cwake Posted December 18, 2013 Posted December 18, 2013 I won't promise anything, and certainly not in the short term, but elaborate, if you will, on what the ideal outcome would be. You speak of blocks. Are you talking about inserting a block as WELL as text, or instead? Or going a step further, are you talking about inserting a block with an attribute, the value of which comes from the spreadsheet? There's so many things you could do with this. I can't speak for Intellicad, but at least in AutoCAD, you could associate data with fields if that gave the best outcome.... Consider, if you would, your ideal outcome and describe it. If I did find time for it, I'd hate to create something that was a compromise and then have to change it. Quote
terra1982 Posted December 18, 2013 Author Posted December 18, 2013 Hello, The file would be a simple as this: LAYOUT,LAYER,STYLE,X-CORD,Y-CORD,TEXT, 22X34 LAND,INV BOLD,HAND,31,1.6,CATHY ENGEL, 22X34 LAND,INV BOLD,HAND,31,1.4,LOT 3 KEYES ROAD, 22X34 LAND,INV BOLD,HAND,31,1.2,WARREN MA, 22X34 LAND,INV BOLD,HAND,31,1,18 JULY 2012, Ignore the 1st line of the file.(header info) Then, place the text "CATHY ENGEL" ON THE 22X34 LANDSCAPE layout sheet, on the layer INV BOLD, with the text style HAND at the x-cord of 31 and the y-cord of 1.6. This would place that text in the lower right hand corner of my drawing (my title block). Then do this for the rest of the csv. Maybe to draw a block I could replace the text style with the word BLOCK and the text value with the block name. Something like: 22X34 LAND,INV BOLD,BLOCK,31,1.6,SEPTIC TANK.DWG, So, instead of placing text a block named SEPTIC TANK.DWG would be inserted at 31, 1.6 The blocks could all be stored in the same folder to simplify it. That is the goal, to just place the text or a block where specified. I am somewhat proficient at excel so what ever format is best for the csv i could make it happen. Thanks, Mark Quote
cwake Posted December 19, 2013 Posted December 19, 2013 Hi Mark, This would be my first run based on what you have said you need. As I said, I don't know if there are any limitations on the application of LISP in Intellicad. You also didn't say anything about text height, so I currently have it using the value of the current textsize variable. The text is MTEXT with a background mask as default. It's a start. (defun C:ImpDes ( / ;;All Functions declared locally ImpDes:err ImpDes:sav ImpDes:res parsestring layouts layers ;;Saved variables for restore ocmd olderr ;;Local Variables data file fileline objad lay ) (vl-load-com) (setq objad (vla-get-activedocument (vlax-get-acad-object))) ;******************************************************************* ; Error Handling, Save and Restore ;******************************************************************* (defun ImpDes:err (s / ) (if (/= s "Function cancelled") (if (= s "quit / exit abort") (princ) (princ (strcat "\nError < " s " >")) );if );if (ImpDes:res);restore environment (princ) ) ;--------------------------------------------------------- (defun ImpDes:sav ( / ) (vla-StartUndoMark objad) (setq ocmd (getvar "cmdecho") olderr *error* *error* ImpDes:err ) (setvar "cmdecho" 0) ) ;--------------------------------------------------------- (defun ImpDes:res ( / ) (setvar "cmdecho" ocmd) (setq *error* olderr); restore old *error* handler (gc);garbage collection (vla-EndUndoMark objad) (princ) ) ;;****************************************************************** ;; Local Functions ;;****************************************************************** (defun parsestring ( str / res found previous) (setq str (vl-string-right-trim "," str) found (vl-string-position 44 str 0) previous -1 ) (while (and found (< found (strlen str))) (setq res (cons (substr str (+ 2 previous) (- found previous 1)) res) previous found found (vl-string-position 44 str (1+ previous)) ) ) (setq res (cons (substr str (+ 2 previous)) res)) (reverse res) ) ;;****************************************************************** (defun layouts ( layout ) (if (and (not (member layout (layoutlist))) (/= layout "Model") ) (vla-add (vla-get-layouts objad) layout) ) ) ;;****************************************************************** (defun layers ( lay / objlay actlyr ) (if (null (tblsearch "LAYER" lay)) (vla-add (vla-get-layers objad) lay) (progn (setq objlay (vla-item (vla-get-layers objad) lay) actlyr (vla-get-name (vla-get-activelayer objad)) ) (vla-put-layeron objlay :vlax-true) (vla-put-lock objlay :vlax-false) (if (/= lay actlyr) (vla-put-freeze objlay :vlax-false) ) ) );if ) ;;****************************************************************** ;; Main Program Code ;;****************************************************************** (ImpDes:sav);Save variables for error handling (if (and (setq file (getfiled "Design File To Import" "" "csv" 4)) (setq file (open file "r")) ) (progn (read-line file) ;ignore header info (while (setq fileline (read-line file)) ;read whole file (if (/= fileline "") (setq data (append data (list (parsestring fileline)))) ;store data ) ) (close file) (foreach line data (if (and (>= (length line) 6) (apply 'and (mapcar (function (lambda ( x ) (> (strlen x) 0) ) ) line ) ) );and (progn (layouts (car line)) (layers (cadr line)) (if (= (strcase (caddr line)) "BLOCK") (if (tblsearch "BLOCK" (nth 5 line)) ;LAYOUT,LAYER,BLOCK,X-CORD,Y-CORD,BLOCKNAME (entmake (list '(0 . "INSERT") (cons 410 (car line)) ;layout (cons 8 (cadr line)) ;layer (cons 2 (nth 5 line)) ;blockname (cons 10 (list (atof (nth 3 line)) (atof (nth 4 line)) 0)) ;insert point ) ) (princ "\nBlockname does not exist in the drawing.") ) ;LAYOUT,LAYER,TEXTSTYLE,X-CORD,Y-CORD,TEXTSTRING (entmake (list '(0 . "MTEXT") '(100 . "AcDbEntity") (cons 410 (car line)) ;layout (cons 8 (cadr line)) ;layer '(100 . "AcDbMText") (cons 10 (list (atof (nth 3 line)) (atof (nth 4 line)) 0)) ;insert point [color=red](cons 40 (getvar "TEXTSIZE")) ;is textheight needed?[/color] (cons 1 (nth 5 line)) ;textstring (cons 7 (if (tblsearch "STYLE" (caddr line)) (caddr line) (getvar "TEXTSTYLE"))) ;textstyle '(90 . 3) '(63 . 256) '(45 . 1.15) ) ) );if );progn );if );foreach );progn );if (ImpDes:res);Restore variables for error handling );defun (Prompt "\nTHIS ROUTINE IMPORTS DESIGN DATA FROM CSV FILE (VERSION 0.0) by C.WAKEFIELD.") (Prompt "\nType ImpDes to run.") (princ) Quote
pBe Posted December 19, 2013 Posted December 19, 2013 (edited) Vanilla flavor: (defun c:demo (/ _delFinder collect _remd file data) ;; pBe Dec 2013 ;; [color="#006400"](defun _delFinder( str n / a b lst ) (while (/= "" str) (while (and (<= n (strlen str)) (not (wcmatch (Setq a (substr str 1 n)) "*`,*"))) (setq n (1+ n) b a)) (setq lst (cons b lst) str (substr str (1+ n)) n 1) ) (reverse lst) )[/color] ;;; cwakes' idea ;;; [color="#006400"](defun _layoutlist (/ lyt ll) (Setq lyt (dictsearch (namedobjdict) "ACAD_LAYOUT")) (while (setq a (assoc 3 lyt)) (setq ll (cons (cdr a) ll) lyt (cdr (member a lyt)))) (cdr ll) ) [/color] (setq collect (lambda (f / a b opf) (setq opf (open f "r")) (read-line opf) (while (setq a (read-line opf)) (setq b (cons (_delfinder a [color="#006400"][b]1[/b][/color]) b)) ) (close opf) b ) ) (setq _remd (lambda (lst / a b) (while (setq a (car lst)) (setq b (if (not (member a b)) (cons a b) b ) lst (cdr lst) ) ) b ) ) (and (setq file (getfiled "Select Data file" (getvar 'dwgprefix) "csv" 16) ) (setq data (collect file)) (foreach itm (_remd (mapcar 'car data)) (if (and (not (member itm (_layoutlist))) (snvalid itm) ) (command "_.layout" "_New" itm) ) itm ) (foreach itm (_remd (mapcar 'cadr data)) (if (and (not (tblsearch "Layer" itm)) (snvalid itm) ) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 itm) (cons 70 0) ) ) itm ) ) (foreach itm (_remd (mapcar 'caddr data)) (if (and (not (tblsearch "Style" itm)) (snvalid itm) ) (entmake (list '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") (cons 2 itm) '(70 . 0) '(40 . 0.0125) ;<-- Text height for style '(41 . 0. '(50 . 0.0) '(71 . 0) '(3 . "ARIAL.TTF") '(4 . "") ) ) itm ) ) (foreach info data (entmakex (list (cons 0 "TEXT") (cons 10 (setq p (list (distof (nth 3 info)) (distof (nth 4 info)))) ) (cons 11 p) (cons 8 (cadr info)) (cons 7 (caddr info)) '(40 . 0.0125) (cons 1 (nth 5 info)) '(71 . 0) '(72 . 1) '(73 . 2) (cons 410 (car info)) ) ) ) ) (princ) ) EDIT: sub with vl-string-position function replace Edited December 20, 2013 by pBe REdefine _delfinder Quote
cwake Posted December 19, 2013 Posted December 19, 2013 Vanilla flavor: (snvalid) Very good point!! I always forget that. It did cross my mind that I was duplicating the checking of existing layers and layouts - but I never thought of doing it like that. So (hopefully) I will be able to tuck that idea away for the future. I'm here to learn, pBe. So, if you don't mind, I'm curious if there was a specific reason you used the setq / lambda combination instead of another defun? Otherwise, I am curious as to whether LISP in Intellicad allows for the use of ActiveX methods. Hopefully the OP will give some feedback. Quote
terra1982 Posted December 19, 2013 Author Posted December 19, 2013 Hello, Not being an expert I would think that IntelliCAD AutoLISP would not support ActiveX methods. It is probably a simpler version and would support the long standing AutoLISP functions and coding methods. Nothing cutting edge. I tried both and got error messages. Do I need to place the csv file in a specific directory? Define anything specific in my template drawing? Any other OP actions? Here were the error messages: Command: impdes null function :error#0 Command: demo bad argument type :error#0 Thanks!! Mark Farrell Sturbridge, MA USA Quote
terra1982 Posted December 19, 2013 Author Posted December 19, 2013 btw, pBe you signature doesn't work and cwake you don't have a link... Quote
cwake Posted December 19, 2013 Posted December 19, 2013 Do I need to place the csv file in a specific directory? Define anything specific in my template drawing? Any other OP actions? You shouldn't have to. Both functions make use of the getfiled function which should present you with a dialogue box to browse and select the file. If you haven't seen the dialogue box, then both routines must have fallen over before they get to that. In the case of my routine, I would guess that "null function :error#0" means as you guessed... that ActiveX methods are not supported in Intellicad. Which means it will be better to start with pBe's routine and see why it thinks a function is being passed a "bad argument". Quote
terra1982 Posted December 19, 2013 Author Posted December 19, 2013 No dialog box presented... Can I embed statements in the code to see where it might have fallen over? Quote
cwake Posted December 19, 2013 Posted December 19, 2013 No dialog box presented... Can I embed statements in the code to see where it might have fallen over? You could, and I was thinking the same. Keeping in mind that I'm suggesting sticking with pBe's routine... First I'd check to see if Intellicad has a variable "dwgprefix". Because I'm thinking that there is most likely where it might fall over. There isn't much else to evaluate before that. Also as a method of "embedding statements", see if (defun c:helpme () (alert "This is debug location number 1") ) works? It should bring up an alert message in a box. 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.