Jump to content

Recommended Posts

  • Replies 61
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    31

  • Lee Mac

    22

  • David Bethel

    6

  • borgunit

    1

Posted

Well, if the error is too many arguments, I would assume it lies elsewhere in the code - as, my supplied code works when not in the main code, and calling the function doesn't leave much room for mistakes.

Posted

The code worked fine before the add_in.

It reports back the correct quantities two different ways.

And as far as the error: Its ;error is too few arguments.

Did you run the last code I sent you?

Posted

Ok I found the problem. I made an edit to the layer name function

calling out the new function you gave me and I forgot to remove it.

 

Sorry about that Lee_Mac the code is fine. Excellent work!

I think I can fix the rest from here. I hope I do not screw-up

the rest.

 

I will re-post when completed.

 

Thanks Again,

The Buzzard

Posted

Cool, no worries Buzzard - everyone makes a few mistakes - after all we're only human, or in your case - bird.

 

Cheers

 

Lee

Posted

Please realize its not easy to work a keyboard with feathers instead of fingers.

Posted

Lee,

 

If and when you have a moment? Would you be able to do a line by line interpretation of the last code you posted for me? I have an idea of what is going on with regards to the function commands used. The problem I am having is understanding how they are used in arguments. This would make alot of sense to me, If I knew how to understand those portions of the code.

 

Thank You,

The Buzzard

Posted

Hi ALL,

 

I am on the last section of the code. This part is suppose to get the numerical values of filtered blocks and add them together. It will then take the total and place it in another block.

 

The code below was by an unknown author and it is well suited to do what I needed, But it had to be modified to select blocks by filtering instead of windowing.

 

ADDQTYS.Lsp

(defun c:AddQtys (/ elist ename epick index number ssqtys text total)
 (princ "\nSelect blocks to add up quantities.")
 (if (setq ssqtys (ssget (list '(66 . 1))))
   (progn
     (setq total 0)
     (setq index 0)
     (repeat (sslength ssqtys)
       (setq ename (ssname ssqtys index))
       (setq elist (entget ename))
       (while (/= (cdr (assoc 0 elist)) "SEQEND")
         (setq elist (entget ename))
         (if (= "CAB-QTY" (cdr (assoc 2 elist)));Change tag name here
           (progn
             (setq number (cdr (assoc 1 elist)))
             (if (= (atoi number) (atof number))
               (setq number (atoi number))
               (setq number (atof number))
             )
             (princ number) (princ " + ")
             (setq total (+ total number))
           )
         )
         (setq ename (entnext ename))
       )
       (setq index (1+ index))
     )
   )
 )
 (if (> total 0)
   (progn
     (if (= (fix total) (float total))
       (setq total (itoa total))
       (setq total (rtos total 2 2))
     )
     (setq text (strcat "\nSelect block to update quantity with " total ": "))
     (if (setq epick (entsel text))
       (progn
         (setq ename (car epick))
         (setq elist (entget ename))
         (while (/= (cdr (assoc 0 elist)) "SEQEND")
           (setq elist (entget ename))
           (if (= "JACK-QTY" (cdr (assoc 2 elist)));Change tag name here
             (progn
               (entmod (subst (cons 1 total) (assoc 1 elist) elist))
               (entupd ename)
             )
           )
           (setq ename (entnext ename))
         )
       )
     )
   )
 )
 (princ)
)
(princ)

 

Also attached in the zip folder is my code with this add-in and modified to select the blocks by filtering, However I ran into a problem

trying to use ssget to find the BOM Block in the supplied drawing in the zip folder. I have an idea as to where the problem is, But I have run out of answers. I indicate the area in the code as to where I think the problem is. Any ideas or help would be appreciated.

 

Thanks,

The Buzzard

CDL.zip

Posted

Perhaps this:

 

Bear in mind you are retrieving a Selection set with ssget,

 

Therefore you cannot just say "entget" ss.

 

You need to look at the ssname (i.e. ename)

 

(see attached)

 

*only roughly looked at though*

CDL.zip

Posted

Thanks Lee_Mac for looking at it.

 

I added one closing bracket to the new statement that was added.

I realize you looked at it quickly.

It suppresses the error, But did not produce any results.

I guess I need to walk away from this for a short while.

I am very puzzled from this one. I will look further into it later.

 

Again Thanks as Always for the help.

The Buzzard

Posted

Just remember the differences between a selection provided by "entsel" and one provided by "ssget".

 

The "ssget" produces a Selection Set from which entity names (like those provided by "entsel" can be extracted (using ssname, or ssnamex).

 

You can create a list of entity names from a selection set using the "ssnamex" function, but, as these may sometimes contain extra information about how the selection set was picked, you will need to include a "vl-remove-if 'listp" to take out any unwanted additional information

 

i.e.

 

(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))

 

The above will return a list of entity names (like those produced by entsel).

 

With a list like this, entity manipulation becomes a lot easier, as list functions like "mapcar" "foreach" etc etc can be used, as opposed to just "shuffling" through the selection set using a while function.

Posted

I appreciate you going further into this for me, But I am not familar with visual lisp , let alone selection sets. I know that this can be worked out the way I was going, But its like walking on rice paper.

The program I used for this worked very well before I got to it. I just

need to approach it a step at a time.

 

Thanks

Posted
Lee,

 

If and when you have a moment? Would you be able to do a line by line interpretation of the last code you posted for me? I have an idea of what is going on with regards to the function commands used. The problem I am having is understanding how they are used in arguments. This would make alot of sense to me, If I knew how to understand those portions of the code.

 

Thank You,

The Buzzard

 

Hi Buzzard,

 

I have a few minutes, so I'll see if I can concoct some kind of explanation:

 


(defun attupd ; [b][color=Red]Define a Local Function (as opposed to (defun c:))[/color][/b]

      (nVal / ss bEnt) ; [b][color=Red]Localise the variables and arguments ~ one argument: nVal.[/color][/b]
 
 (if ; [b][color=Red]If the following returns T:[/color][/b]
   
   (and ; [b][color=Red]ALL of the following must return T:[/color][/b]
     
     (setq ss ; [b][color=Red]Set variable ss to:[/color][/b]
        
        (ssget "X" ;[b][color=Red] "X" to search entire database for:[/color][/b]
                       
              (list ;[b][color=Red] create list of conditions[/color][/b]

                (cons 0 "INSERT") ;[b][color=Red] "INSERT" type ~ Blocks/XRefs[/color][/b]
                
                (cons 2 "BOM") ;[b][color=Red] With name of "BOM"[/color][/b]
                
                (cons 66 1) ; [color=Red][b]Attributed Blocks only please...[/b][/color]
                
                (if (getvar "CTAB") ; [b][color=Red]If there exists a variable CTAB (layout tab variable)[/color][/b]
                  
                  (cons 410 (getvar "CTAB")) ;[b][color=Red] Then filter by it[/color][/b]
                  
                  (cons 67 (- 1 (getvar "TILEMODE"))) ;[b][color=Red] Otherwise use the "TILEMODE" variable[/color][/b]
                  
                ) ; [b][color=Red]end if[/color][/b]
                
              ) ;[color=Red][b] end list[/b][/color]
           
           ) ; [b][color=Red]end ssget[/color][/b]
       
      ) ; [color=Red][b]end setq[/b]
     [/color]
      (= (sslength ss) 1) ; [b][color=Red]If the Selection Set only contains 1 item (only one BOM block)[/color][/b]
     
     ) ; [color=Red][b]end and[/b][/color]
   
   (progn ; [b][color=Red]Then do the following (progn is program wrapper)[/color][/b]
     
     (setq bEnt ; [b][color=Red]set variable bEnt to the following[/color][/b]
        
        (entget (entnext (ssname ss 0))) ; [b][color=Red]Retrieve the DXF Table of the attribute of BOM[/color][/b]
       
       bEnt ; [b][color=Red]re-assign the variable bEnt to:[/color][/b]
        
        (subst ; [b][color=Red]Substitute
          [/color][/b]
          (cons 1 nVal) ; [b][color=Red]the New Attribute value (nVal ~ the argument required)[/color][/b]
          
          (assoc 1 bEnt) ; [b][color=Red]to replace the old attribute value[/color][/b]
          
          bEnt) ; [b][color=Red]search the DXF Table for these values[/color][/b]
       
     ) ; [b][color=Red]end setq[/color][/b]
     
     (entmod bEnt) ; [b][color=Red]modify the attribute DXF Table to account for these changes[/color][/b]
     
   ) ; [b][color=Red]end progn (otherwise...)[/color][/b]
   
   (princ "\n<!> None/Multiple BOM Blocks Found <!>") ; [b][color=Red]No or Multiple BOM Blocks found (if AND doesn't return T)[/color][/b]
   
 ) ; [color=Red][b]end if[/b][/color]
 
 (princ) ;[color=Red] [b]exit cleanly[/b][/color]
 
) ; [color=Red][b]end function[/b][/color]


 

Hope this helps somewhat :)

 

If you have any further questions, just ask :)

 

Cheers

 

Lee :mrgreen:

Posted

Ok Lee_Mak I GOT IT!

 

 

Before
(while (/= (cdr (assoc 0 elist)) "SEQEND")

After
(while (/= (cdr (assoc 2 elist)) "SEQEND")

 

It works great! Now its time to finish this code off! I hope to post the finished version soon.

 

Thanks,

The Buzzard

Posted
Ok Lee_Mak I GOT IT!

 

 

Before
(while (/= (cdr (assoc 0 elist)) "SEQEND")

After
(while (/= (cdr (assoc 2 elist)) "SEQEND")

It works great! Now its time to finish this code off! I hope to post the finished version soon.

 

Thanks,

The Buzzard

 

 

HAHAHA school-boy error :P

 

Hope the explanation helps somewhat.

 

Cheers

 

Lee

Posted

The explanations are great. My problem is I get too far ahead of myself sometimes, Especially when it comes to learning new things.

 

From some of your previous codes posted I finally figured out the use of cons which opened up a whole new world for me. The came assoc.

The AutoCAD definitions of these and others I find very limited and dry reading, So I need to find other sources to see these operations in action.

 

When this code is complete I will break it all down again just to make sure I fully understand every line.

 

Thanks for all the help and code.

It will not go to waste.

The Buzzard

Posted

Have a look at other reference websites to see examples of how the different functions are put to use - don't just limit yourself to ACAD Help and Developers Help in the Visual LISP Editor (vlide at command prompt).

 

Check these out:

 

http://www.afralisp.net/

 

http://www.jefferypsanders.com/autolispbeg.html

 

http://klobouk.fsv.cvut.cz/~chour/Lisp/Chapter%201.htm

 

You will learn a ton of stuff from these sites.

 

Also,

 

http://www.74mph.com/faq/FAQ00066.html

 

and

 

http://autodesk.com/techpubs/autocad/acad2000/dxf/entities_section.htm

 

Are good for reference.

 

Hope this helps :)

Posted

I can sure use it!

 

I work with four monitors so there is plenty of room to have them open.

 

I am sure you know the sense of relief when the light goes on in your head. You can look at code over and over again and sometimes you do not get your answers until it bites you. I spent too much time on codes that did just entity creation that I never set some time to learn other things.

Posted

I know what you mean - it drives you crazy when you can't find the mistakes... and most of the time, the mistakes are only minor.. :)

 

But with experience, you get better at identifying mistakes, by analysing the error that occurs.

 

like for instance:

 

malformed list on input ~ missing ")"

 

extra right paren ~ extra ")"

 

numberp nil/stringp nil etc ~ variable set wrong or typed wrong

 

lselsetp nil ~ trying to do something with an empty selection set

 

bad argument ~ trying to feed a wrong argument type to a function

 

and there are many more. :)

Posted

I have gotton most of them down well. The only one from that group is the bad argument where most of my problems occur.

 

The only way I can get a good argument is if I am willing to pay for it like on that Monty Python skit about the Arguments.

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