See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Too few arguments, can someone check please?

  1. #1
    Member
    Join Date
    2010-11
    Posts
    21
    Login to Give a bone
    0

    Default Too few arguments, can someone check please?

    Hi,

    I'm still a LISP beginner, and I've been trying to write a routine to take all text and mtext entities and write them to a CSV file in Excel. I could be approaching it the wrong way, but as it stands I'm getting the "too few arguments" error and it's starting to bug me! Could anyone take a look? Also if i'm doing anything wrong please let me know, I don't even know if this code will work yet!

    Thanks

    (defun c:extxt (fname tlst / sset k edata txt)
    (vl-load-com)
    (command "undo" "be")
    (setq fname (getfiled "Text to CSV" "" "csv" 1))
    (setq sset (ssget "_x" '((0 . "mtext,text"))))
    (setq k 0)
    (while (< k (sslength sset))
    (setq edata (entget (ssname sset k)))
    (setq txt (cdr (assoc 1 edata)))
    (setq tlst (cons txt tlst))
    (setq k (1+ k))
    );while
    (fwrite fname "w" (cons NIL tlst))
    (command "undo" "e")
    );defun


    (defun fwrite (fname tlst / fno e)
    (setq fno (open fname "w"))
    (foreach e tlst (write-line e fno))
    (close fno)
    ) ;defun



    One other thing - my selection set excludes text in blocks, etc. Is there a quick fix to use blocks too?

  2. #2
    Member
    Join Date
    2010-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    Quick update,

    I'm guessing the "too few arguments" was to do with localising my variables, if I change the first line temporarily to:

    (defun c:extxt (/)

    It seems to pass, and attempt the routine. I'm now getting a "too many arguments" error, and I believe it's on the line:

    (fwrite fname "w" (cons NIL tlst))

    Anyone know why?

    Thanks
    Last edited by mrsusan; 2011-10-13 at 09:35 AM. Reason: typo

  3. #3
    All AUGI, all the time marko_ribar's Avatar
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    556
    Login to Give a bone
    1

    Default Re: Too few arguments, can someone check please?

    You are guessing correctly... Correct would be :

    Code:
    (defun c:extxt ( / fname sset k edata txt tlst )
    (command "undo" "be")
    (setq fname (getfiled "Text to CSV" "" "csv" 1))
    (setq sset (ssget "_x" '((0 . "mtext,text"))))
    (setq k 0)
    (while (< k (sslength sset))
    (setq edata (entget (ssname sset k)))
    (setq txt (cdr (assoc 1 edata)))
    (setq tlst (cons txt tlst))
    (setq k (1+ k))
    );while
    (fwrite fname tlst)
    (command "undo" "e")
    );defun
    
    
    (defun fwrite ( fname tlst / fno )
    (setq fno (open fname "w"))
    (foreach e tlst (write-line e fno))
    (close fno)
    ) ;defun
    You don't need (vl-load-com) as it's all Vanilla Alisp... Please use Code Tags when posting on sites where BBC is enabled...
    [code]Your code[/code]

    M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  4. #4
    Member
    Join Date
    2010-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    Thank you so much, you're a genius!

    Now I need to fine tune this baby. My test DWG has 4 text elements in it, the CSV file reads them but repeats the list 7 times over :/ Any ideas?

    I don't suppose you also know if I just have to use another SSGET to get text values of blocks,attblocks?

    Thanks in advance

  5. #5
    All AUGI, all the time marko_ribar's Avatar
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    556
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    And to include blocks with attributes, try :

    Code:
    (defun c:extxt ( / fname sset k edata blA txt tlst )
    (vl-load-com)
    (command "undo" "be")
    (setq fname (getfiled "Text to CSV" "" "csv" 1))
    (setq sset (ssget "_x" '((0 . "insert,mtext,text"))))
    (setq k 0)
    (while (< k (sslength sset))
    (setq edata (entget (ssname sset k)))
    (if (eq (cdr (assoc 0 edata)) "INSERT")
      (progn
      (setq blA (vlax-ename->vla-object (ssname sset k)))
      (if (eq (vlax-property-available-p blA 'Path) nil)
        (if (eq (vla-get-HasAttributes blA) :vlax-true)
          (foreach att (vlax-invoke blA 'getattributes)
            (setq txt (vla-get-textstring att))
    	(setq tlst (cons txt tlst))
          )
        )
      )
      )
      (progn
        (setq txt (cdr (assoc 1 edata)))
        (setq tlst (cons txt tlst))
      )
    )  
    (setq k (1+ k))
    );while
    (fwrite fname tlst)
    (command "undo" "e")
    );defun
    
    
    (defun fwrite ( fname tlst / fno )
    (setq fno (open fname "w"))
    (foreach e tlst (write-line e fno))
    (close fno)
    ) ;defun
    M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  6. #6
    Member
    Join Date
    2010-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    Wow, thank you so much for your help, when it comes to vlax stuff I'm well out of my comfort zone!

    The code you produced runs good, although it doesn't return all text and mtext elements. Incidentally, the original code you modified for me (minus the att-blocks) seems to return more text, but still not all.

    I've already asked you for too much, but if you had any ideas as to why it's missing text out it would be appreciated.

    Just so you know, the reason as to why I'm writing this is so all text can be exported, sent to be translated, then put back into AutoCAD where I have a text-replace routine already written.

    Thanks

  7. #7
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    My version:

    Code:
    (defun c:txt2csv ( / data file ) (vl-load-com)
        (cond
            (   (not
                    (progn
                        (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                            (if (eq :vlax-false (vla-get-isxref block))
                                (vlax-for obj block
                                    (if (wcmatch (vla-get-objectname obj) "AcDb*Text")
                                        (setq data (cons (vla-get-textstring obj) data))
                                    )
                                )
                            )
                        )
                        data
                    )
                )
                (princ "\nNo Text or MText found.")
            )
            (   (not (setq file (getfiled "Create CSV file" "" "csv" 1)))
                (princ "\n*Cancel*")
            )
            (   (setq file (open file "w"))
                (foreach x data (write-line x file))
                (setq file (close file))
                (princ (strcat "\n" (itoa (length data)) " strings written to file."))
            )
        )
        (princ)
    )
    Will write all Text / MText strings in Model / Layouts / Blocks to a CSV file (not attributes, these may be added if necessary).

    Be aware that text containing a comma will span cells.
    Lee Mac ProgrammingTwitter

    With Mathematics there is the possibility of perfect rigour, so why settle for less?


  8. #8
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    To include Attributed Blocks (including all nested to any level):

    Code:
    (defun c:txt2csv ( / data file ) (vl-load-com)
        (cond
            (   (not
                    (progn
                        (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                            (if (eq :vlax-false (vla-get-isxref block))
                                (vlax-for obj block
                                    (cond
                                        (   (wcmatch (vla-get-objectname obj) "AcDb*Text")
                                            (setq data (cons (vla-get-textstring obj) data))
                                        )
                                        (   (and
                                                (eq "AcDbBlockReference" (vla-get-objectname obj))
                                                (eq :vlax-true (vla-get-hasattributes obj))
                                            )
                                            (foreach att (vlax-invoke obj 'getattributes)
                                                (setq data (cons (vla-get-textstring att) data))
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        data
                    )
                )
                (princ "\nNo Text or MText found.")
            )
            (   (not (setq file (getfiled "Create CSV file" "" "csv" 1)))
                (princ "\n*Cancel*")
            )
            (   (setq file (open file "w"))
                (foreach x data (write-line x file))
                (setq file (close file))
                (princ (strcat "\n" (itoa (length data)) " strings written to file."))
            )
        )
        (princ)
    )
    Lee Mac ProgrammingTwitter

    With Mathematics there is the possibility of perfect rigour, so why settle for less?


  9. #9
    Member
    Join Date
    2010-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    Jesus wept, that worked perfectly! The CSV file was a bit messy but I can't complain, that's great - thanks!

    I was wondering if I could pick your brain over one last thing. I'm now trying to replace the text with a foreign language, using the following works fine (not going to bother loading other definitions):

    Code:
    (defun c:replacer ( / relist elist olist nlist k alltext)
    	(command "undo" "be")
    	(setq relist (cdr (ReadFile "G:\\list1.csv")))
    	(foreach e relist
    		(setq elist (string->list e ","))
    		(setq olist (cons (nth 0 elist) olist))
    		(setq nlist (cons (nth 1 elist) nlist))
    	); foreach
    	(setq alltext (ssget "x" '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>")))) 
    	(if (/= alltext NIL)
    		(progn
    			(setq k 0)
    			(while (< k (length olist))
    				(txt_replace (nth k olist) (nth k nlist) T 3 "*" "*" alltext)
    				(setq k (1+ k))
    			); while
    		); progn
    	); if
    	(command "undo" "end")
    ); defun
    
    (defun ReadFile (fname / fno txt flst e flst1)
    	(if (/= fname NIL)
    		(progn
    			(setq fno (open fname "r"))
    			(setq txt (read-line fno))
    			(while (/= txt nil)
    				(setq flst (cons txt flst))
    				(setq txt (read-line fno))
    			) ;while
    			(close fno)
    			(while (= (nth 0 flst) "")
    				(setq flst (cdr flst))
    			) ;while
    			(setq flst (reverse flst))
    		) ;progn
    	) ;if
    	(setq flst flst)
    ) ;defun
    But instead of hard coding the CSV path, I'd like a user prompt, so did this (which doesn't work, it returns error: bad argument type: consp "LIST1.csv")

    Code:
    (defun c:replacer ( / relist elist olist nlist k alltext)
    	(command "undo" "be")
    	(setq relist (getfiled "Select CSV File" "" "csv" 8))
    	(foreach e relist
    		(setq elist (string->list e ","))
    		(setq olist (cons (nth 0 elist) olist))
    		(setq nlist (cons (nth 1 elist) nlist))
    	); foreach
    	(setq alltext (ssget "x" '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>")))) 
    	(if (/= alltext NIL)
    		(progn
    			(setq k 0)
    			(while (< k (length olist))
    				(txt_replace (nth k olist) (nth k nlist) T 3 "*" "*" alltext)
    				(setq k (1+ k))
    			); while
    		); progn
    	); if
    	(command "undo" "end")
    ); defun
    What am i doing wrong? Cheers from a fellow Londoner

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,483
    Login to Give a bone
    0

    Default Re: Too few arguments, can someone check please?

    You are not using the ReadFile function on the file. Once the function is used on the file, it will place the contents of the file into a list.

    Does that help?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 9
    Last Post: 2017-10-16, 04:27 PM
  2. error: too many arguments??
    By tedg in forum AutoLISP
    Replies: 3
    Last Post: 2010-08-31, 02:58 AM
  3. arguments
    By d_m_hopper in forum AutoLISP
    Replies: 4
    Last Post: 2007-08-24, 03:03 PM
  4. Help fix a routine - Error: too few arguments
    By cadd4la in forum AutoLISP
    Replies: 3
    Last Post: 2006-01-10, 06:06 PM
  5. too few arguments on compile
    By voigtmark in forum AutoLISP
    Replies: 3
    Last Post: 2005-10-28, 06:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •