Search the Community
Showing results for tags 'import points'.
-
Aotomatic cogo point import from csv file
benlconstructors posted a topic in AutoLISP, Visual LISP & DCL
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- 15 replies
-
- lisp
- cogo points
-
(and 2 more)
Tagged with: