Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting a block flat, using error handler problem

3 REPLIES 3
Reply
Message 1 of 4
ChuckEdwards
255 Views, 3 Replies

Getting a block flat, using error handler problem

I've written the little routine below. Something is going wrong with how the variable ent is passed but I can't work out what, any suggestions?

 

The core code works fine, if I comment out the catch-all-apply code, and de-comment the rest of the second module, it works fine. not what i want though, I'd like to avoid problems like trying to change the normal of an object on a locked layer.

 

 

(defun flattenblock (ent / newNormal)

  (setq enx (vlax-ename->vla-object ent))

  (setq newNormal (vlax-3d-point 0 0 1))

  (vla-put-Normal enx newNormal)

  (vla-Update enx)

  (setq newNormal (vlax-variant-value newNormal))

)

 

;;selection routine

(defun c:flatblock (/ ent ss enx newNormal)

  (vl-load-com)

  (while (null ss)

    (prompt "\nSelect Blocks or Xrefs")

    (setq ss (ssget '((0 . "INSERT"))))

  )

  (while (> (sslength ss) 0)

    (setq ent (ssname ss 0))

      (setq

        catchit (vl-catch-all-apply 'flattenblock ent)

      )

   ; (setq enx (vlax-ename->vla-object ent))

  ;  (setq newNormal (vlax-3d-point 0 0 1))

  ;  (vla-put-Normal enx newNormal)

  ;  (vla-Update enx)

   ; (setq newNormal (vlax-variant-value newNormal))

    (ssdel ent ss)

  )                                                                            ;end while

  (princ)

)

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: ChuckEdwards

The issue is because the vl-catch-all-apply function requires a list of arguments to which the supplied function is to be applied - similar in operation to the apply function, but will catch any exceptions.

 

However, I would suggest the following:

 

(defun c:flatblock ( / e i n s )
    (if (setq s (ssget "_:L" '((0 . "INSERT"))))
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i))))
                  n (assoc 210 e)
            )
            (entmod
                (subst
                    (cons  10 (trans (cdr (assoc 10 e)) (cdr n) 0))
                    (assoc 10 e)
                    (subst '(210 0.0 0.0 1.0) n e)
                )
            )
        )
    )
    (princ)
)

 

Message 3 of 4
ChuckEdwards
in reply to: Lee_Mac

Thanks.

 

I think I'll stick with the VLAX, I get lost in the parenthesiseseses....

 

Charles.

Message 4 of 4
Lee_Mac
in reply to: ChuckEdwards


@ChuckEdwards wrote:
 

I think I'll stick with the VLAX, I get lost in the parenthesiseseses....


Vanilla AutoLISP is faster and has fewer bugs, but your choice.

 

For the Visual LISP (ActiveX) route:

 

(defun c:flatblock ( / i p s )
    (if (setq s (ssget "_:L" '((0 . "INSERT"))))
        (repeat (setq i (sslength s))
            (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))
                  p (vlax-get o 'insertionpoint)
            )
            (vlax-put o 'normal '(0.0 0.0 1.0))
            (vlax-put o 'insertionpoint p)
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost