mhy3sx Posted April 23 Posted April 23 Hi, I am using this code to insert block. The idea is to insert the block or by pick on a point or by giving the number of the point. But if is not a point in the drawing the code crash so I want to add (alert "No POINT found") (defun c:myblock(/ lPointList scl scl1 dt1 pnt pointsToList) (command "_layer" "_m" "Block" "_c" "142" "" "") (defun pointsToList (/ ssPoints iCounter ePoint oPoint aAttributes vAttributes oPointTag sTag lPoints lCoord ) (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT"))) iCounter 0 ) (repeat (sslength ssPoints) (if (and (setq ePoint (ssname ssPoints iCounter)) (setq oPoint (vlax-ename->vla-object ePoint)) (setq iCounter (1+ iCounter)) (= (vla-get-hasattributes oPoint) :vlax-true) (setq aAttributes (vla-getattributes oPoint)) (setq vAttributes (vlax-variant-value aAttributes)) (setq aAttributes (vlax-safearray->list vAttributes)) (setq oPointTag (car aAttributes)) (setq sTag (vla-get-textstring oPointTag)) (setq lCoord (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint oPoint)) ) ) ) (progn (setq lPoints (append lPoints (list (cons sTag (list oPoint lCoord))) ) ) ) ) ) lPoints ) (setq lPointList (pointsToList) scl (getvar "useri1") scl1 (* scl 0.0025) ) (while (progn (initget 128) (setq dt1 (getpoint "\n Insert Point or Number of point: ")) ) (progn (if (= 'STR (type dt1)) (setq pnt (assoc dt1 lPointList) pnt (caddr pnt) ) (setq pnt dt1) ) (command "_.insert" "c:\\library\\myblock.dwg" pnt scl1 scl1 0) ) ) (princ) (command "setvar" "clayer" "0") ) Thanks Quote
mhy3sx Posted April 23 Author Posted April 23 I try this (defun c:myblock(/ lPointList scl scl1 dt1 pnt pointsToList) (command "_layer" "_m" "Block" "_c" "142" "" "") (defun pointsToList (/ ssPoints iCounter ePoint oPoint aAttributes vAttributes oPointTag sTag lPoints lCoord ) (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT"))) iCounter 0 ) (repeat (sslength ssPoints) (if (and (setq ePoint (ssname ssPoints iCounter)) (setq oPoint (vlax-ename->vla-object ePoint)) (setq iCounter (1+ iCounter)) (= (vla-get-hasattributes oPoint) :vlax-true) (setq aAttributes (vla-getattributes oPoint)) (setq vAttributes (vlax-variant-value aAttributes)) (setq aAttributes (vlax-safearray->list vAttributes)) (setq oPointTag (car aAttributes)) (setq sTag (vla-get-textstring oPointTag)) (setq lCoord (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint oPoint)) ) ) ) (progn (setq lPoints (append lPoints (list (cons sTag (list oPoint lCoord))) ) ) ) ) ) lPoints ) (setq lPointList (pointsToList) scl (getvar "useri1") scl1 (* scl 0.0025) ) (while (progn (initget 128) (setq dt1 (getpoint "\n Insert Point or Number of point: ")) ) (progn (if (= 'STR (type dt1)) (setq pnt (assoc dt1 lPointList) pnt (caddr pnt) ) (setq pnt dt1) ) (if pnt (command "_.insert" "c:\\library\\myblock.dwg" pnt scl1 scl1 0) (alert "No POINT found") ) ) ) (princ) (command "setvar" "clayer" "0") ) But gives me Error: incorrect type - nil Quote
Steven P Posted April 23 Posted April 23 So before the new 'if' line, what is the value of pnt? Add maybe (princ pnt) so you can see what it is. However consider the 6 lines just before this, pnt is always being set, either as (caddr pnt) or as dt1 Quote
mhy3sx Posted April 23 Author Posted April 23 HI Steven P.I fix the problem. I add in the beginning ((and (not POINT)) (alert (strcat "The block POINT does not exist in this drawing.")) ) Thanks 1 Quote
mhy3sx Posted April 23 Author Posted April 23 This work better (if (not (tblsearch "BLOCK" "POINT")) (alert "The block POINT does not exist in this drawing.!!!\nPlease insert block POINT") ) Quote
BIGAL Posted April 23 Posted April 23 This will exit code if block does not exist (if (not (tblsearch "BLOCK" "POINT")) (progn (alert "The block POINT does not exist in this drawing.!!!\nPlease insert block POINT\n\nWill now exit") (exit)) ) Quote
Recommended Posts
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.