Jump to content

Recommended Posts

Posted

Hi am using this lisp but the secont time i try to use it gives me this error

 

VERTEXT - Error: bad argument type: listp <Entity name: 1cdf2de12f0>
SYSTEM VARIABLES have been reset

 

(defun ERR (S)
  (if (= S "Function cancelled")
    (princ "\nVERTEXT - cancelled: ")
    (progn (princ "\nVERTEXT - Error: ") (princ S) (terpri))
  )
  (RESETTING)
  (princ "SYSTEM VARIABLES have been reset\n")
  (princ)
)
(defun SETV (SYSTVAR NEWVAL)
  (setq X (read (strcat SYSTVAR "1")))
  (set X (getvar SYSTVAR))
  (setvar SYSTVAR NEWVAL)
)
(defun SETTING ()
  (setq OERR *ERROR*)
  (setq *ERROR* ERR)
  (SETV "CMDECHO" 0)
  (SETV "BLIPMODE" 0)
)
(defun RSETV (SYSTVAR)
  (setq X (read (strcat SYSTVAR "1")))
  (setvar SYSTVAR (eval X))
)

(defun RESETTING ()
  (RSETV "CMDECHO")
  (RSETV "BLIPMODE")
  (setq *ERROR* OERR)
)


(defun DXF (CODE ENAME) (cdr (assoc CODE (entget ENAME)))) ; dxf

(defun VERTEXT (/ EN VLIST)
  (setq EN (GET-EN))
  (if (= (DXF 0 EN) "LWPOLYLINE")
    (setq VLIST (GET-LWVLIST EN))
    (setq VLIST (GET-PLVLIST EN))
  )
  (WRITE-IT VLIST EN)
)

(defun GET-EN (/ NO-ENT EN MSG1 MSG2)
  (setq	NO-ENT 1
	EN     NIL
	MSG1   "\nSelect a polyline: "
	MSG2   "\nNo polyline selected, try again."
  )					; setq
  (while NO-ENT
    (setq EN (car (entsel MSG1)))
    (if	(and EN
	     (or (= (DXF 0 EN) "LWPOLYLINE") (= (DXF 0 EN) "POLYLINE"))
					; or
	)				; and
      (progn (setq NO-ENT NIL))		; progn
      (prompt MSG2)
    )					; if
  )					; while
  EN
)					; get-en

(defun GET-LWVLIST (EN / ELIST NUM-VERT VLIST)
  (setq	ELIST	 (entget EN)
	NUM-VERT (cdr (assoc 90 ELIST))
	ELIST	 (member (assoc 10 ELIST) ELIST)
	VLIST	 NIL
  )					; setq
  (repeat NUM-VERT
    (setq VLIST	(append VLIST (list (cdr (assoc 10 ELIST)))) ; append
    )					; setq
    (setq ELIST	(cdr ELIST)
	  ELIST	(member (assoc 10 ELIST) ELIST)
    )					; setq
  )					; repeat
  VLIST
)					; get-lwvlist

(defun GET-PLVLIST (EN / VLIST)
  (setq	VLIST NIL
	EN    (entnext EN)
  )					; setq
  (while (/= "SEQEND" (DXF 0 EN))
    (setq VLIST (append VLIST (list (DXF 10 EN))))
    (setq EN (entnext EN))
  )					; while
  VLIST
)					; get-plvlist

(defun WRITE-IT	(VLST EN / NEWVLIST MSG3 FNAME)
  (setq	NEWVLIST (mapcar '(lambda (X) (trans X EN 0)) ;_ lambda
			 VLST
		 ) ;_ mapcar
	MSG3	 "Polyline vertex file"
					;FNAME    (getfiled MSG3 "" "txt" 1)
	F1	 (open "FNAME" "w")
  )					; setq
  (WRITE-HEADER)
  (WRITE-VERTICES NEWVLIST)
  (setq F1 (close F1))
) ;_ write-it

(defun WRITE-HEADER (/ STR)
  (setq STR "        POLYLINE VERTEX POINTS")
  (write-line STR F1)
  (setq	STR (strcat "  X            " "  Y            " "  Z") ;_ strcat
  ) ;_ setq
  (write-line STR F1)
) ;_ write-header


(defun WRITE-VERTICES (NEWVLIST / XSTR YSTR ZSTR STR)
   (setvar 'OSMODE 0)
(progn
	   (initget "1 2")
	   (setq
	     l
	      (cond
		((getkword
		   "\nΓια Φ.Ε (1)/ Για Ερυθρά (2) < 1 > :"
		 )
		)
		("1")
	      )
	   )
       
(if (eq l "1")
	(COMMAND "_layer" "_m" "ground1" "_c" "94" "" "")
       )
       (if (eq l "2")
	(COMMAND "_layer" "_m" "ground2" "_c" "10" "" "")
	   )
)
  (setq httt "1.80")
  (setq gptx (getpoint "\nBasepoint for X axis: "))
  (setq gpty (getpoint "\nBasepoint for Y axis: "))

  (foreach ITEM	NEWVLIST
    (setq XSTR (rtos (nth 0 ITEM) 2 2)
	  YSTR (rtos (/ (nth 1 ITEM) 10) 2 2)
	  ZSTR (rtos (nth 2 ITEM) 2 2)
	  STR  (strcat XSTR (SPACES XSTR) YSTR (SPACES YSTR) ZSTR) ;_ strcat
    )					; setq
					;      (write-line STR F1)

 (command "style" "PMSF-TEXT 2" "Arial" "" "" "" "" "")
    (command "text" "_mc"
	     (list (+ (atof xstr) (/ (atof httt) 2.0)) (cadr gptx))
	     httt
	     "0"
	     (strcat xstr)
    )
    (command "text" "_mc"
	     (list (+ (atof xstr) (/ (atof httt) 2.0)) (cadr gpty))
	     httt
	     "0"
	     (strcat ystr)
    )

  )					; foreach

)					; write-vertices


(defun SPACES (STR / FIELD NUM CHAR SPACE)
  (setq	FIELD 15
	NUM   (- FIELD (strlen STR))
	CHAR  " "
	SPACE ""
  ) ;_ setq
  (repeat NUM (setq SPACE (strcat SPACE CHAR))) ;_ repeat
) ;_ spaces

(defun C:vv () (SETTING) (VERTEXT) (RESETTING) 
(vl-load-com)
(princ)) ; c:nsl

(prompt "\nEnter VV to start")

Thanks

Posted

not sure what it is this program is supposed to do but it ain't writing no vertex data. I would suggest when you open a file you also close it : (if f1 (close f1))   , not only in (resetting) but also in error routine. Also, localize your global variables in your main routine , like file pointer f1 or your oerr and whatever more you may have.

 

Don't have the time to play any further at this moment , have a deadline to score here at work.


(defun err  (s)
  (if (= s "function cancelled") (princ "\nvertext - cancelled: ") (progn (princ "\nvertext - error: ") (princ s) (terpri)))
  (resetting) (if f1 (close f1)) (princ "system variables have been reset\n") (princ))

(defun setv  (systvar newval)
  (setq x (read (strcat systvar "1"))) (set x (getvar systvar))(setvar systvar newval))

(defun setting  () (setq oerr *error* *error* err)(setv "cmdecho" 0)(setv "blipmode" 0))

(defun rsetv (systvar) (setq x (read (strcat systvar "1"))) (setvar systvar (eval x)))

(defun resetting () (rsetv "cmdecho") (rsetv "blipmode") (if f1 (close f1)) (setq *error* oerr))

(defun dxf (code ename) (cdr (assoc code (entget ename))))

(defun vertext  (/ en vlist)
  (setq en (get-en))
   (if (eq (dxf 0 en) "LWPOLYLINE") (setq vlist (get-lwvlist en)) (setq vlist (get-plvlist en))) (write-it vlist en))

(defun get-en  (/ no-ent en msg1 msg2)
  (setq no-ent 1 en nil msg1 "\nselect a polyline: " msg2 "\nno polyline selected, try again.")
  (while no-ent
    (setq en (car (entsel msg1)))
    (if (and en (or (= (dxf 0 en) "LWPOLYLINE") (= (dxf 0 en) "LWPOLYLINE")))(setq no-ent nil)(prompt msg2))) en)

(defun get-lwvlist  (en / elist num-vert vlist)
  (setq elist (entget en) num-vert (cdr (assoc 90 elist)) elist (member (assoc 10 elist) elist) vlist nil)
  (repeat num-vert
    (setq vlist (append vlist (list (cdr (assoc 10 elist)))) elist (cdr elist) elist (member (assoc 10 elist) elist))) vlist)

(defun get-plvlist  (en / vlist)
  (setq vlist nil en (entnext en))
  (while (/= "SEQEND" (dxf 0 en))(setq vlist (append vlist (list (dxf 10 en))) en (entnext en))) vlist)

(defun write-it  (vlst en / newvlist fname)
  (setq fname "c:/temp/Prodromosm.txt") ; msg3 "polyline vertex file" -> apperently not used? so created dummy file
  (if (and (setq newvlist (mapcar '(lambda (x) (trans x en 0)) vlst))(setq f1 (open fname "w")))
    (progn (write-header) (write-vertices newvlist) (setq f1 (close f1)))  (princ "\nUnable to save data")))

(defun write-header  (/ str)
  (write-line "        polyline vertex points" f1) (write-line "  x              y              z" f1))

(defun write-vertices  (newvlist / l xstr ystr zstr str)
  (setvar 'osmode 0) (initget "1 2") (setq l (getkword "\nFor F.E (1)/ To Red (2) < 1 > :"))
  (if (eq l "1") (command "_layer" "_m" "ground1" "_c" "94" "" ""))
  (if (eq l "2") (command "_layer" "_m" "ground2" "_c" "10" "" ""))
  (setq httt "1.80" gptx (getpoint "\nbasepoint for x axis: ") gpty (getpoint "\nbasepoint for y axis: "))
  (foreach item  newvlist
    (setq xstr (rtos (nth 0 item) 2 2) ystr (rtos (/ (nth 1 item) 10) 2 2) zstr (rtos (nth 2 item) 2 2)
          str  (strcat xstr (spaces xstr) ystr (spaces ystr) zstr))
    (command "style" "pmsf-text 2" "arial" "" "" "" "" "")
    (command "text" "_mc" (list (+ (atof xstr) (/ (atof httt) 2.0)) (cadr gptx)) httt "0" (strcat xstr))
    (command "text" "_mc" (list (+ (atof xstr) (/ (atof httt) 2.0)) (cadr gpty)) httt "0" (strcat ystr))
  )
)


(defun spaces  (str / field num char space)
  (setq field 15 num (- field (strlen str)) char  " " space "")  (repeat num (setq space (strcat space char))))

 

(defun c:vv ( / f1 oerr ) (setting) (vertext) (resetting)  (princ)) ; c:nsl


(vl-load-com)
(prompt "\nenter vv to start")

 

 

Posted

If code / remark above was sufficient , ok , your welcome  🙂 , else could you post example dwg plus a data file with what you expect as output from your appie? If just exporting points , isn't AutoCad data extract all you need? Also think there should be like a ton of export vertex data appies on this and other forums? Never have had the need for this myself so of cource  I could be wrong. Made a polyline appie a couple of weeks ago for this forum , to put height & length plus area along polylines and also put the results in a table. Shouln't be to hard to add option to export point data.

 

gr.RLX

Posted

This is a vertex data I stumbled on apologise for no author description.


(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(if ss  (setq co-ords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0))))))

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...