TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ChrisCarlson on July 01, 2013, 11:55:24 AM
-
Hitting writers block here, my lisp will only create the 50th line or what ever line is set in the (repeat n ) function. I have approximately 1500~ lines in the text file. Any advice?
;**************************************
;CREATE PART NUMBER BLOCK
;**************************************
(defun C:csvblock (/ pt01)
(if (findfile "e:/lisps/csvblock.txt")
(progn
(setq btable (open "e:/lisps/csvblock.txt" "r"))
(repeat 50 (setq partnumber (read-line btable)))
(close btable)
) ; end progn
(alert "FILE NOT FOUND!")
) ; end if
(entmake
(list
(cons 0 "BLOCK") ; entity
(cons 2 partnumber) ; block name
(cons 70 2) ; block type
(list 10 0.0 0.0 0.0) ; base point
) ; end list
) ; end entmake
(entmake
(list
(cons 0 "TEXT") ; entity
(cons 8 "SYS-Bom_Part_Numbers") ; layer
(list 10 0.0 0.0 0.0) ; base point
(cons 40 0.035) ; text height
(cons 1 partnumber) ; text string
(cons 50 0) ; text rotation
; (cons 7 "STANDARD") ; text style
(cons 72 10) ; text justification
) ; end list
) ; end entmake text
;**************************************
;START ANNOTATIVE / NO EXPLODE SEQUENCE
;**************************************
(entmake
(list
(cons 0 "ENDBLK")
(cons 8 "0")
)
)
(entget (cdr (assoc 330 (entget (tblobjname "BLOCK" partnumber)))))
(vl-load-com)
(setq BLOCKS
(vla-get-Blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
BLK (vla-Item BLOCKS partnumber)
)
(vla-put-explodable (vla-Item BLOCKS partnumber) :vlax-false)
(princ)
) ; end function
-
Maybe something like this:
;**************************************
;CREATE PART NUMBER BLOCK
;**************************************
(defun c:csvblock (/ _ readfile pt01)
(defun _readfile (filename / file result line)
(cond ((and (eq 'str (type filename)) (setq file (open filename "r")))
(while (setq line (read-line file)) (setq result (cons line result)))
(close file)
(reverse result)
)
)
)
;; (idt_readfile "c:\\test.csv")
(if (setq lst (_readfile "e:/lisps/csvblock.txt"))
(progn (vl-load-com)
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(foreach partnumber lst ; (if (eq (type partnumber) 'STR)
(entmake (list (cons 0 "BLOCK") ; entity
(cons 2 partnumber) ; block name
(cons 70 2) ; block type
(list 10 0.0 0.0 0.0) ; base point
) ; end list
) ; end entmake
(entmake (list (cons 0 "TEXT") ; entity
(cons 8 "SYS-Bom_Part_Numbers") ; layer
(list 10 0.0 0.0 0.0) ; base point
(cons 40 0.035) ; text height
(cons 1 partnumber) ; text string
(cons 50 0) ; text rotation
; (cons 7 "STANDARD") ; text style
(cons 72 10) ; text justification
) ; end list
) ; end entmake text
;**************************************
;START ANNOTATIVE / NO EXPLODE SEQUENCE
;**************************************
(entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
;; (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" partnumber)))))
(if (tblobjname "BLOCK" partnumber)
(vla-put-explodable (vla-item blocks partnumber) :vlax-false)
)
)
) ; end progn
(alert "FILE NOT FOUND!")
) ; end if
(princ)
) ; end function
Welcome to theswamp :)
-
Had a hunch (while was the way to go.
Thanks a bunch :kewl: