Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy attribute from one tag to another tag within same block. Halp!!

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
bhull1985
9378 Views, 15 Replies

Copy attribute from one tag to another tag within same block. Halp!!

Hey all-

Sorry for the new thread but the old one was getting a bit out of focus, and I've had a full day to research my problem so that I may accurately describe what it is that I'm hoping to find.

 

Concisely, i need a program that will ask for an integer (getint "\nAttribute line to be moved>").

Then the program needs to attach the given integer to the following tags:

REV#

R#DESC

R#BY

R#CHK

R#DATE

 

In place of the #. Perhaps like this:


(setq rdate (strcat "R" num "DATE"))
(setq rchk (strcat "R" num "CHK"))
(setq rby (strcat "R" num "BY"))
(setq rdesc (strcat "R" num "DESC"))
(setq rev (strcat "REV" num)

 

-and/or-

 

(setq $rdatepre (substr 'rdate 1 1))

(setq $rdatesuf (substr 'rdate 3 4))

(setq new_rdate (strcat $rdatepre num $rdatesuf))

 

not sure which would be more effective or useful.

 

At this point the program will have the exact tag names within the specified block (that can be obtained via entsel, that is no problem). So with the tags to be 'moved' and the block selected already, the program then should store all of the values (there will be some) from the previously specified tags.

 

After storing the tag values, it should then re-write them in the same block, but to different tags. I.e. after giving the prog an integer of "4" and selecting the block, the program should then ask which line should the values be moved to? After giving the second user input integer, the program would now have the location to which the stored values should be moved to, and once placed within the new tags the information should be removed from the old tags, i.e. deleted out. In the illustration below the first getint would be assigned a value of "4" which means to move the 4th line from the top. Then I would tell it "5", to move it to one line below where it currently resides in this image.

12.jpg All tags within this block that shall be modified by the program follow that same structure outlined above, with the integers ranging from 1-7. I'd like to be able to swap these lines around, but not via a simple attribute move, that messes with the order of the attribute tags/values. I'd much prefer for a program capable of what I've described in order to 'move' my attribute lines correctly.

 

I've searched and searched and read and read, and will continue to do so, but am posting this here in the hopes that it's clear enough that someone can provide me a tool they've got. Surely this has been done before, a proper method as opposed to the multitude of 'move' attribute programs that in essence, grip edit tags. I need actual removal and placement into other existing tags.

 

Cheers 🙂

and thanks in advance!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
15 REPLIES 15
Message 2 of 16
scot-65
in reply to: bhull1985

Ready for this one?

Your program description is a little lengthy, and you did not tell us how far you have

developed this program, so us audience members do not know where to begin?

 

Attached file is a little program that matches attributes. The program structure

is quite different to that you are requesting, but most of the elements inside are

what you are looking for to get you started.

 

Good Luck!

 

scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 3 of 16
bhull1985
in reply to: scot-65

Thanks Scot65!

Yes, I have started on this'n, and as the description the code is fairly lengthy as i've currently got it to select the actual block tag names based on the (getint). I.e. every tag is set to a variable beforehand, and the (getint) lets the prog know which variables will be manipulated.

Thanks for your reference, i've actually got about 15 block attribute routines printed out and pinned together, but will add this one to them and place it on top.

 

I was pulled yesterday but this morning have more time to write so that's what I'll be doing.

 

Thanks for your post and I'll be sure to update this thread with a new reply once I get to a point that warrants doing so.

 

Cheers!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 4 of 16
bhull1985
in reply to: bhull1985

Thanks to pBe over at cadtutor, this has been solved!

Fancy, complex looking code that works great! 

Here take a peek:

 

 

(VL-LOAD-COM)
(defun c:rvb (/ _AttFunc ss i e values status void num);; Repair Revision Box
(defun _AttFunc  (en lst / vals v)
(mapcar (function (lambda (at)
 (setq vals (list (vla-get-tagstring at)(vla-get-textstring at)))
           (if (and lst (setq v (assoc (car vals) lst)))
                   (vla-put-textstring at (cadr v))) vals))
                      (vlax-invoke (if (eq (type en) 'VLA-OBJECT)
                                  en (vlax-ename->vla-object en)) 'Getattributes)
   )
  ) 
(setq atlst '("REV#" "R#DESC" "R#BY" "R#CHK" "R#DATE")) 
   (if (setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq e (ssname ss (setq i (1- i))))
     (if (setq values (vl-remove-if-not
          '(lambda (x)
      (setq tgnm (car x))
      (vl-some
        '(lambda (y)
           (wcmatch tgnm y)
         )
        atlst
      )
    )
          (_AttFunc e nil)
        )
  )
       (progn
  (setq status nil
        void nil
  )
  (repeat (setq num 7)
    (setq
      line (mapcar
      '(lambda (s)
         (vl-string-translate "#" (itoa num) s)
       )
      atlst
    )
    )
    (if (vl-every '(lambda (p)
       (/= (cadr (assoc p values)) "")
     )
    line
        )
      (setq status (cons num Status))
    )
    (setq num (1- num))
  )
  (repeat (- (setq lv (last status)) (car status))
    (if (not (member (setq lv (1- lv)) status))
      (setq void (cons lv void))
    )
  )
  (if (and (setq from (car status))
    (setq to (last void))
      )
    (progn
      (_AttFunc e
         (setq
    data (mapcar '(lambda (s)
      (list (vl-string-translate
       "#"
       (itoa from)
       s
            )
            ""
      )
           )
          atlst
         )
         )
      )
      (_Attfunc e
        (mapcar '(lambda (h)
     (list (vl-string-translate
      (itoa from)
      (itoa to)
      (car h)
           )
           (cadr (assoc (car h) values))
     )
          )
         data
        )
      )
    )
  )
       )
     )
   )
   )
   (princ)
 )

 

 

 

 

before:

112.jpg

after:

 

113.jpg

Bravo and thanks to pBe for this brilliant routine. Now, to try to understand it ! 😄

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 16
Lee_Mac
in reply to: bhull1985

Here is my attempt:

 

(defun c:fixblk ( / a b i s x )
    (if (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
        (repeat (setq i (sslength s))
            (mapcar
               '(lambda ( a b )
                    (mapcar '(lambda ( a b ) (vla-put-textstring (last a) (caddr b))) a b)
                )
                (setq a
                    (vl-sort
                        (mapcar
                           '(lambda ( x )
                                (vl-remove nil
                                    (mapcar
                                       '(lambda ( p )
                                            (vl-some
                                               '(lambda ( a )
                                                    (if (wcmatch (cadr a) p) a)
                                                )
                                                x
                                            )
                                        )
                                       '("REV#" "R#DESC" "R#BY" "R#CHK" "R#DATE")
                                    )
                                )
                            )
                            (LM:groupbyfunction
                                (mapcar
                                   '(lambda ( a )
                                        (list
                                            (vl-list->string
                                                (vl-remove-if-not '(lambda ( x ) (< 47 x 58))
                                                    (vl-string->list (vla-get-tagstring a))
                                                )
                                            )
                                            (strcase (vla-get-tagstring a))
                                            (vla-get-textstring a)
                                            (progn (vla-put-textstring a "") a)
                                        )
                                    )
                                    (vl-remove-if-not
                                       '(lambda ( a )
                                            (wcmatch (strcase (vla-get-tagstring a))
                                                "REV#,R#DESC,R#BY,R#CHK,R#DATE"
                                            )
                                        )
                                        (vlax-invoke
                                            (vlax-ename->vla-object (ssname s (setq i (1- i))))
                                            'getattributes
                                        )
                                    )
                                )
                                (lambda ( a b ) (= (car a) (car b)))
                            )
                        )
                       '(lambda ( a b ) (> (caar a) (caar b)))
                    )
                )
                (vl-remove-if '(lambda ( x ) (vl-every '(lambda ( y ) (= "" (caddr y))) x)) a)
            )
        )
    )
    (princ)
)

;; Group By Function  -  Lee Mac
;; Groups items considered equal by a given predicate function

(defun LM:groupbyfunction ( lst fun / tmp1 tmp2 x1 )
    (if (setq x1 (car lst))
        (progn
            (foreach x2 (cdr lst)
                (if (fun x1 x2)
                    (setq tmp1 (cons x2 tmp1))
                    (setq tmp2 (cons x2 tmp2))
                )
            )
            (cons (cons x1 (reverse tmp1)) (LM:groupbyfunction (reverse tmp2) fun))
        )
    )
)

(vl-load-com) (princ)

 

Quick demo:

 

fixblk.gif

Message 6 of 16
scot-65
in reply to: bhull1985

I figured someone else would jump in.

I attached a file that I created using the helping hands of others on this board.

Had it not been like this, I probably would only provide a key snippet or two to

get you going.

 

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 7 of 16
bhull1985
in reply to: scot-65

Lee-

Works greatly! This would be a slight upgrade over the previous working routine, because of the multi-line functionality. I haven't found a condition that distinguishes the usage of one over the other but that's alright, i'll have two nice routines tucked away when the next issue gets ready to go out and for that thanks.

I'm going to see what I can get into this week.

Cheers and thanks again

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 8 of 16
Lee_Mac
in reply to: bhull1985

