benlconstructors Posted April 22 Posted April 22 used chatgpt to get me this code but it generates this error "error: Automation Error. Problem in loading application" any ideas? (defun c:MGC ( / filePath fileLine fileHandle parts ptNum north east elev desc fileName newLayerName acadApp doc layMan layObj civApp civDoc pointsObj groupColl newGroup lastPoint centerPt lineCount existingGroup) ;; Step 1: Open file (setq filePath (getfiled "Select CSV File" "" "csv" 0)) (if (not filePath) (progn (alert "No file selected.") (exit) ) ) ;; Step 2: Save file name (setq fileName (vl-filename-base filePath)) ;; Step 3: Create new layer (setq newLayerName (strcat "Points - " fileName)) (setq acadApp (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadApp)) (setq layMan (vla-get-Layers doc)) (if (not (tblsearch "LAYER" newLayerName)) (progn (setq layObj (vla-Add layMan newLayerName)) (vla-put-Color layObj 3) ) ) ;; Step 4: Make new layer active (vla-put-ActiveLayer doc (vla-Item layMan newLayerName)) ;; Step 5: Civil 3D setup + Point Group (setq civApp (vla-getInterfaceObject acadApp "AeccXUiLand.AeccApplication.24")) (setq civDoc (vla-get-ActiveDocument civApp)) (setq groupColl (vla-get-PointGroups civDoc)) ;; Delete existing group with same name if it exists (vlax-for g groupColl (if (= (strcase (vla-get-Name g)) (strcase fileName)) (vla-Delete g) ) ) ;; Create new group (setq newGroup (vla-Add groupColl fileName)) (vla-put-IncludeAllPoints newGroup :vlax-true) ;; Step 6: Read and import points (setq pointsObj (vla-get-Points (vla-get-Points civDoc))) (setq fileHandle (open filePath "r")) (if (not fileHandle) (progn (alert "Unable to open the selected file.") (exit) ) ) (setq lineCount 0) (while (setq fileLine (read-line fileHandle)) (setq parts (vl-string->list fileLine ",")) (if (>= (length parts) 5) (progn (setq ptNum (nth 0 parts)) (setq north (atof (nth 1 parts))) (setq east (atof (nth 2 parts))) (setq elev (atof (nth 3 parts))) (setq desc (nth 4 parts)) (setq lastPoint (vlax-3d-point (list east north elev))) (vla-Add pointsObj lastPoint desc) (setq lineCount (1+ lineCount)) ) ) ) (close fileHandle) ;; Warn if no valid points were imported (if (= lineCount 0) (alert "No valid points were imported. Please check the file format.") ) ;; Step 7: Zoom to last point (if lastPoint (progn (setq centerPt (vlax-get lastPoint 'Coordinates)) (vla-ZoomCenter acadApp (vlax-3d-point (list (car centerPt) (cadr centerPt) 0)) 50.0) ) ) (princ) ) MGC.lsp Quote
aridzv Posted April 22 Posted April 22 (edited) can you share CSV example? Edited April 22 by aridzv Quote
rlx Posted April 22 Posted April 22 (edited) two options : add (vl-load-com) , either the very first or last line in your lisp file. number 2 : (setq civApp (vla-getInterfaceObject acadApp "AeccXUiLand.AeccApplication.24")) I have never worked with civil but it could be application name is incorrect. I'm sure others here on CadTutor can show you how to check this name or have a way to find out (assuming like AutoCad , Civil also comes in different versions). I believe Bigal is quite experienced on this subject. Edited April 22 by rlx Quote
GLAVCVS Posted April 22 Posted April 22 Hi I think there are several functions in your code that aren't implemented in VLISP: vla-get-PointGroups vla-put-IncludeAllPoints... and possibly some more. Quote
GLAVCVS Posted April 22 Posted April 22 Regarding the call to 'vla-get-interface-object' try changing 24 to 13.6 Quote
BIGAL Posted April 23 Posted April 23 One of the things I did to my CIV3D is made a custom menu, rather than keep swapping workspaces I just made a custom menu with CIV3D commands in it, for common tasks, in your case "ImportXYZ" so if you use CUI you can find the CIV3D commands, so the one your looking for is "_AECCIMPORTPOINTS". Yes there is sample code included with CIV3D on how to import points using VL. But honestly it's easier to just type the correct command, in my case pick on a pop menu. This also takes into account description keys. Just a comment "AeccXUiLand.AeccApplication.24" may fail as every now and then with new CIV3D version the number changes, so you can read the registry and get correct version. vercheck.lsp I have a lot of CIV3D stuff. The smartest is using a toolbar for setting surface styles. No need to use Toolspace, A Ps have same for Bricscad Civil also way easier to change compared to CIV3D. Quote
SLW210 Posted April 23 Posted April 23 "error: Automation Error. Problem in loading application" means it's not getting the correct version. Like mentioned, post the CSV file. I just wrote a code a few days ago for myself, I did have a version that set the layer, I might still have that. I have 4 columns, x,y,z and some text, the z is placed at 0 elevation with text for the z and the other text placed near the point. It could use refinement, but does what I need. Quote
BIGAL Posted April 24 Posted April 24 (edited) @SLW210 something for you to play with a full version and a cut down version. Real data. Playing with string cogo points in Bricscad Civil. known as spaghetti as that is what it looks like when you get it wrong SURVTUT.XYZ-2.csv SURVTUT.XYZ.csv Dwg from Bricscad Taking the request "Aotomatic cogo point import from csv file" if you have CIV3D then look down deep in the sample code I think it was API or ACTIVEX directory, and it has all the code for import points using VL. Pretty sure was a VBA version as well. Will see if I can find it. survtut plain.dwg Edited April 24 by BIGAL Quote
SLW210 Posted April 24 Posted April 24 I originally created a Script for the engineer with LT for doing just the points, it also worked just fine. Multiple Point ; Add your coordinates below x,y,z x,y,z x,y,z x,y,z IIRC, there are probably several LISPs out there and several different scripts, I just needed point with z = 0 in the main file which is 2d, with the text information and z value so rolled my own. @BIGAL My LISP ran your CSV just fine. I think I commented it pretty good. I have some versions that draw a line through the points and placed on a specific layer. Maybe I still have those. ;;; Import State Plane Coordinates (Four columns in CSV) ;;; ;************************************************************************************************** ;************************************************************************************************** ;;; ;;; By SLW210 (a.k.a. Steve Wilson) ;;; ;;; April 9, 2025 Original ;;; ;************************************************************************************************** ;************************************************************************************************** (defun c:ImpCSV (/ file line data label x y ztext pt fh) ;; Set point display to crosshairs (setvar 'PDMODE 34) (setvar 'PDSIZE 2.0) (setq file (getfiled "Select CSV File" "" "csv" 4)) ; Pick CSV file (if (and file (setq fh (open file "r"))) (progn (while (setq line (read-line fh)) (setq data (parsecsv line)) ; parse line to list ;; Make sure at least 4 columns (if (>= (length data) 4) (progn ;; Extract values (setq label (nth 0 data)) ; First column (setq x (atof (nth 1 data))) ; Second column (setq y (atof (nth 2 data))) ; Third column (setq ztext (nth (1- (length data)) data)) ; Last column ;; Build point (Z = 0) (setq pt (list x y 0.0)) ;; Place POINT (entmakex (list (cons 0 "POINT") (cons 10 pt))) ;; TEXT above (label) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 0.5) (cons 1 label) (cons 7 "Standard") (cons 72 1) (cons 11 pt) ) ) ;; TEXT below (ztext) (entmakex (list (cons 0 "TEXT") (cons 10 (list x (- y 0.5) 0.0)) (cons 40 0.5) (cons 1 ztext) (cons 7 "Standard") (cons 72 1) (cons 11 (list x (- y 0.5) 0.0)) ) ) ) ) ) (close fh) (princ "\nImport complete.") ) (princ "\nFile not selected or failed to open.") ) (command "_.zoom" "_extents") (princ) ) ;; CSV parse (defun parsecsv (line / pos lst tmp) (setq lst '()) (while (setq pos (vl-string-search "," line)) (setq tmp (substr line 1 pos)) (setq lst (append lst (list (vl-string-trim "," tmp)))) (setq line (substr line (+ pos 2))) ) (setq lst (append lst (list line))) lst ) Was this correct? I don't have Civil 3D, but if I get time I'll try with MAP 3D. SURVTUT_SLW210.dwg Quote
BIGAL Posted April 24 Posted April 24 (edited) A good bit of code @SLW210 have a look at this use the survtut.xyz-2.csv. After running your code. Yes worked with your code. It is very much code under development, I found that in the original software some 40 years ago it uses some other method of joining strings, the dwg I attached was edited as the result from the other software years ago. As it used a point library all line work was on correct layers. Point with 00 means its a point only so place a matching block if applicable, eg 00TR6 or TR6, would be the block "Tree6", expanding more TR6*6 was a 6m spread with a 600 trunk this used a dynamic block with 2 objects spread and trunk, which are resized to match, but was done only in CIV3D as a manual update. In the survtut.xyz.csv is extra point coding *C is close like pline, 01eb*02eb is string 02eb starts here at this point, *A is arc option 3 points if I remember correct. The Excel may be useful also its a dump from CIV3D description keys. Remove the XXXX had a client name there. Just a comment you can export the descriptions keys from CIV3D to Excel built in, but no import keys, so I wrote one. It is where I would start with a look up table. That is next step. spagetti.lsp Export of desc keys.xlsx Edited April 24 by BIGAL 1 Quote
SLW210 Posted April 25 Posted April 25 Nice @BIGAL On further review for the OP, doesn't Civil 3D already have the ability to import CSV with the data to COGO point. Maybe you need to explain a little more what you are looking to accomplish. It seems the OP has gone AWOL. Quote
troggarf Posted April 25 Posted April 25 5 hours ago, SLW210 said: It seems the OP has gone AWOL. Maybe so, but as a fly on the wall, I have been enjoying learning from you two as you share knowledge and experience Quote
SLW210 Posted April 25 Posted April 25 If time allows next week, I'll continue with exploring Map 3D, I haven't used it in a couple of years now. I might redo my LISP to add them to a specific layer (or create it), but I had hard coded it, I want to ask for the name next time. I did have it drawing a pline, but it was on all points ( in order), I only needed a pline between certain points (they all had the same identifier description). Main purpose was to place the points as 2D with just the text for Z and add in information as text as well (maybe add the option for 3D points and text locations). Does COGO create 3D? I cannot recall and didn't even think to try Map 3D for this job. The engineer heading this up has 2025 LT, was hoping to have it so he could update the drawing, but alas, the LISP doesn't work in LT. Maybe the option for PNEZD or PENZD? Quote
BIGAL Posted April 26 Posted April 26 Re open civ3D database you can use a check of current version and it corresponds to say a Acad year the number for a particular year may be 24. But as it’s LT doubtful that you can access database anyway, the code though should work in LT as it uses a cond to compare version number with a Civ3D version number, they are different. On iPad else would post code. Import points, string via code and create surface, re YMG triangulation lisp. Desired task. Importing points is easy but needs a lookup library, string points under development should work in LT2024+. If someone wants to have a go with LT try the code @SLW210 and I posted. Please let me know how it goes. Quote
SLW210 Posted April 27 Posted April 27 Mine does not work on LT, but the engineer didn't mention what the error was. I didn't have time at that point to work on it and since I had it done, it was low priority. IIRC, there is a line of code you can add to the LISP that returns the correct version. I can check tomorrow at work. Quote
BIGAL Posted April 28 Posted April 28 This is the old way, I very much doubt it will work in LT. I don't have LT ! I dont think LT will recognise the "AeccXUiLand.AeccApplication." as LT does not work with get Application for say Excel. Personally not needed to import points. ;vercheck.lsp version check for *aecc objects ; By Alan H (defun ah:vercheck ( / vrsn appstr) (vl-load-com) (if ((lambda (vrsn) (cond ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;09 ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;2010 ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;2011 ((vl-string-search "R18.2" vrsn) (setq appstr "9.0")) ;2012 ((vl-string-search "R19.0" vrsn) (setq appstr "10.0")) ;2013 ((vl-string-search "R19.1" vrsn)(setq appstr "10.3"));;2014 ((vl-string-search "R20.0" vrsn)(setq appstr "10.4"));;2015 ((vl-string-search "R20.1" vrsn)(setq appstr "10.5"));;2016 ((vl-string-search "R21.0" vrsn)(setq appstr "11.0"));;2017 ((vl-string-search "R22.0" vrsn)(setq appstr "12.0"));;2018 ((vl-string-search "R23.0" vrsn)(setq appstr "13.0"));;2019 ((vl-string-search "R23.1" vrsn)(setq appstr "13.2"));;2020 ((alert "This version of C3D not supported!")) ) ) (vlax-product-key) ) ; end if condition progn is true (progn (cond (*AeccDoc*) ((setq *AeccDoc* (vlax-get (cond (*AeccApp*) ((setq *AeccApp* (vla-getinterfaceobject (cond (*Acad*) ((setq *Acad* (vlax-get-acad-object))) ) (strcat "AeccXUiLand.AeccApplication." appstr) ) ) ) ) 'ActiveDocument ) ) ) ) ; end main cond ) ; end progn ) ; end if vsrn ) Would appreciate the numbers for 2021+ use About to see the numbers. The registry version, do apologise I don't have an author name. ; vercheck.lsp version check for *aecc objects ; uses registerycheck (defun ah:vercheck ( / vrsn appstr) (vl-load-com) (setq acApp (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1)) ) ) (setq *AeccDoc*(vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq *aeccDoc* (vlax-get-property *aeccdoc* "ActiveDocument")) (princ) ) Thats why just import the points using a look up table read a csv etc. The run the string program again using the look up table, working on that next when time permits. I guess if starting from scratch. 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.