Jump to content

Recommended Posts

Posted

I have been trying to get the routine to work for a couple days and I can't find a way to get past this error in the visual lisp code checker "; error: bad function: ("1" "Plant__" "1164")".

When I step through the code it gives me the correct results but I skip the while expression in order to get the correct result. So I believe that is where my error is. When I run the routine in autocad window I get this error "; error: bad argument type: consp nil".

 

Any suggestions?

(Attatched is the file I am using to collect the Tag data)

 

Note: The getattdata program is part of another lisp routine that collects the block data into lists and remains the same from the previous program. The only part that I created was the npinum Program portion.

 

 

 
;;;--- Function to get the block data
(defun getAttData(/ eset dataList blkCntr en enlist blkType blkName entName 
                    attTag attVal group66)
 ;;;--- Set up an empty list
 (setq dataList(list))
 ;;;--- If that type of entity exist in drawing
 (if (setq eset(ssget ":s" (list (cons 0 "INSERT"))))
   (progn
     ;;;--- Set up some counters
     (setq blkCntr 0 cntr 0)

     ;;;--- Loop through each entity
     (while (< blkCntr (sslength eset))

       ;;;--- Get the entity's name
       (setq en(ssname eset blkCntr))

       ;;;--- Get the DXF group codes of the entity
       (setq enlist(entget en))
       ;;;--- Get the name of the block
       (setq blkName(cdr(assoc 2 enlist)))

       ;;;--- Check to see if the block's attribute flag is set
       (if(cdr(assoc 66 enlist))
         (progn

           ;;;--- Get the entity name
           (setq en(entnext en))

           ;;;--- Get the entity dxf group codes
           (setq enlist(entget en))

           ;;;--- Get the type of block
           (setq blkType (cdr(assoc 0 enlist)))

           ;;;--- If group 66 then there are attributes nested inside this block
           (setq group66(cdr(assoc 66 enlist)))

           ;;;--- Loop while the type is an attribute or a nested attribute exist
           (while(or (= blkType "ATTRIB")(= group66 1))

             ;;;--- Get the block type 
             (setq blkType (cdr(assoc 0 enlist)))

             ;;;--- Get the block name         
             (setq entName (cdr(assoc 2 enlist)))

             ;;;--- Check to see if this is an attribute or a block
             (if(= blkType "ATTRIB")
               (progn

                 ;;;--- Save the name of the attribute
                 (setq attTag(cdr(assoc 2 enlist)))

                 ;;;--- Get the value of the attribute
                 (setq attVal(cdr(assoc 1 enlist))) 

                 ;;;--- Save the data gathered
                 (setq dataList(append dataList(list (list blkName attTag attVal))))

                 ;;;--- Increment the counter
                 (setq cntr (+ cntr 1))

                 ;;;--- Get the next sub-entity or nested entity as you will
                 (setq en(entnext en))

                 ;;;--- Get the dxf group codes of the next sub-entity
                 (setq enlist(entget en))

                 ;;;--- Get the block type of the next sub-entity
                 (setq blkType (cdr(assoc 0 enlist)))

                 ;;;--- See if the dxf group code 66 exist.  if so, there are more nested attributes
                 (setq group66(cdr(assoc 66 enlist)))
               ) 
             )
           )
         )

         ;;;--- Else, the block does not contain attributes
         (progn

           ;;;--- Setup a bogus tag and value
           (setq attTag "" attVal "")
           ;;;--- Save the data gathered
           (setq dataList(append dataList(list (list blkName attTag attVal))))
         )
       )
       (setq blkCntr (+ blkCntr 1))
     )
   )                    
 )
 dataList
)
(defun c:npinum(/ datalist cnt pl ln off ls vr txt)
         ;;;--- Get a the data from the blocks
         (setq dataList(getattData))
         ;;;--- Set up counter
  (setq cnt 0)

         ;;;--- Define pl
    (setq pl "Plant__")

    ;;;--- Set loop off switch
    (setq off 0)

    ;;;--- Loop to find the Correct Tag
(while (= off 0)
  (
         ;;;--- Get each entry 
     (setq ls (nth cnt dataList))

      ;;;--- Get only the Tag Name
    (setq vr (nth 1 ls))

  ;;;--- Check if Tag matches 
   (If (= vr pl)
       (progn

          ;;;--- Set txt to Tag Value
   (setq txt(last ls))

   ;;;--- Turn off Loop
   (setq off(+ off 1))
       )
      ;;;--- If txt not found look at next item
     (Progn
 (setq cnt (+ cnt 1))
     )
   )
        )
      )    


        ;;;--- Set layer to 0 layer
 (command "layer" "set" "0" "")

   ;;;--- Place text with Tag Value
        (Command "MTEXT" PAUSE "WIDTH" "3" txt "")    

 (princ) 
))

NPI_xx.dwg

Posted

Hi elilewis,

 

Welcome to the forum.

 

As you suggest the while expression in the npinum routine seems to be causing an error. There is an extra bracket

 

;;;--- Loop to find the Correct Tag

(while (= off 0)

(

;;;--- Get each entry

(setq ls (nth cnt dataList))

 

 

Try the following an see how it goes

 

(defun c:npinum(/ ); datalist cnt pl ln off ls vr txt)
         ;;;--- Get a the data from the blocks
         (setq dataList(getattData))
         ;;;--- Set up counter
  (setq cnt 0)

         ;;;--- Define pl
    (setq pl "Plant__")

    ;;;--- Set loop off switch
    (setq off 0)

    ;;;--- Loop to find the Correct Tag
(while (= off 0)
  
[color="Red"]   ;( -> Extra bracket removed[/color]
  
         ;;;--- Get each entry 
     (setq ls (nth cnt dataList))

      ;;;--- Get only the Tag Name
    (setq vr (nth 1 ls))

  ;;;--- Check if Tag matches 
   (If (= vr pl)
       (progn

          ;;;--- Set txt to Tag Value
   (setq txt(last ls))

   ;;;--- Turn off Loop
   (setq off(+ off 1))
       )
      ;;;--- If txt not found look at next item
     (Progn
 (setq cnt (+ cnt 1))
     )
   )
        );End of while
   [color="Red"]     -> Extra bracket removed[/color]


        ;;;--- Set layer to 0 layer
   (command "layer" "set" "0" "")

   ;;;--- Place text with Tag Value
        (Command "MTEXT" PAUSE "WIDTH" "3" txt "")    

 (princ) 
)[color="Red"]
-> Extra bracket removed

[/color]

 

Regards,

 

Jammie

Posted

Do you really need the blkcounter in there, if, in the ssget you are only allowing a single entity?

Posted

Thank you for your help everyone. It works now with no errors. I have some added things like the blkcounter because I am going to expand the program later to step through each one of the blocks and place the text automatically. I am new at the lisp coding and needed to start somewhere and didn't want bite off too much. I have been reading different lisp code and trying to find the proper ways to use expressions, it seems to be working but everyonce and a while I hit a snag. Thank you again for your help.

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