For fun:
- (defun c:EHC () (c:ExportHandleCentroid))(defun c:ExportHandleCentroid (/ *error* wcs ss path acApp acDoc oSpace oShell file oRegion centroid) ;; RenderMan, 2012 ;; Special thanks to Lee Mac for demonstrating the region functionality! (princ "\rEXPORTHANDLECENTROID ") (vl-load-com) (defun *error* (msg) (if oShell (vlax-release-object oShell)) (if file (close file)) (if oRegion (vla-delete oRegion)) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; or (quit) ((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it (princ)) (prompt "\nSelect polylines to extract handle and centroid: ") (if (and (setq wcs (= 1 (getvar 'worlducs))) (setq ss (ssget '((0 . "LWPOLYLINE") (70 . 1)))) (setq path (strcat (vl-filename-directory (vl-filename-mktemp)) "\\Handles & Centroids.csv")) (setq acApp (vlax-get-acad-object)) (setq acDoc (vla-get-activedocument acApp)) (setq oSpace (vlax-get-property acDoc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))) (setq oShell (vla-getinterfaceobject acApp "Shell.Application"))) (progn (setq file (open path "w")) (write-line "Handle, X, Y, Z" file) (vlax-for oPline (setq ss (vla-get-activeselectionset acDoc)) (setq oRegion (car (vlax-invoke oSpace 'addregion (list oPline)))) (setq centroid (trans (vlax-get oRegion 'centroid) 1 0)) (vla-delete oRegion) (write-line (strcat (vla-get-handle oPline) "," (rtos (car centroid)) "," (rtos (cadr centroid)) "," (rtos (caddr centroid))) file)) (setq file (close file)) (setq oRegion nil) (vla-delete ss) (vlax-invoke oShell 'open path) (*error* nil)) (cond (wcs (*error* "Nothing selected")) (ss (*error* "No file specified")) ((*error* "The current drawing is not in WCS")))) (princ))
|