Jump to content

Recommended Posts

Posted

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

Posted

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

 

Posted

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

Posted

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

  • Like 1
Posted

This work better

 

 (if (not (tblsearch "BLOCK" "POINT")) 
    (alert "The block POINT does not exist in this drawing.!!!\nPlease insert block POINT")
  )

 

Posted

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))
  )

 

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...