nghiahuu Posted July 1, 2009 Share Posted July 1, 2009 Can you help me??. Thanks. File excel.zip Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 1, 2009 Share Posted July 1, 2009 I wrote this a while back - will extract from a txt file. Assumes points are comma delimited. (defun c:ptpoly (/ doc spc file nl ptlst) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (setq file (getfiled "Select File" "" "txt" ) (progn (setq file (open file "r")) (while (setq nl (read-line file)) (setq ptlst (cons (StrBrk nl 44) ptlst))) (close file) (if ptlst (progn (setq ptlst (apply 'append (mapcar (function (lambda (x) (list (car x) (cadr x)))) (reverse (mapcar (function (lambda (x) (mapcar 'distof x))) ptlst))))) (vla-addLightweightpolyline spc (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length ptlst)))) ptlst)))) (princ "\n<< No Points Found in File >>"))) (princ "\n<< No File Selected >>")) (princ)) (defun StrBrk (str chrc / pos lst) (while (setq pos (vl-string-position chrc str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos 2)))) (reverse (cons str lst))) Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 2, 2009 Share Posted July 2, 2009 I have an Excel file can do what u want, but cant upload. I dont know why Please send me an email hasancad@gmail.com Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 2, 2009 Share Posted July 2, 2009 I think you need to Zip Excel files, as they are not a supported file upload type. Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 2, 2009 Share Posted July 2, 2009 I ziped as RAR in 2 files (as forum capacity) but cant uplod If you would I'll email to you, Quote Link to comment Share on other sites More sharing options...
eldon Posted July 2, 2009 Share Posted July 2, 2009 Don't zip it with RAR because that is not a commonly (for free) available format. Try saving your Excel file as a CSV file, and copy ten lines or so into your post. Quote Link to comment Share on other sites More sharing options...
fixo Posted July 3, 2009 Share Posted July 3, 2009 Can you help me??. Thanks. Try this one, just select the diapazone with numbers only Tested on A2008, Excel 2003 (vl-load-com) (defun C:PX (/ acapp acsp adoc aexc cel col cols coords csht item nwb points poly rang result row rows sht tmp wbks) (setq aexc (vlax-get-or-create-object "Excel.Application") wbks (vlax-get-property aexc "Workbooks") nwb (vlax-invoke-method wbks "Open" "C:\\File excel.xls");;<--change file name here sht (vlax-get-property nwb "Sheets") csht (vlax-get-property sht "Item" 1) ) (vla-put-visible aexc :vlax-true) (setq rang (vlax-invoke-method (vlax-get-property aexc "Application") "InputBox" "Select Diapazone To Get Coordinates" "Let you get a points" nil nil nil nil nil (vlax-make-variant 8 3)) ) (setq rang (vlax-variant-value rang) ) (setq coords (vlax-get-property rang "Value2") ) (setq rows (vlax-get-property (vlax-get-property rang "Rows") "Count") ) (setq cols (vlax-get-property (vlax-get-property rang "Columns") "Count") ) (setq row 1) (repeat rows (setq col 1) (repeat cols (setq cel (vlax-variant-value (vlax-get-property (vlax-get-property rang "Cells") "Item" (vlax-make-variant row vlax-vbLong) (vlax-make-variant col vlax-vbLong)))) (setq item (vlax-variant-value (vlax-get-property cel "Value2")) ) (setq tmp (cons item tmp) ) (setq col (1+ col) ) ) (setq points (cons (reverse tmp) points) tmp nil row (1+ row) ) ) (setq points (reverse points) points (apply 'append points) ) (vl-catch-all-apply (function (lambda () (vlax-invoke-method nwb "Close" :vlax-false))) ) (vl-catch-all-apply (function (lambda () (vlax-invoke-method aexc "Quit"))) ) (mapcar (function (lambda (x) (vl-catch-all-apply (function (lambda () (progn (vlax-release-object x) (setq x nil))))))) (list rang csht nwb wbks aexc) ) (setq adoc (vla-get-activedocument (setq acapp (vlax-get-acad-object)) ) ) (if (= 1 (vlax-get-property adoc "Activespace")) (setq acsp (vla-get-modelspace adoc)) (setq acsp (vla-get-paperspace adoc)) ) (setq poly (vlax-invoke acsp "Add3DPoly" points) ) (vla-eval acapp (strcat "ThisDrawing.SetVariable \"USERI1\"," "MsgBox (\"Close Polyline?\"," "vbYesNo" ",\"" "Answer this question:" "\")" ) ) (if (= 6 (setq result (getvar "USERI1"))) (vlax-put-property poly "Closed" :vlax-true) ) (vla-zoomextents acapp) (gc) (gc) (princ) ) (prompt "\t\t***\t\nType PX to run program\t***") (prin1) ~'J'~ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 3, 2009 Share Posted July 3, 2009 Try this one, just select the diapazone with numbers onlyTested on A2008, Excel 2003 Fixo, I could learn a lot from your code - I like the way you merge VBA and VL - didn't know you could do that like that. Lee Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 3, 2009 Share Posted July 3, 2009 download this file http://www.4shared.com/file/115732876/5917bc3/Excel2Autocad-03.html Quote Link to comment Share on other sites More sharing options...
eldon Posted July 3, 2009 Share Posted July 3, 2009 I downloaded the file, and saved it in csv format, deleted some columns and a row, and saved it in csv format again so that it looked like this:- 0,0,0 0.05,0.002,0.05 0.1,0.01,0.1 0.148,0.022,0.15 0.196,0.04,0.2 0.242,0.062,0.25 0.287,0.089,0.3 0.329,0.12,0.35 0.368,0.156,0.4 Then I opened the text file, selected all and copied, went to AutoCAD, started the 3D polyline command, and when it wanted a startpoint, I clicked on the command line and pasted, and here is what I got (without using Lisp). Quote Link to comment Share on other sites More sharing options...
fixo Posted July 3, 2009 Share Posted July 3, 2009 Fixo, I could learn a lot from your code - I like the way you merge VBA and VL - didn't know you could do that like that. Lee Thanks for the flowers Lee ) I was just grabbing all these things from Excel VBA Help and partially from my old experiences Regards, Oleg ~'J'~ Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 8, 2009 Share Posted July 8, 2009 eldon Fill in the point coordenate in the Excel file, then select the yellow cells next to the points you entered then copy (Ctrl+C) the selected area then paste in AutoCAD command line. Quote Link to comment Share on other sites More sharing options...
eldon Posted July 8, 2009 Share Posted July 8, 2009 eldon Fill in the point coordenate in the Excel file, then select the yellow cells next to the points you entered then copy (Ctrl+C) the selected area then paste in AutoCAD command line. I am not quite sure why you are telling me this, because I have already plotted your points as shown in the picture. I did not in fact use the yellow cells, but saved the file as a csv format, and worked from there. Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 8, 2009 Share Posted July 8, 2009 Why did you save the file as csv? Use the file as it is. Quote Link to comment Share on other sites More sharing options...
eldon Posted July 8, 2009 Share Posted July 8, 2009 I used it my way, and it worked. Why should I change? I am used to ASCII text data, and see no reason to complicate matters with further formatting. Quote Link to comment Share on other sites More sharing options...
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.