Jump to content

Debugging Dynamic Block Insert


tricon77

Recommended Posts

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. 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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