Message 1 of 15
Not applicable
01-29-2020
04:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code works relatively well, however when I run it for the first time it generates
Error: bad argument type: stringp nilbad argument type: stringp #<FILE internal>
and does not end. I've done it step by step and I don't understand why, any guidance?
;;--------------------- { Get Attribute Value - Lee Mac } --------------------;;
;; ;;
;;------------------------------------------------------------------------------;;
;; Autor: Lee Mac ;;
;;------------------------------------------------------------------------------;;
;; Argumentos: ;;
;; blk - [vla] VLA Block Reference Object ;;
;; tag - [str] Attribute TagString ;;
;;------------------------------------------------------------------------------;;
(defun LM:vl-getattributevalue ( blk tag )
(setq tag (strcase tag))
(vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))
)
;;--------------------- { Set attributevalue - Lee Mac- } --------------------;;
;; ;;
;;------------------------------------------------------------------------------;;
;; Autor: Lee Mac ;;
;;------------------------------------------------------------------------------;;
;; Argumentos: ;;
;; blk - [vla] VLA Block Reference Object ;;
;; tag - [str] Attribute TagString ;;
;; val - [str] Attribute Value ;;
;;------------------------------------------------------------------------------;;
(defun LM:vl-setattributevalue ( blk tag val )
(setq tag (strcase tag))
(vl-some '(lambda ( att )(if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val)))(vlax-invoke blk 'getattributes))
)
;;------------------------------------------------------------------------------;;
(defun c:EXTRELATORIO (/ ss file i blk vatt ratt ip ss2 att1 att2 att3 att4 att5 )
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
)
(close file)
(vl-file-delete file)
(princ)
)
(setq ss (ssget '((0 . "INSERT") (66 . 1)(2 . "Poste_Enel,`*U*"))))
(setq file (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".txt") "w"))
(write-line "Numero;Latitude;Longitude;Relatorio" file )
(repeat (setq i (sslength ss))
(setq blk (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq vatt '("NUM" "LATITUDE" "LONGITUDE" "RELATORIO"))
(setq ratt (mapcar '(lambda (x) (LM:vl-getattributevalue blk x)) vatt))
;(setq ratt (mapcar '(lambda (x) (vl-some '(lambda ( att ) (if (= (strcase x) (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))) vatt)) <- Melhor!
(mapcar 'set '(att1 att2 att3 att4) ratt)
(setq ip (vlax-get blk 'insertionpoint))
(setq ss2 (ssget "_C" (mapcar '+ ip '(5 5)) (mapcar '- ip '(5 5)) '((0 . "INSERT")(66 . 1)(2 . "Caixa001,Caixa002,Caixa003,Caixa004,Caixa005,Caixa006"))))
(if (/= ss2 nil)
(if (= (sslength ss2) 1)
(progn
(setq blk2 (vlax-ename->vla-object (ssname ss2 0)))
(LM:vl-setattributevalue blk2 "IDCX" att1)
(setq att5 (LM:vl-getattributevalue blk2 "NOM"))
)
)
(setq att5 "")
)
(write-line (strcat att1 ";" att2 ";" att3 ";" att4 ";" att5 ) file )
)
(close file)
;(startapp "notepad" "G:\\Meu Drive\\Brisanet Programas\\Desenhos\\Extrator Material\\Teste-.txt")
(princ)
)
Solved! Go to Solution.