Jump to content

Recommended Posts

Posted

Hi there,

 

I have a problem with lisp routine in CAD 2011 (and Civil 3d 2011).

Attached lisp is working perfectly in CAD and Civil 2010 but when I'm trying to run it in 2011 I have an error message in command line:

 

** Error: Too many actual parameters **

 

I've searched on web but couldn't find answer. Does anybody know what is wrong?

 

Thanks for all help in advance

a2f.lsp

Posted

Hi Tomjas,

 

I see that is one of mine, hence I am intrigued as to the root of the problem...

 

If you run the code through the VLIDE in 2011 with the 'Break on Error' option ticked, then go to 'Last Break Source' when the error occurs, what line is highlighted?

Posted

Hi Lee Mac,

 

Yes- it's one of your great lisps :)

Below I made the code highlighted in vlide in red:

 

(defun c:a2f (/ *error* Stringify ENT OBJ PT TMP TOBJ TYP UFLAG)
 ;; Lee Mac  ~  13.01.10
 (vl-load-com)

 (defun *error* (msg)
   (and uFlag (vla-EndUndoMark *doc*))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (defun Stringify (x / typ)
   (cond (  (eq 'REAL (setq typ (type x)))
            (rtos x))
         (  (eq 'INT typ)
            (itoa x))
         (  (eq 'STR typ) x)
         (t (vl-princ-to-string x))))
 

 (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument
                              (vlax-get-acad-object))))

       *spc* (cond (*spc*) ((if (zerop (vla-get-activespace *doc*))
                              (if (= [b][color=Red](vla-get-mspace *doc* :vlax-true)[/color][/b])
                                (vla-get-modelspace *doc*)
                                (vla-get-paperspace *doc*))
                              (vla-get-modelspace *doc*)))))

 (setq *a2f_Uni 2))
 (or *a2f_Pre (setq *a2f_Pre 0))
 (or *a2f_Con (setq *a2f_Con 1.))
 (or *a2f_Hgt (setq *a2f_Hgt (getvar 'TEXTSIZE)))
 (setq *a2f_Rot 0.))
 (or *a2f_Suf (setq *a2f_Suf "m2"))

 (mapcar (function set) '(*a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)
         (mapcar
           (function
             (lambda (ini foo msg x)
               (and ini (initget ini))
               (cond ((and (setq tmp ((eval foo) (strcat "\n" msg " <" (Stringify x) "> : ")))
                           (/= "" tmp)) tmp)
                     (x))))
            
            (list 4 6 6 nil)
           '(GetInt GetReal GetDist GetString)
           '("Specify Precision" "Specify Conversion Factor"
             "Specify Text Height" "Specify Suffix")
            (list *a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)))
           
 (while
   (progn
     (setq ent (car (entsel "\n>> Pick Hatch [And don't you dare pick anything else]  >>")))

     (cond (  (eq 'ENAME (type ent))

              (if (and (eq "AcDbHatch" (vla-get-ObjectName (setq obj (vlax-ename->vla-object ent))))
                       (vlax-property-available-p obj 'Area))
                
                (if (setq pt (getpoint "\nPick Point for Field: "))
                  (progn
                    (setq uFlag (not (vla-StartUndoMark *doc*)))

                    (setq tObj
                      (vla-AddMText *spc* (vlax-3D-point pt) 0.0
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                (vl-princ-to-string (vla-get-ObjectId obj))
                                ">%).Area \\f \"%lu" (itoa *a2f_Uni) "%pr"
                                (itoa *a2f_Pre) "%ps[," *a2f_Suf "]%ct8[" (rtos *a2f_Con) "]\">%")))

                    (mapcar
                      (function
                        (lambda (property value)
                          (vlax-put-property tObj property value)))

                      '(Height Rotation Layer Color)
                       (list *a2f_Hgt *a2f_Rot (vlax-get-property obj 'Layer)
                                               (vlax-get-property obj 'Color)))

                    (setq uFlag (vla-EndUndoMark *doc*))

                    t) ;; repeat

                  )

                (princ "\n** Invalid Object Selected **"))))))
 (princ))

 

Thanks for your help in advance!

Posted

Ah - that's a typo on my part - I should've spotted that :oops:

 

Please try this instead:

 

(defun c:a2f (/ *error* Stringify ENT OBJ PT TMP TOBJ TYP UFLAG)
 ;; Lee Mac  ~  13.01.10
 (vl-load-com)

 (defun *error* (msg)
   (and uFlag (vla-EndUndoMark *doc*))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (defun Stringify (x / typ)
   (cond (  (eq 'REAL (setq typ (type x)))
            (rtos x))
         (  (eq 'INT typ)
            (itoa x))
         (  (eq 'STR typ) x)
         (t (vl-princ-to-string x))))
 

 (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument
                              (vlax-get-acad-object))))

       *spc* (cond (*spc*) ((if (zerop (vla-get-activespace *doc*))
                              (if (eq (vla-get-mspace *doc*) :vlax-true)
                                (vla-get-modelspace *doc*)
                                (vla-get-paperspace *doc*))
                              (vla-get-modelspace *doc*)))))

 (setq *a2f_Uni 2))
 (or *a2f_Pre (setq *a2f_Pre 0))
 (or *a2f_Con (setq *a2f_Con 1.))
 (or *a2f_Hgt (setq *a2f_Hgt (getvar 'TEXTSIZE)))
 (setq *a2f_Rot 0.))
 (or *a2f_Suf (setq *a2f_Suf "m2"))

 (mapcar (function set) '(*a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)
         (mapcar
           (function
             (lambda (ini foo msg x)
               (and ini (initget ini))
               (cond ((and (setq tmp ((eval foo) (strcat "\n" msg " <" (Stringify x) "> : ")))
                           (/= "" tmp)) tmp)
                     (x))))
            
            (list 4 6 6 nil)
           '(GetInt GetReal GetDist GetString)
           '("Specify Precision" "Specify Conversion Factor"
             "Specify Text Height" "Specify Suffix")
            (list *a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)))
           
 (while
   (progn
     (setq ent (car (entsel "\n>> Pick Hatch [And don't you dare pick anything else]  >>")))

     (cond (  (eq 'ENAME (type ent))

              (if (and (eq "AcDbHatch" (vla-get-ObjectName (setq obj (vlax-ename->vla-object ent))))
                       (vlax-property-available-p obj 'Area))
                
                (if (setq pt (getpoint "\nPick Point for Field: "))
                  (progn
                    (setq uFlag (not (vla-StartUndoMark *doc*)))

                    (setq tObj
                      (vla-AddMText *spc* (vlax-3D-point pt) 0.0
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                (vl-princ-to-string (vla-get-ObjectId obj))
                                ">%).Area \\f \"%lu" (itoa *a2f_Uni) "%pr"
                                (itoa *a2f_Pre) "%ps[," *a2f_Suf "]%ct8[" (rtos *a2f_Con) "]\">%")))

                    (mapcar
                      (function
                        (lambda (property value)
                          (vlax-put-property tObj property value)))

                      '(Height Rotation Layer Color)
                       (list *a2f_Hgt *a2f_Rot (vlax-get-property obj 'Layer)
                                               (vlax-get-property obj 'Color)))

                    (setq uFlag (vla-EndUndoMark *doc*))

                    t) ;; repeat

                  )

                (princ "\n** Invalid Object Selected **"))))))
 (princ))

Posted

now when I'm trying to load it I have

error: extra right paren on input

 

I think I know where is a problem as I was trying to do some changes to original code- please see below in red

 

(defun c:a2f (/ *error* Stringify ENT OBJ PT TMP TOBJ TYP UFLAG)
 ;; Lee Mac  ~  13.01.10
 (vl-load-com)

 (defun *error* (msg)
   (and uFlag (vla-EndUndoMark *doc*))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (defun Stringify (x / typ)
   (cond (  (eq 'REAL (setq typ (type x)))
            (rtos x))
         (  (eq 'INT typ)
            (itoa x))
         (  (eq 'STR typ) x)
         (t (vl-princ-to-string x))))
 

 (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument
                              (vlax-get-acad-object))))

       *spc* (cond (*spc*) ((if (zerop (vla-get-activespace *doc*))
                              (if (eq (vla-get-mspace *doc*) :vlax-true)
                                (vla-get-modelspace *doc*)
                                (vla-get-paperspace *doc*))
                              (vla-get-modelspace *doc*)))))

 (setq *a2f_Uni 2)[b][color=Red])[/color][/b]
 (or *a2f_Pre (setq *a2f_Pre 0))
 (or *a2f_Con (setq *a2f_Con 1.))
 (or *a2f_Hgt (setq *a2f_Hgt (getvar 'TEXTSIZE)))
 (setq *a2f_Rot 0.)[b][color=Red])[/color][/b]
 (or *a2f_Suf (setq *a2f_Suf "m2"))

 (mapcar (function set) '(*a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)
         (mapcar
           (function
             (lambda (ini foo msg x)
               (and ini (initget ini))
               (cond ((and (setq tmp ((eval foo) (strcat "\n" msg " <" (Stringify x) "> : ")))
                           (/= "" tmp)) tmp)
                     (x))))
            
            (list 4 6 6 nil)
           '(GetInt GetReal GetDist GetString)
           '("Specify Precision" "Specify Conversion Factor"
             "Specify Text Height" "Specify Suffix")
            (list *a2f_Pre *a2f_Con *a2f_Hgt *a2f_Suf)))
           
 (while
   (progn
     (setq ent (car (entsel "\n>> Pick Hatch [And don't you dare pick anything else]  >>")))

     (cond (  (eq 'ENAME (type ent))

              (if (and (eq "AcDbHatch" (vla-get-ObjectName (setq obj (vlax-ename->vla-object ent))))
                       (vlax-property-available-p obj 'Area))
                
                (if (setq pt (getpoint "\nPick Point for Field: "))
                  (progn
                    (setq uFlag (not (vla-StartUndoMark *doc*)))

                    (setq tObj
                      (vla-AddMText *spc* (vlax-3D-point pt) 0.0
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                (vl-princ-to-string (vla-get-ObjectId obj))
                                ">%).Area \\f \"%lu" (itoa *a2f_Uni) "%pr"
                                (itoa *a2f_Pre) "%ps[," *a2f_Suf "]%ct8[" (rtos *a2f_Con) "]\">%")))

                    (mapcar
                      (function
                        (lambda (property value)
                          (vlax-put-property tObj property value)))

                      '(Height Rotation Layer Color)
                       (list *a2f_Hgt *a2f_Rot (vlax-get-property obj 'Layer)
                                               (vlax-get-property obj 'Color)))

                    (setq uFlag (vla-EndUndoMark *doc*))

                    t) ;; repeat

                  )

                (princ "\n** Invalid Object Selected **"))))))
 (princ))



 

when I removed it- is working great

 

thanks for all your help

Posted

Why did you change that part? All that means is that it wouldn't remember the last entry for default.

Posted

I thought this is to set 'variables' and don't ask user for them- sorry I'm not good in lisp - I was just trying to modify it...with my poor knowledge about programming lisp.

I've changed few lines below as well- sorry I did lot of mess but is working :)

 

Thanks once again!

Posted

(defun c:a2f (/ *error* Stringify ENT OBJ PT TMP TOBJ TYP UFLAG)
 ;; Lee Mac  ~  13.01.10

 (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument
                              (vlax-get-acad-object))))

       *spc* (cond (*spc*) ((if (zerop (vla-get-activespace *doc*))
                              (if (eq (vla-get-mspace *doc*) :vlax-true)
                                ([color="red"]vla-get-modelspace *doc*[/color])
                                (vla-get-paperspace *doc*))
                              ([color="red"]vla-get-modelspace *doc*[/color])))))            

 

Must be modified also.

 

Regards

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