You're very welcome Brandon - it was an interesting program to write Smiley Happy

I'm glad the program will prove useful in your work.

 

Lee

Message 9 of 16
bhull1985
in reply to: Lee_Mac

Yes definitely it shall, this in conjunction with your global attribute editor really "does a number" on the revision blocks that are standard with each client-bordered drawing that my company produces. See what I did there? Heh...anyhow,

I'm going to spend the next few mornings taking this routine into each piece and seeing if I can do the mental commenting of your routine, if you would. However....If you'd care to actually comment out some of the heftier parts of your routine ...that would be an invaluable tool for learning, as i've noticed that within both takes on the routine there is extensive usage of lambda functions that by definition are tough for me to understand from the first few educated glances.

It's early monday morning and all of the lisp forums have un-read posts, so i'll stay reading them in the meantime. Thanks a ton Lee your coding-reach within lisp is endless it seems, and i honor the chance to learn from your methodology and explination but would never demand it. We're all busy though so of course I understand if I'll need to find other material to study up on. Cheers! 

🙂

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 10 of 16
Lee_Mac
in reply to: bhull1985


@bhull1985 wrote:

However....If you'd care to actually comment out some of the heftier parts of your routine ...that would be an invaluable tool for learning, as i've noticed that within both takes on the routine there is extensive usage of lambda functions that by definition are tough for me to understand from the first few educated glances.

 

Thanks a ton Lee, your coding-reach within lisp is endless it seems, and i honor the chance to learn from your methodology and explination but would never demand it. We're all busy though so of course I understand if I'll need to find other material to study up on.


Thank you for your kind words Brandon, I appreciate your compliments for my programming.

 

I have taken some time to comment the entire program below, however, please be aware that there may be some typos lurking within the comments:

 

(defun c:fixblk ( / a b i s x )
    ;; Define function, declare local variables
    ;; To understand why variable localisation is important, see http://bit.ly/15Qw104
    
    (if ;; IF the following expression returns a non-nil value

        (setq s ;; Assign the following value to symbol 's'
 
            (ssget ;; Retrieve a selection set from the user

                "_:L" ;; Restrict the selection to objects on unlocked layers
                      ;; For information on SSGET mode strings, see http://bit.ly/137NmOJ

                '(                   ;; Use a selection filter list to restrict the selection to
                  
                     (0 . "INSERT")  ;; Block references...
                     (66 . 1)        ;; ...that are attributed
                  
                 ) ;; end quoted filter list
                
            ) ;; end SSGET
            
        ) ;; end SETQ

        ;; The following expression is the 'then' argument for the IF function,
        ;; to be evaluated if the test expression returns a non-nil value, i.e.
        ;; if a valid selection set is retrieved.
        
        (repeat (setq i (sslength s))
            ;; Evaluate the following expressions a number of times equal to
            ;; the number of items in the selection set.

            ;; When studying the following expressions, read the comments from
            ;; the innermost expression (labelled below) and read outwards.
            
            (mapcar
                ;; Evaluate the following function on each item in the supplied lists
                ;;
                ;; This expression will re-assign the attribute values in each group
                
               '(lambda ( a b )
                    ;; Define an anonymous function accepting two arguments:
                    ;; both arguments are the same set of lists, but the second argument will
                    ;; be asynchronous with the first if any empty values have been removed.
                    
                    (mapcar
                        ;; Evaluate the following function on each item in the supplied lists
                        ;;
                        ;; Now we are operating on each attribute data list within the group

                       '(lambda ( a b )
                            ;; Define another anonymous function accepting two arguments:
                            ;; again, both arguments are attribute data lists, as constructed
                            ;; earlier, but will not be identical if groups have been removed
                            ;; from the main list.

                            (vla-put-textstring (last a) (caddr b))
                            ;; Populate the value of the ActiveX textstring property
                            ;; of the Attribute Reference VLA-Object with the 3rd item
                            ;; (i.e. the current value) of the attribute from the attribute
                            ;; data held by the second argument - this argument will never contain
                            ;; an empty string as a result of the operations performed earlier.

                        ) ;; end LAMBDA
                       
                        a b
                       ;; Each of these arguments contains a list of grouped attribue data
                       ;; If all rows have been filled, these arguments will be identical.
                       ;; If some rows are missing, the lists will be automatically out of sync
                       ;; as a consequence of the earlier operations and hence the values will be
                       ;; reordered.

                    ) ;; end MAPCAR
                    
                ) ;; end LAMBDA
               
                (setq a
                    ;; Assign the following list to the symbol 'a'
                    ;; This list is the 1st argument for our anonymous lambda function
                    ;; to be evaluated by MAPCAR.
                       
                    (vl-sort
                        ;; Sort the following items using the supplied sorting function.
                        ;;
                        ;; This will sort the rows of attribute information in descending
                        ;; order by the numerical content of each attribute tag.
                        
                        (mapcar
                            ;; Evaluate the following function on all items
                            ;; in the supplied list of lists.
                            ;; 
                            ;; This will return a list of lists where each item
                            ;; is a list of lists containing the information for
                            ;; the attributes in each row, ordered consistently
                            ;; by attribute tag.
                            
                           '(lambda ( x )
                                ;; Define an anonymous function accepting a single list argument
                                
                                (vl-remove nil
                                    ;; Remove the 'nil' symbol from the following list
                                    ;; to account for the possibility that an attribute tag
                                    ;; is not present (quite unlikely, but still a possibility)
                                    
                                    (mapcar
                                        ;; Evaluate the following function on all items
                                        ;; in the supplied list of strings.
                                        
                                       '(lambda ( p )
                                            ;; Define an anonymous function accepting a single
                                            ;; argument (a wildcard pattern string).
                                            
                                            (vl-some
                                                ;; Evaluate the following function on items
                                                ;; in the supplied list until the function returns
                                                ;; a non-nil value, at which point cease evaluation
                                                ;; and return the first non-nil result.
                                                
                                               '(lambda ( a )
                                                    ;; Define an anonymous function accepting a
                                                    ;; single argument (a list)
                                                    
                                                    (if ;; IF the following returns a non-nil value
                                                        
                                                        (wcmatch (cadr a) p)
                                                        ;; If the second item in the supplied list
                                                        ;; (the uppercase tagstring property)
                                                        ;; matches the given pattern

                                                        a ;; Return the item to VL-SOME
                                                        
                                                    ) ;; end IF
                                                    
                                                ) ;; end LAMBDA
                                               
                                                x ;; The group of lists considered equal
                                               
                                            ) ;; end VL-SOME
                                            
                                        ) ;; end LAMBDA
                                       
                                       '("REV#" "R#DESC" "R#BY" "R#CHK" "R#DATE")
                                        ;; A list of wildcards to ensure that all attribute
                                        ;; references appear in a consistent order before
                                        ;; the values are replaced.
                                       
                                    ) ;; end MAPCAR
                                    
                                ) ;; end VL-REMOVE
                                
                            ) ;; end LAMBDA
                           
                            (LM:groupbyfunction
                                ;; Group items in the following list that are considered
                                ;; equal by the supplied predicate function.
                                ;;
                                ;; This will group the lists of information for each
                                ;; Attribute Reference into a list of lists, where
                                ;; each list contains the attribute information for
                                ;; each row of the revision block.
                                
                                (mapcar
                                    ;; Evaluate the following function on every
                                    ;; item in the list of Attribute Reference VLA-Objects
                                    ;; returned by VL-REMOVE-IF-NOT and return a list
                                    ;; of the results of each evaluation.
                                    
                                   '(lambda ( a )
                                        ;; Define an anonymous function accepting a single
                                        ;; argument (an Attribute Reference VLA-Object)
                                        
                                        (list ;; Construct a list of the following items:
                                            
                                            (vl-list->string
                                                ;; Convert the following list of ASCII character
                                                ;; codes to a string
                                                
                                                (vl-remove-if-not
                                                    ;; Remove character codes in the given list
                                                    ;; which do not meet the condition set by the
                                                    ;; following predicate function:

                                                   '(lambda ( x )
                                                        ;; Define an anonymous function accepting
                                                        ;; a single argument (ASCII character code)

                                                        (< 47 x 58)
                                                        ;; Remove character codes which are not
                                                        ;; in the range 47 < x < 58

                                                    ) ;; end LAMBDA
                                                   
                                                    (vl-string->list
                                                        ;; Convert the given string into a list
                                                        ;; of ASCII character codes.

                                                        (vla-get-tagstring a)
                                                        ;; Retrieve the ActiveX tagstring property
                                                        ;; of the Attribute Reference VLA-Object
                                                        
                                                    ) ;; end VL-STRING->LIST
                                                   
                                                ) ;; end VL-REMOVE-IF-NOT
                                                
                                            ) ;; end VL-LIST->STRING
                                            
                                            (strcase (vla-get-tagstring a))
                                            ;; Retrieve the ActiveX tagstring property of the
                                            ;; Attribute Reference VLA-Object and convert it
                                            ;; to uppercase.
                                            
                                            (vla-get-textstring a)
                                            ;; Retrieve the ActiveX textstring property of the
                                            ;; Attribute Reference VLA-Object (the attribute value)
                                            
                                            (progn
                                                ;; Evaluate the following expressions and return
                                                ;; the value of the last expression evaluated.

                                                (vla-put-textstring a "")
                                                ;; Set the ActiveX textstring property of the
                                                ;; Attribute Reference VLA-Object to an empty
                                                ;; string (a blank value).

                                                a ;; Return the Attribute Reference VLA-Object
                                                
                                            ) ;; end PROGN
                                            
                                        ) ;; end LIST
                                        
                                    ) ;; end LAMBDA
                                   
                                    (vl-remove-if-not
                                        ;; Remove those items from the supplied list for which
                                        ;; the following predicate function returns nil
                                        
                                       '(lambda ( a )
                                            ;; Define an anonymous function accepting a single
                                            ;; argument (an Attribute Reference VLA-Object)
                                            
                                            (wcmatch
                                                ;; Test the Attribute Tag name against
                                                ;; the supplied wildcard pattern, remove
                                                ;; the Attribute Reference from the list
                                                ;; if it fails the test.

                                                ;; Retrieve the ActiveX tagstring property
                                                ;; of the Attribute Reference and convert it
                                                ;; to uppercase.
                                                (strcase (vla-get-tagstring a))

                                                ;; The wildcard pattern for the test.
                                                "REV#,R#DESC,R#BY,R#CHK,R#DATE"
                                                
                                            ) ;; end WCMATCH
                                            
                                        ) ;; end LAMBDA
                                       
                                        (vlax-invoke
                                            ;; Invoke the given ActiveX method on the supplied
                                            ;; Block Reference VLA-Object

                                            (vlax-ename->vla-object
                                                ;; Convert the entity to a VLA-Object

                                                ;; ************************************
                                                ;; *** START HERE AND READ OUTWARDS ***
                                                ;; ************************************

                                                ;; Retrieve the block reference entity at the last
                                                ;; index in the selection set (sslength - 1)
                                                ;; and decrement the index variable for the next
                                                ;; iteration of the repeat loop.
                                                (ssname s (setq i (1- i)))

                                            ) ;; end VLAX-ENAME->VLA-OBJECT

                                            'getattributes
                                            ;; Invoke the 'getattributes' method
                                            ;; to return a list of Attribute Reference VLA-Objects
                                            
                                        ) ;; end VLAX-INVOKE
                                       
                                    ) ;; end VL-REMOVE-IF-NOT
                                   
                                ) ;; end MAPCAR

                                ;; Define an anonymous function accepting two arguments (two lists)
                                ;; to act as the predicate function argument for the
                                ;; LM:groupbyfunction function.
                                
                                (lambda ( a b ) (= (car a) (car b)))
                                
                                ;; Items are considered equal if the 1st item in the list is equal
                                ;; i.e. if the numerical content of each attribute tag is equal.
                                
                            ) ;; end LM:GROUPBYFUNCTION
                           
                        ) ;; end MAPCAR
                        
                       '(lambda ( a b ) (> (caar a) (caar b)))
                        ;; Define an anonymous sorting function for the VL-SORT function
                        ;; accepting two arguments (lists of grouped attribute data)
                        ;;
                        ;; The function will sort the grouped items in descending order
                        ;; by the value 1st item of the 1st list in each group.
                        
                    ) ;; end VL-SORT
                    
                ) ;; end SETQ
               
                (vl-remove-if
                    ;; Iterate over the supplied list and remove items
                    ;; for which the following predicate function returns a non-nil value
                    ;;
                    ;; This will remove rows of attribute data in the list of groups
                    ;; for which all attribute values are blank.

                   '(lambda ( x )
                        ;; Define an anonymous function accepting a single argument
                        ;; (the list of grouped attribute data lists)

                        (vl-every
                            ;; Evaluate the following function on every item in the supplied list
                            ;; and cease evaluate for the first item for which the predicate
                            ;; function returns nil.
                            ;;
                            ;; This function will return T if all attribute values in the
                            ;; group are blank.

                           '(lambda ( y )
                                ;; Define an anonymous function accepting a single
                                ;; argument (a list of attribute data within a group)

                                (= "" (caddr y))
                                ;; Returns T if the 3rd item in the list is blank
                                ;; i.e. if the current attribute value is blank
                                 
                            ) ;; end LAMBDA

                            x ;; The list of grouped attribute data lists

                        ) ;; end VL-EVERY
                        
                    ) ;; end LAMBDA

                    a ;; The sorted list of grouped attribute data lists
                   
                ) ;; end VL-REMOVE-IF
               
            ) ;; end MAPCAR
            
        ) ;; end REPEAT

        ;; The 'else' argument for the IF function would go here
        ;; but we don't need one, as the user already knows if nothing
        ;; has been selected (hence when SSGET returns nil).
        
    ) ;; end IF
    
    (princ) ;; Suppress the return of the last evaluated expression
    
) ;; end DEFUN

;; Group By Function  -  Lee Mac
;; Groups items considered equal by a given predicate function

(defun LM:groupbyfunction ( lst fun / tmp1 tmp2 x1 )
    (if (setq x1 (car lst))
        (progn
            (foreach x2 (cdr lst)
                (if (fun x1 x2)
                    (setq tmp1 (cons x2 tmp1))
                    (setq tmp2 (cons x2 tmp2))
                )
            )
            (cons (cons x1 (reverse tmp1)) (LM:groupbyfunction (reverse tmp2) fun))
        )
    )
)

(vl-load-com) ;; Load the Visual LISP ActiveX extensions

(princ) ;; Suppress the return of the last evaluated expression on loading

 

I've tried my best to explain what is going on at each stage of the program, and I hope the above is clear and comprehensible.

 

Lee

Message 11 of 16
bhull1985
in reply to: Lee_Mac

Hot dang Lee!!

Thanks for the material!

I'll spend some time with this'n, very *very* much appreciated....I'm sure I'll learn a thing or two from the thouroughness of your post. Thanks yet again 🙂

 

Two thumbs up and 3 kudos 😉

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 12 of 16
Lee_Mac
in reply to: bhull1985

You're most welcome Brandon -

I hope the post helps you & others in the CAD community Smiley Happy

Message 13 of 16
pbejse
in reply to: bhull1985


@bhull1985 wrote:

Thanks to pBe over at cadtutor, this has been solved!

Fancy, complex looking code that works great! 

Here take a peek:

 

(VL-LOAD-COM)

(defun c:rvb (/ _AttFunc ss i e values status void num);; Repair Revision Box....

Bravo and thanks to pBe for this brilliant routine. Now, to try to understand it ! 😄


I updated the code @ [post # 11 @ CTT] to work with mutliple blank space similar to LM's post. also i attached a lisp file with comments like you requested. 

 

HTH

Message 14 of 16
bhull1985
in reply to: pbejse

Oh excellent!

I got fairly deep into Lee's code via his comments yesterday, having something comparitive will help even more. Much appreciated you two.

There were some portions of code in Lee's that I weren't quite able to understand... ascii character ranges, and the sorting functions. But I was able to get through most of the lambda functions and hence will do some googling on those two terms to see if there's any information that way. But first things first, let me give what you've commented a good read.

 

Thanks!!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 15 of 16
Lee_Mac
in reply to: bhull1985


@bhull1985 wrote:

 

I got fairly deep into Lee's code via his comments yesterday, having something comparitive will help even more. Much appreciated you two.


 

You're entirely welcome Brandon! Smiley Happy

 


@bhull1985 wrote:

 

There were some portions of code in Lee's that I weren't quite able to understand... ascii character ranges, and the sorting functions. But I was able to get through most of the lambda functions and hence will do some googling on those two terms to see if there's any information that way. But first things first, let me give what you've commented a good read.


 

With regards to the ASCII character range, this ASCII character reference may shed some light as to what that section of the code is achieving - of course, if you are still unsure, please ask.

 

I'm glad that you were able to grasp the many anonymous lambda functions used throughout the code - of course, to make things a little less intimidating for those not familiar with lambda functions, you can always remember that any lambda function could be equivalently written as a separate named function (using defun), and then passed as an argument to mapcar.

 

However, since each anonymous lambda function is only used once, it does not warrant the overhead of defining a separate named function, and furthermore, the code is far more readable when the anonymous lambda function is in-line with the mapcar expression.

 

Lee

Message 16 of 16
bhull1985
in reply to: Lee_Mac

Yes indeed, these principles are not lost on me.

It's even moreso apparent when the lambdas are used in conjunction with subroutines such as your group by function and pbE's (_AttFunc) and (#tonum) functions. It is clear to me why some receive their own (defun call and others are wrapped in (lambda) instead. As you just stated, this is dependant on how many times the particular portion of code will be used throughout the entire routine's processes. With pbE's subfunctions that I named above, they are used throughtout the code in various places, and his comments on the (_AttFunc) exemplify this:

 

;;; This function use for both read and edit attribute values ;;;
(defun _AttFunc  (en lst / vals v)
(mapcar (function (lambda (at)
 (setq vals (list (vla-get-tagstring at)(vla-get-textstring at)))
           (if (and lst (setq v (assoc (car vals) lst)))
                   (vla-put-textstring at (cadr v))) vals))
                      (vlax-invoke (if (eq (type en) 'VLA-OBJECT)
                                  en (vlax-ename->vla-object en)) 'Getattributes)
   )
  )

;;;;;;;

 

Simple, yet concise and relevant. That is the fact to know about (_attFunc)! Rather than creating two or three lambda functions to satisfy this need within the code, and also rather than writing a subr to read attribute values and then another to write attribute values....I really like this example because it screams effeciency to me, placing a function to complete dual purposes *when it is possible*.

I completely understand that lambdas are very often necessary for niche situations or a situation which a return value obtained only once within the program should be returned to another portion of the program or to become output, and that in conjunction with subroutines that are flexible in nature powerful tasks can be completed with minimal code.

 

As I'm going through pBe's currently, but I believe the process would have been similar within Lee's, that it appears as if there is a portion that checks the value of each tag one at a time, if it is blank or empty, then the program writes it into a variable to construct another list of (tag.value) associations. I'm getting through the specifics of this at the moment, to see how exactly that works (i may be slightly off, it takes me longer to process each line than the interpreter that's for sure!! hah...) but i'm getting through it!

Just wanted to show that i'm giving these codes their due diligiance in spending time dissecting each line to further my understanding beyond cursory glances...way beyond that. It was time to study up on attribute functions but this blows google searches out of the water 😉 hard to express how grateful I am..so I just say thanks alot 😄

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost