tricon77 Posted June 10 Posted June 10 I need help in debugging the following code: (defun c:spool_labels ( / prefix cnt pt ol) (setq prefix (getstring t "\nENTER PREFIX: ") cnt (getint "\nENTER INTEGER TO START: ") ;; value to start the counter at ol (getvar 'clayer) oa (getvar 'attdia) ) ;; Turn dialog off for the attributes (setvar 'attdia 0) ;; Create layer for the blocks to be inserted on (command "-layer" "make" "Blocks-Spool Label" "color" "magenta" "" "") (while (setq pt (getpoint "\nPICK INSERTION POINT: ")) ;; get insertion point for block (command ".-insert" ;; command to insert a dynamic block "_MP Spool Label" ;; name of block to insert pt ;; insertion point for block 1 ;; scale value for the block 0 ;; rotation value for the block ;; concatenate the prefix to the counter for the name (strcase (strcat prefix (itoa cnt))) ) ;; increment the counter (setq cnt (1+ cnt)) ) ;; restore change system values (setvar 'clayer ol) (setvar 'attdia ol) (princ) ) The output of the code: Command: SPOOL_LABELS ENTER PREFIX: 4" CND # ENTER INTEGER TO START: 1 PICK INSERTION POINT: Unknown command "\". Press F1 for help. Block gets inserted but the attribute does not get filled in. Any help with this will be greatly appreciated. Quote
rlx Posted June 10 Posted June 10 welcome to the club... It would help to have your block attached but wondering : systemvariable "attreq" , is this set to 1? and when inserting your block does it ask for x factor only or also y scale because in that case you need an extra 1 in your command Quote
mhupp Posted June 10 Posted June 10 I think you haven't exited/finished the insert command and go straight into calling another point. probably only need a "" at the end to simulate enter key. ;Insert one at a time into command line to see where it hangs (command "_.insert" "MP Spool Label" "0,0 " 1 0 (strcase (strcat "prefix-" (itoa 1)))) (command "_.insert" "MP Spool Label" "_non" "0,0 " 1 0 (strcase (strcat "prefix-" (itoa 1))) "") ;always us "_non" when calling points with command things can snap to close entitys depending on zoom. Quote
BIGAL Posted June 10 Posted June 10 Try this should it be 1 1 0 in code above ? (command "_.insert" "MP Spool Label" "S" 1 "0,0 " 0 (strcase (strcat "prefix-" (itoa 1)))) Also look at Attreq will determine whether an attribute is allowed for or not. Just a comment if you want to know last number used can get all the MP.... blocks and look at the attribute value and save highest put that into a getint if press enter. Uisng ssget can find any MP...... blocks if its nil set cnt to 1. Quote
tricon77 Posted June 11 Author Posted June 11 I did manage to get this working. I am not sure if attreq was set properly but it is now. There is a difference in prompts between dynamic and non dynamic blocks. This was the part that was messing me up. Thanks everyone for helping out. BIGAL for ssget idea (this will be implemented in the next version) mhupp for showing me the typos. (I always forget to quote or not quote numbers) rlx for point out attreq variable (did not know about this variable before) working code (defun c:spool_labels ( / prefix cnt oldclayer oldattdia oldattreq pt) (setq prefix (getstring t "\nENTER PREFIX: ") cnt (getint "\nENTER INTEGER TO START: ") ;; value to start the counter at oldclayer (getvar 'clayer) oldattdia (getvar 'attdia) oldattreq (getvar 'attreq) ) ;; Turn dialog off for the attributes (setvar 'attdia 0) (setvar 'attreq 1) ;; Create layer for the blocks to be inserted on (command "-layer" "make" "Blocks-Spool Label" "color" "magenta" "" "") (while (setq pt (getpoint "\nPICK INSERTION POINT: ")) ;; get insertion point for block (command ".-insert" ;; command to insert a dynamic block "_MP Spool Label" ;; name of block to insert "_non" pt ;; insertion point for block "1" ;; x scale value for the block "0" ;; rotation value for the block ;; concatenate the prefix to the counter for the name (strcase (strcat prefix (itoa cnt))) ) ;; increment the counter (setq cnt (1+ cnt)) ) ;; restore change system values (setvar 'clayer oldclayer) (setvar 'attdia oldattdia) (setvar 'attreq oldattreq) (princ) ) attaching dynamic block _MP Spool Label.dwg 1 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.