+ Reply to Thread
Results 1 to 4 of 4

Thread: Copy Blocks

  1. #1
    ImaJayhawk
    Guest

    Default Copy Blocks

    Registered forum members do not see this ad.

    I'm trying to write a simple routine that copies all blocks of a entered name or selected. I'm getting an Invalid Selection error when I enter in the name, and when I select I'm getting a never ending loop. Thanks.

    (defun C:bs ( / blocker continue selecty selecter selecterset)
    (setvar "cmdecho" 0)
    (setq continue T)
    (if (= (strcase (getstring "\nDo you want to enter block name? y/<n>")) "Y")
    (progn
    (setq blocker (getstring "\nEnter Block Name: "))

    (While continue
    (progn
    (setq selecty (ssget "X" (list (cons 0 "Insert") (cons 2 blocker))))
    (command "_copybase" pause selecty)
    )
    )
    )
    (While continue
    (if (setq enty (car (entsel "\nSelect Block: ")))
    (progn
    (setq e (entget enty))
    (setq selecter (cdr (assoc 2 e)))
    (setq selecterset (ssget "X" (list (cons 0 "Insert") (cons 2 selecter))))
    (command "_copybase" pause selecterset)
    (setq continue F)
    ) (progn (princ "Please select a block") (setq continue T))

    )))
    (Setvar "cmdecho" 1)
    (princ)
    )

  2. #2
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,540

    Default

    ImaJayhawk
    Your error:
    ....
    (setq continue T)
    ...
    (while continue
    ...
    (setq continue F)
    )
    This is an endless loop. The opposite of TRUE (T) is NIL. F is not NIL, so the test (while continue...) will return T even if continue is set to F.
    Here is my attempt to solve your problem. But (again) I think that is not safe to accept the block name to be typed by the user. Not without a verification!
    Code:
    ; Blocks to Clippboard
    ; copy all occurences of a block to the clipboard
    ;  mfuccaro@hotmail.com
    ;  January 2004
    &#40;defun c&#58;b2c&#40; / answer name blocks&#41;
      &#40;setvar "cmdecho" 0&#41;
      &#40;initget "N"&#41;
      &#40;setq answer &#40;entsel "\nselect block\\enter &#91;N&#93;ame "&#41;&#41;
      &#40;setq name &#40;if &#40;listp answer&#41;
    	       &#40;cdr &#40;assoc 2 &#40;entget &#40;car answer&#41;&#41;&#41;&#41;
    	       &#40;getstring "\nenter block name "&#41;
    	       &#41;
    	blocks &#40;ssget "X" &#40;list &#40;cons 0 "insert"&#41; &#40;cons 2 name&#41;&#41;&#41;&#41;
      &#40;princ "\nbase point "&#41;
      &#40;command "_copybase" pause blocks ""&#41;
      &#40;princ "\nOK"&#41;
      &#40;princ&#41;
      &#41;
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  3. #3
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    (ssget) accepts wildcards as well

    So maybe:

    (while (or (not bn)
    (not (or (snvalid bn)
    (wcmatch bn "*[#@`,.*?~]*"))))
    (setq bn (getstring "\nBlock Name <Pattern>: ")))

    ;And then

    (and
    (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bn))))
    (command ........)
    )


    or:

    (setq i (sslength ss))
    (while (not (minusp (setq i (1- i))))
    (setq en (ssname ss i)
    ed (entget en))))

    For picks:

    (while (not ss)
    (setq ss (ssget (list (cons 0 "INSERT"))))
    (command .....)
    )

  4. #4
    ImaJayhawk
    Guest

    Default

    Registered forum members do not see this ad.

    Thanks for the help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts