BIGAL Posted April 10, 2017 Posted April 10, 2017 (edited) A recent post had me thinking you have a table with multiple columns and want to insert different block attributes into the table, but the blocks are all different but have common column headings like part number, length, width. The attribute positions are all over the place, so pick a block and pick the column you want the attribute value to appear in. This is very rough but I am looking for some sample dwgs or have a play and let me know how you found it, I have included a make table for testing just change the number of columns to more than you largest number of attributes. Please note there is a limit to the number of attributes that can be displayed. Just use a number like 99 for a non entry into a column. Next version could be to select multiple blocks of same name rather than 1 at a time. ; pick a block and enter attributes into table ; by Alan H April 2017 (defun c:blk-tab ( / tabrows lst lst2 lstatt x ) (if (/= tblobj nil) (princ) (setq tblobj (vlax-ename->vla-object (car (entsel "Pick table")))) ) (setq tabrows (vla-get-rows tblobj)) ; number of rows existing ; if has attribs check here (while (setq obj (vlax-ename->vla-object (car (entsel "Pick Block")))) (setq lst '()) (setq lstatt '()) (foreach att (vlax-invoke obj 'getattributes) (setq lstatt (cons (vla-get-textstring att) lstatt)) (setq lst (cons (strcat (vla-get-tagstring att) " " (vla-get-textstring att)) lst)) (setq lst (cons 4 lst)) (setq lst (cons 2 lst)) ) (setq lst (reverse lst)) (setq lstatt (reverse lstatt)) (if (not AH:getkeys)(load "getvals2")) ;(AH:getkeys (list "Line 1" 5 4 "line 2" 4 2 "line 3" 8 7)) (princ "\nGetvals2 loaded") (AH:getkeys lst) ; get key values as a list (setq num (/ (length lst) 3)) (setq x 1) (setq lst2 '()) (repeat num (setq lst2 (cons (atoi (eval (read (strcat "Key" (rtos x 2))))) lst2)) (setq x (+ x 1)) ) (setq lst2 (reverse lst2)) ; this is the order for table matches nth lstatt ; now do table insertion this is column values for next entry ; add a row then insert values. (vla-InsertRows tblobj (+ tabrows 1) (vla-GetRowHeight tblobj (- tabrows 1)) 1) (repeat (setq x (length lstatt)) (setq x (- x 1)) (vla-settext tblobj tabrows (- (nth x lst2) 1) (nth x lstatt)) ;1st column is zero ) (setq tabrows (+ tabrows 1)) ) ;while (setq ans (getstring "To reset table just press <Cr> any other key to continue ")) (if (= ans nil)(setq tblobj nil)) ) ;defun ; example of creating a table ; By Alan H (defun c:sct (/ colwidth numcolumns numrows objtable rowheight sp vgad vgao ) (vl-load-com) (setq sp (vlax-3d-point '(0 0 0))) (setq doc (vla-get-activedocument (vlax-get-acad-object) )) (setq vgms (vla-get-modelspace doc)) (setq numrows 5) (setq numcolumns 5) (setq rowheight 0.5) (setq colwidth 30) (setq objtable (vla-addtable vgms sp numrows numcolumns rowheight colwidth)) ; RetVal = object.AddTable(InsertionPoint, NumRows, NumColumns, RowHeight, ColWidth) (vla-settext objtable 0 0 "TABLE title") (vla-settext objtable 1 0 "A") (vla-settext objtable 1 1 "B") (vla-settext objtable 1 2 "C") (vla-settext objtable 1 3 "D") (vla-settext objtable 1 4 "E") (vla-settext objtable 2 0 "1") (vla-settext objtable 3 0 "2") (vla-settext objtable 4 0 "3") (vla-setcolumnwidth objtable 0 15) ; 0 is first column (vla-setcolumnwidth objtable 1 30) (vla-setcolumnwidth objtable 2 60) (command "_zoom" "e") (princ) ) (C:sct) ; multi line dcl ; with help from the guys at Cadtutor ; sample code a 3 line example ; (if (not AH:getkeys)(load "getvals2")) ;(AH:getkeys (list "Line 1" 5 4 "line 2" 2 4 "line 3" 8 7)) (princ "Getvals2 loaded") (defun AH:getkeys (INFO / fo fname newlst num x y klist) ; you can hard code a directory if you like for dcl file (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) ;(setq fo (open (setq fname "c:\\acadtemp\\getkeys.dcl") "w")) (write-line "ddgetkey : dialog {" fo) (write-line " : column {" fo) (setq num (/ (length info) 3)) (setq x 1) (repeat num (setq klist (cons (strcat "key" (rtos x 2 0)) klist)) (setq x (+ 1 x)) ) (setq x 1) (setq y 1) (repeat num (write-line ": edit_box {" fo) (write-line (strcat " key = " (chr 34) (strcat "key" (rtos y 2 0)) (chr 34) ";") fo) (write-line (strcat " label = " (chr 34) (nth (- x 1) info) (chr 34) ";" ) fo) (write-line (strcat " edit_width = " (rtos (nth x info) 2 0) ";" ) fo) (write-line (strcat " edit_limit = " (rtos (nth (+ x 1) info) 2 0) ";" ) fo) (write-line " is_enabled = true;" fo) (write-line " }" fo) (write-line "spacer_1 ;" fo) (setq x (+ x 3)) (setq y (+ y 1)) ) (write-line " }" fo) (write-line "ok_only;}" fo) (close fo) (setq x 1) (setq outlst '()) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "ddgetkey" dcl_id)) (exit)) (foreach k klist (action_tile k (strcat "(setq " k " (get_tile \"" k "\"))")) ) (action_tile "accept" "(done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") (setq action (start_dialog)) (unload_dialog dcl_id) ) ; defun Edited April 13, 2017 by BIGAL changed to default directory Quote
rlx Posted April 11, 2017 Posted April 11, 2017 Hi Bigal, First had to look where your table went but found it on the layout tab and then routine stopped at (load "getvals2") because of (if (not AH:getkeys) etc... gr. Rlx Quote
Grrr Posted April 11, 2017 Posted April 11, 2017 Hi BIGAL, I'd suggest to use some subfunction that converts an assoc list into acad_table, then by using list manipulation and testing the format of the output list you can pass it to that subfunction. Use the pretty-print option in vlide's console to get a readable list, so you can spot eventual problems. Quote
BIGAL Posted April 12, 2017 Author Posted April 12, 2017 Sorry guys added the getvals2.lsp and changed it to "modelspace" thats the problem with loading a lisp that you keep in a library directory so when testing it works.. Quote
rlx Posted April 12, 2017 Posted April 12, 2017 Sorry guys added the getvals2.lsp and changed it to "modelspace" thats the problem with loading a lisp that you keep in a library directory so when testing it works.. Happens to me all the time... well , ok, sometimes... gr.Rlx Quote
rlx Posted April 12, 2017 Posted April 12, 2017 Ok , first test... You use (setq fname "c:\\acadtemp\\getkeys.dcl") , not everybody will have this folder. When selecting a block , what values are expected? Apparently a (row) number , not a (column) letter? After I entered some numbers, it again asks to select a block. When I give a return (enter) program stops... That's it for now... but I know , first use / new user (with a 'blank' system) can be difficult. gr. Rlx Quote
BIGAL Posted April 13, 2017 Author Posted April 13, 2017 RLX thanks will change to default path the code as posted has two options a user directory or the users temp directory just rem out the line not required line 9 & 10. Quote
rlx Posted April 13, 2017 Posted April 13, 2017 RLX thanks will change to default path the code as posted has two options a user directory or the users temp directory just rem out the line not required line 9 & 10. Hi Al, Got it working more or less. First run doesn't do anything besides creating a table. Program also keeps asking to pick a block but stops when I give an enter when I'm done selecting. When I then run your app the second time it creates a new table and then populates the table. Also maybe place (c:sct) at the end of your file? Not sure if it load the part beyond this line if it executes this command upon loading but I think it does since I get the dialog. Anywayz , on the second run your program adds a new line next to the table and when I manualy adjust the table it correctly shows all the attribute values in the column numers I entered in the dialog. Maybe built in a check for maximum number of colums because if I select a titleblock with many attributes it erros out with the message dialog to big, Al ;-) Not sure if I can put your app to use in my line of work (electrical) but maybe I can think of something. gr. Rlx Quote
BIGAL Posted April 14, 2017 Author Posted April 14, 2017 Rlx Not sure why not working 1st pass, have a bit of time over Easter. It was put together as method to show how it could be done, so its a little rough at moment. You are right how many columns to start with is really user choice as it would be based on the desired headings in the table. It only selects one at a time at moment and it makes sense pick a block and ask 1 or all. This was probably the next version step. The only reason for a create table example was to make it a bit easier for testing. In real life this step should not exists or could like you suggest pick a block and match the number of attributes to columns. The other known problem is that there is a limit on the number of lines that can be displayed in a dcl so would need a step 2 show 2nd page etc. I managed 14 lines. It needs a real world dwg that has multiple blocks but need to populate a table but without a rule for every block that sets the column, taking into account blank cells. Need something like block1 4 atts, block2 6 atts, block3 2 atts. Quote
rlx Posted April 14, 2017 Posted April 14, 2017 Rlx Not sure why not working 1st pass, have a bit of time over Easter. It was put together as method to show how it could be done, so its a little rough at moment. You are right how many columns to start with is really user choice as it would be based on the desired headings in the table. It only selects one at a time at moment and it makes sense pick a block and ask 1 or all. This was probably the next version step. The only reason for a create table example was to make it a bit easier for testing. In real life this step should not exists or could like you suggest pick a block and match the number of attributes to columns. The other known problem is that there is a limit on the number of lines that can be displayed in a dcl so would need a step 2 show 2nd page etc. I managed 14 lines. It needs a real world dwg that has multiple blocks but need to populate a table but without a rule for every block that sets the column, taking into account blank cells. Need something like block1 4 atts, block2 6 atts, block3 2 atts. Hi Al, Only thing I can think off would be a one-line diagram or a lighting lay-out where you would count all the lights and have a table with all types of lighting armatures , their power consumption and on which group (fuse / switch) the are connected. Included I have a one-line diagram of a mcc which have different types of feeders , some feed another electric panel or fuse box , some feed a pump or a motor. Then you could sum them up in a table accoording to power consumption or something like that , although it would be a little bit the world upside down because I have generated this drawing from a table (excell) to start with. Your app would probably be more usefull in making a list from all different parts in a mechanical drawing? But still, it is nice to play with and maybe later I or somebody else can come up with a better example. gr. Rlx One-Line-Mcc.dwg Quote
BIGAL Posted April 14, 2017 Author Posted April 14, 2017 Thanks for that it really is just an idea but with a solution. The table in your drawing really matches the idea with some cells blank. Quote
rlx Posted April 14, 2017 Posted April 14, 2017 Thanks for that it really is just an idea but with a solution. The table in your drawing really matches the idea with some cells blank. one thought just popped into my mind : 'sometimes it's not about the destination but about the journey itself' gr. Rlx Quote
Recommended Posts
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.