Author Topic: ERROR LISP  (Read 2433 times)

0 Members and 1 Guest are viewing this topic.

vnanhvu

  • Guest
ERROR LISP
« on: June 09, 2011, 10:07:49 PM »
First Sorry Lee Mac Because Change Some Name Command In This Lisp.
When I Copy Two Lee's Lisp Into A File Lisp, Display A Error : ** Error : Too Many Arguments **  ( when use command : CB, CCB, RRB )
Can Lee Help Me? Or Someone.
Thank you very much.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ERROR LISP
« Reply #1 on: June 09, 2011, 10:43:39 PM »
What lisp are you talking about?
Please post a link to the code.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

vnanhvu

  • Guest
Re: ERROR LISP
« Reply #2 on: June 10, 2011, 12:35:24 AM »
LISP 1:
Code: [Select]
COPY & TAO BLOCK NAME MOI, RENAME BLOCK
(defun c:CCB nil (c:RenameBlock   t))

(defun c:RRB nil (c:RenameBlock nil))

;;------------------------------------------------------------;;

(defun c:RenameBlock ( copy / *error* _Name _ReleaseObject acapp acdoc b1 b2 dbdoc df n1 n2 )

;;------------------------------------------------------------;;

  (defun *error* ( msg )
    (_ReleaseObject dbdoc)
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun _Name ( obj )
    (if (vlax-property-available-p obj 'EffectiveName)
      (vla-get-EffectiveName obj)
      (vla-get-Name obj)
    )
  )

  (defun _ReleaseObject ( obj )
    (and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj))
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply 'vlax-release-object (list obj))
        )
      )
    )
  )
 
;;------------------------------------------------------------;;

  (setq acapp (vlax-get-acad-object)
        acdoc (vla-get-activedocument acapp)
  )
 
  (if
    (and
      (setq b1
        (car
          (LM:Selectif (strcat "\nSelect Block Reference to " (if copy "Copy" "Rename") ": ")
            (lambda ( x )
              (and (eq "INSERT" (cdr (assoc 0 (entget (car x)))))
                (zerop
                  (logand 44
                    (cdr
                      (assoc 70
                        (tblsearch "BLOCK" (cdr (assoc 2 (entget (car x)))))
                      )
                    )
                  )
                )
              )
            )
            entsel nil
          )
        )
      )
      (LM:CopyBlockDef acdoc (setq dbdoc (LM:ObjectDBXDocument acapp)) (setq n1 (_Name (setq b1 (vlax-ename->vla-object b1))))
        (progn
          (while
            (progn
              (setq n2
                (getstring t
                  (strcat "\nSpecify New Block Name <"
                    (setq df
                      (
                        (lambda ( i / b )
                          (while
                            (tblsearch "BLOCK"
                              (setq b (strcat n1 "_" (itoa (setq i (1+ i)))))
                            )
                          )
                          b
                        )
                        0
                      )
                    )
                    "> : "
                  )
                )
              )
              (cond
                ( (eq "" n2) (setq n2 df)
                  nil
                )
                ( (or (not (snvalid n2)) (tblsearch "BLOCK" n2))
                  (princ "\nBlock Name Invalid or Already Exists.")
                )
              )
            )
          )
          n2
        )
      )
    )
    (progn
      (if (and (vlax-property-available-p b1 'isDynamicBlock) (eq :vlax-true (vla-get-isDynamicBlock b1)))
        (progn
          (setq p1 (mapcar 'vla-get-value (vlax-invoke b1 'GetDynamicBlockProperties)))
          (vla-put-name (if copy (setq b1 (vla-copy b1)) b1) n2)
          (mapcar
            (function
              (lambda ( a b )
                (or (eq "ORIGIN" (strcase (vla-get-PropertyName a))) (vla-put-value a b))
              )
            )
            (vlax-invoke b1 'GetDynamicBlockProperties) p1
          )
        )
        (vla-put-name (if copy (setq b1 (vla-copy b1)) b1) n2)
      )
      (if copy (sssetfirst nil (ssadd (vlax-vla-object->ename b1))))
    )
  )
  (_ReleaseObject dbdoc)
  (princ)
)

;;---------------=={ Copy Block Definition }==----------------;;
;;                                                            ;;
;;  Copies the specified block defintion with new name as     ;;
;;  specified                                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  acdoc - Document Object containing Block to copy          ;;
;;  dbdoc - ObjectDBX Document                                ;;
;;  name1 - Name of block definition to copy                  ;;
;;  name2 - Name to be used for copied definition             ;;
;;------------------------------------------------------------;;
;;  Returns: Copied VLA Block Definition Object, else nil     ;;
;;------------------------------------------------------------;;

(defun LM:CopyBlockDef ( acdoc dbdoc name1 name2 / acblk dbblk b1 b2 )
  (setq acblk (vla-get-blocks acdoc)
        dbblk (vla-get-blocks dbdoc)
  )               
  (if
    (and
      (setq b1 (LM:GetItem acblk name1))
      (not     (LM:GetItem acblk name2))
    )
    (progn 
      (vla-CopyObjects acdoc (LM:SafearrayVariant vlax-vbObject (list b1)) dbblk)
      (vla-put-Name (setq b2 (LM:GetItem dbblk name1)) name2)
      (vla-CopyObjects dbdoc (LM:SafearrayVariant vlax-vbObject (list b2)) acblk)
    )
  )
  (LM:GetItem acblk name2)
)

;;--------------=={ VLA-Collection: Get Item }==--------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  collection - the VLA Collection Object                    ;;
;;  item       - the index of the item to be retrieved        ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:GetItem ( collection item )
  (if
    (not
      (vl-catch-all-error-p
        (setq item (vl-catch-all-apply 'vla-item (list collection item)))
      )
    )
    item
  )
)

;;-----------------=={ ObjectDBX Document }==-----------------;;
;;                                                            ;;
;;  Retrieves a version specific ObjectDBX Document object    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  acapp - AutoCAD VLA Application Object                    ;;
;;------------------------------------------------------------;;
;;  Returns:  VLA ObjectDBX Document object, else nil         ;;
;;------------------------------------------------------------;;

(defun LM:ObjectDBXDocument ( acapp / acVer )
  (vla-GetInterfaceObject acapp
    (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
      "ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
    )
  )
)

;;------------------=={ Safearray Variant }==-----------------;;
;;                                                            ;;
;;  Creates a populated Safearray Variant of a specified      ;;
;;  data type                                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  datatype - variant type enum (eg vlax-vbDouble)           ;;
;;  data     - list of static type data                       ;;
;;------------------------------------------------------------;;
;;  Returns:  VLA Variant Object of type specified            ;;
;;------------------------------------------------------------;;

(defun LM:SafearrayVariant ( datatype data )
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray datatype (cons 0 (1- (length data)))) data
    )
  )
)

;;---------------------=={ Select if }==----------------------;;
;;                                                            ;;
;;  Provides continuous selection prompts until either a      ;;
;;  predicate function is validated or a keyword is supplied. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  msg  - prompt string                                      ;;
;;  pred - optional predicate function [selection list arg]   ;;
;;  func - selection function to invoke                       ;;
;;  keyw - optional initget argument list                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Entity selection list, keyword, or nil          ;;
;;------------------------------------------------------------;;

(defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred)) 
  (while
    (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
      (cond
        ( (= 7 (getvar 'ERRNO))
          (princ "\nMissed, Try again.")
        )
        ( (eq 'STR (type sel))
          nil
        )
        ( (vl-consp sel)
          (if (and pred (not (pred sel)))
            (princ "\nInvalid Object Selected.")
          )
        )
      )
    )
  )
  sel
)

;;------------------------------------------------------------;;

(vl-load-com) (princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;

vnanhvu

  • Guest
Re: ERROR LISP
« Reply #3 on: June 10, 2011, 12:36:37 AM »
LISP 2:
Code: [Select]
;; DOI DIEM CHEN BLOCK TUYET CU MEO
;; -- Retains Insertion Point --
(defun c:CB  nil (ChangeBlockInsertion nil))

;; -- Retains Block Position --
(defun c:CB nil (ChangeBlockInsertion   t))


;;------------------{ Local Functions }------------------------;;

(defun ChangeBlockInsertion ( retain / *error* _StartUndo _EndUndo doc blocks oldc
                                       SourceBlock pt undo vec name ss )
  ;; © Lee Mac 2010
  (vl-load-com)

  (setq doc    (vla-get-ActiveDocument (vlax-get-acad-object))
        blocks (vla-get-blocks doc))

  (defun *error* ( msg )
    (if doc  (_EndUndo doc))
    (if oldc (setvar 'CMDECHO oldc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun _StartUndo ( doc ) (_EndUndo doc)
    (vla-StartUndoMark doc)
  )

  (defun _EndUndo ( doc )
    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
      (vla-EndUndoMark doc)
    )
  )

  (setq oldc (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)

  (if
    (and
      (setq SourceBlock
        (LM:Selectif
          (lambda ( x )
            (eq "AcDbBlockReference"
              (vla-get-ObjectName (vlax-ename->vla-object x))
            )
          )
          entsel "\nSelect Block: "
        )
      )
      (setq SourceBlock (vlax-ename->vla-object SourceBlock))
      (setq pt (getpoint "\nSpecify New Base Point: "))
    )
    (progn
      (_StartUndo doc)

      (setq Vec  (LM:ChangeBlockInsertion SourceBlock pt)
            Name (LM:GetBlockName SourceBlock))

      (if retain
        (
          (lambda ( i / ss e obj )
            (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 Name))))
            (while (setq e (ssname ss (setq i (1+ i))))
              (vla-Move (setq obj (vlax-ename->vla-object e))
                (vlax-3D-point '(0. 0. 0.))
                (vlax-3D-point (mxv (LM:Def->Geom obj) Vec))
              )
            )
          )
          -1
        )
      )

      (if (eq :vlax-true (vla-get-HasAttributes SourceBlock))
        (vl-cmdf "_.attsync" "_N" Name)
      )
      (vla-regen doc acAllViewports)
      (_EndUndo doc)
    )
  )
  (setvar 'CMDECHO oldc)
  (princ)
)

;;---------------=={ Change Block Insertion }==---------------;;
;;                                                            ;;
;;  Changes the block definition insertion point calculated   ;;
;;  from a reference block and user specified point.          ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  SourceBlock - VLA Block Reference Object                  ;;
;;  Pt (UCS)    - New Insertion Point relative to SourceBlock ;;
;;------------------------------------------------------------;;
;;  Returns:  Translation Vector from mapping previous        ;;
;;            insertion point to new point, relative to       ;;
;;            block definition geometry.                      ;;
;;------------------------------------------------------------;;

(defun LM:ChangeBlockInsertion ( SourceBlock pt / BlockDef Mat Vector )
  ;; © Lee Mac 2010
  (vl-load-com)

  (if (and (setq BlockDef (LM:Itemp blocks (LM:GetBlockName SourceBlock)))
           (setq Mat (LM:Geom->Def SourceBlock)))
    (progn
      (setq Vector
        (mxv Mat
          (mapcar '- (setq pt (trans pt 1 0)) ; UCS->WCS
            (setq Insertion
              (vlax-get SourceBlock 'InsertionPoint)
            )
          )
        )
      )
      (vlax-for obj BlockDef
        (vla-Move obj (vlax-3D-point Vector) (vlax-3D-point '(0. 0. 0.)))
      )
    )
  )
  Vector
)

;;---------------------=={ Geom->Def }==----------------------;;
;;                                                            ;;
;;  Returns the Transformation Matrix for transforming Block  ;;
;;  Geometry to the Block Definiton.                          ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  SourceBlock - VLA Block Reference Object                  ;;
;;------------------------------------------------------------;;
;;  Returns:  A 3x3 Transformation Matrix                     ;;
;;------------------------------------------------------------;;

(defun LM:Geom->Def ( SourceBlock / norm ang x y z )
  ;; © Lee Mac 2010
  (vl-load-com)

  (setq norm (vlax-get SourceBlock 'Normal)
         ang (- (vla-get-rotation SourceBlock)))
     
  (mapcar 'set '(x y z)
    (mapcar
      '(lambda ( prop alt )
         (/ 1.
            (vlax-get-property SourceBlock
              (if (vlax-property-available-p SourceBlock prop) prop alt)
            )
          )
       )
      '(XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor)
      '(XScaleFactor          YScaleFactor          ZScaleFactor         )
    )
  )
  (mxm
    (list
      (list x 0. 0.)
      (list 0. y 0.)
      (list 0. 0. z)
    )
    (mxm
      (list
        (list (cos ang) (sin (- ang)) 0.)
        (list (sin ang) (cos ang)     0.)
        (list     0.        0.        1.)
      )
      (mapcar '(lambda ( e ) (trans e norm 0 t)) ; OCS->WCS
        '((1. 0. 0.) (0. 1. 0.) (0. 0. 1.))
      )
    )
  )
)

;;---------------------=={ Def->Geom }==----------------------;;
;;                                                            ;;
;;  Returns the Transformation Matrix for transforming Block  ;;
;;  Definition Geometry to a Block Reference.                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  SourceBlock - VLA Block Reference Object                  ;;
;;------------------------------------------------------------;;
;;  Returns:  A 3x3 Transformation Matrix                     ;;
;;------------------------------------------------------------;;

(defun LM:Def->Geom ( SourceBlock / norm ang x y z )
  ;; © Lee Mac 2010
  (vl-load-com)

  (setq norm (vlax-get SourceBlock 'Normal)
         ang (vla-get-rotation SourceBlock))
     
  (mapcar 'set '(x y z)
    (mapcar
      '(lambda ( prop alt )
         (vlax-get-property SourceBlock
           (if (vlax-property-available-p SourceBlock prop) prop alt)
         )
       )
      '(XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor)
      '(XScaleFactor          YScaleFactor          ZScaleFactor         )
    )
  )
  (mxm
    (mapcar '(lambda ( e ) (trans e 0 norm t)) ; WCS->OCS
      '((1. 0. 0.) (0. 1. 0.) (0. 0. 1.))
    )
    (mxm
      (list
        (list (cos ang) (sin (- ang)) 0.)
        (list (sin ang) (cos ang)     0.)
        (list     0.        0.        1.)
      )
      (list
        (list x 0. 0.)
        (list 0. y 0.)
        (list 0. 0. z)
      )
    )
  )
)

;;-------------------=={ Get Block Name }==-------------------;;
;;                                                            ;;
;;  Retrieves the Block Name as per the Block Definition      ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  obj - VLA Block Reference Object                          ;;
;;------------------------------------------------------------;;
;;  Returns:  Block Name [STR]                                ;;
;;------------------------------------------------------------;;
 
(defun LM:GetBlockName ( obj )
  ;; © Lee Mac 2010
  (vlax-get-property obj
    (if (vlax-property-available-p obj 'EffectiveName)
      'EffectiveName 'Name
    )
  )
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;
 
(defun LM:Itemp ( coll item )
  ;; © Lee Mac 2010
  (if
    (not
      (vl-catch-all-error-p
        (setq item
          (vl-catch-all-apply
            (function vla-item) (list coll item)
          )
        )
      )
    )
    item
  )
)

;;---------------------=={ Select if }==----------------------;;
;;                                                            ;;
;;  Continuous selection prompts until the predicate function ;;
;;  foo is validated                                          ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  foo - optional predicate function taking ename argument   ;;
;;  fun - selection function to invoke                        ;;
;;  str - prompt string                                       ;;
;;------------------------------------------------------------;;
;;  Returns:  selected entity ename if successful, else nil   ;;
;;------------------------------------------------------------;;

(defun LM:Selectif ( foo fun str / e )
  ;; © Lee Mac 2010
  (while
    (progn (setq e (car (fun str)))     
      (cond
        ( (eq 'ENAME (type e))

          (if (and foo (not (foo e)))
            (princ "\n** Invalid Object Selected **")
          )
        )
      )
    )
  )
  e
)

;; Matrix x Vector  ~  Vladimir Nesterovsky
(defun mxv ( mat vec )
  (mapcar '(lambda ( row ) (apply '+ (mapcar '* row vec))) mat)
)

;; Matrix x Matrix  ~  Vladimir Nesterovsky
(defun mxm ( m q )
  (mapcar (function (lambda ( r ) (mxv (trp q) r))) m)
)

;; Matrix Transpose  ~  Doug Wilson
(defun trp ( m )
  (apply 'mapcar (cons 'list m))
)



......when copy lisp 1 & 2 into 1 file lisp, i have a error...
THANKS

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: ERROR LISP
« Reply #4 on: June 10, 2011, 05:54:43 AM »
Why have you removed the program headers?  :x

vnanhvu

  • Guest
Re: ERROR LISP
« Reply #5 on: June 10, 2011, 05:57:59 AM »
sorry Lee. When i upload, because long characters, i erased some characters. i saved and lost header.
Sorry much. Can you help me ?

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: ERROR LISP
« Reply #6 on: June 10, 2011, 06:01:50 AM »
sorry Lee. When i upload, because long characters, i erased some characters. i saved and lost header.

A likely story...

Anyway, you don't have the latest versions:

Copy/Rename Block

Change Block Insertion

Read this also.

vnanhvu

  • Guest
Re: ERROR LISP
« Reply #7 on: June 10, 2011, 07:21:24 AM »
Hi Lee.
When i upload, i copy 2 lisp into 1 file lisp, and very long characters, i cant upload... and..... I hope you belive me.
You help me, i thank you very much. I copy your lisp and promise no change it.
Have a nice day.
Thanks again.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: ERROR LISP
« Reply #8 on: June 10, 2011, 07:36:52 AM »
You could have attached the files instead, but at this point it doesn't matter too much.

I hope the programs work for you now.

Lee