- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Erm. this code is a mess...
I need to make a selection set of a certain block.
Extract the coordinates of those blocks.
Sort them low to high by z.
Prefix each set of coordinates with a number incrementally from 1.
Annotate each block position on the drawing with that number.
Reorder each list row from NUM,X,Y,Z to NUM,Y,X,Z
Write the list to a csv text file
Text file example -
1,Y,X,Z
2,Y,X,Z
3,Y,X,Z
etc,
I've cobbled the code together a bit haphazardly, with a good helping of wrong, and guess what... It doesn't work.
Tried to test in VLIDE but get error "too many arguments:"
Have checked parenthesis.
Pretty sure the csv text file part is wrong but was just trying it to see what happened, although the routine never got going anyway...
(defun c:TNCL ()
(setvar 'Cmdecho 1)
(if (setq target_blocks (ssget "_X" '((0 . "INSERT") (2 . "PTAR")))) ;;; check for and select blocks
(repeat
(setq i (sslength target_blocks))
(setq target_coords (cdr (assoc 10 (entget (ssname target_blocks (setq i (1- i))))))) ;;; list of coordinates
(setq target_coords_by_z (vl-sort target_coords (lambda (PT1 PT2) (< (caddr PT1) (caddr PT2))))) ;;; sort low to high by z
)
(setq CSV (open (strcat (getvar "dwgprefix") (getvar "dwgname") ".txt") "w")) ;;; open text file to write to
(repeat
(setq i (sslength target_coords_by_z))
(setq i (1- i))
(setq xyz (entget (ssname target_coords_by_z i)))
(command "TEXT" xyz "" "" i) ;;; TEXT count number at coordinates
(setq numb_list '(strcat i (ssname target_coords_by_z i))) ;;; prefix list with count number
(setq NUM (car (ssname numb_list i))) ;;; separate items
(setq X (cadr (ssname numb_list i)))
(setq Y (caddr (ssname numb_list i)))
(setq Z (last (numb_list i)))
(setq list_to_export '(strcat NUM Y X Z)) ;;; reorder items into a list
(write-line (ssname list_to_export i) CSV) ;;; write line of list to txt file
)
(close CSV) ;;; close text file
)
(princ)
)
Solved! Go to Solution.