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

Lisp Question

8 REPLIES 8
Reply
Message 1 of 9
safcadd08
507 Views, 8 Replies

Lisp Question

Hello,

My question is, I have 10 blocks on the screen and I would like to select any 3 of the 10 blocks and be able to erase all 10 blocks and insert the 3 that where selected. Does anyone know what would be the best way to do this?

 

Thanks,

Steve

8 REPLIES 8
Message 2 of 9
_Tharwat
in reply to: safcadd08

Things like this ... ?

 

(defun c:Test (/ ss s i sn p)
  ;;; Tharwat 28. May. 2012 ;;;
  (if (and (setq ss (ssget "_:L" '((0 . "INSERT"))))
           (> (sslength ss) 2)
      )
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (if (< (length s) 3)
        (setq s (cons (cdr (assoc 2 (entget sn))) s))
      )
      (entdel sn)
    )
  )
  (if (and (eq (length s) 3)
           (setq
             p (getpoint "\n Specify point to insert the three Blocks :")
           )
      )
    (foreach x s
      (entmakex
        (list '(0 . "INSERT")
              (cons 10 p)
              (cons 2 x)
              '(41 . 1.0)
              '(42 . 1.0)
              '(43 . 1.0)
        )
      )
    )
  )
  (princ)
)

 

Message 3 of 9
safcadd08
in reply to: _Tharwat

Hello Mentor, Wouldyou send me an email to safcadd@gmail.com and I will be able to give you the details of what I want to do. Thanks, Steve
Message 4 of 9
pbejse
in reply to: safcadd08


@safcadd08 wrote:
Hello Mentor, Wouldyou send me an email to safcadd@gmail.com and I will be able to give you the details of what I want to do. Thanks, Steve


I suppose other forum members wont be able to suggest/advice/chime-in then  Smiley Very Happy

 

This forum is also about sharing  after all.

Message 5 of 9
_Tharwat
in reply to: pbejse


@pbejse wrote:

I suppose other forum members wont be able to suggest/advice/chime-in then  Smiley Very Happy

 

This forum is also about sharing  after all.



You know that you can , and you are always welcome to your precious and unique ideas pBe Smiley Wink

 

Feel free to give what you have in mind to the OP and me as well . Smiley Happy

 

Regards

Message 6 of 9
pbejse
in reply to: _Tharwat


@_Tharwat wrote:

 

You know that you can , and you are always welcome to your precious and unique ideas pBe Smiley Wink

 

Feel free to give what you have in mind to the OP and me as well . Smiley Happy

 

Regards


I'm just being my silly self Tharwat, we know you got it covered  Smiley Happy

 

Cheers my friend.


 

Message 7 of 9
Kent1Cooper
in reply to: safcadd08


@safcadd08 wrote:

.... I have 10 blocks on the screen and I would like to select any 3 of the 10 blocks and be able to erase all 10 blocks and insert the 3 that where selected. Does anyone know what would be the best way to do this?

....


 

Do you want to re-Insert the selected Blocks in a different place than where they were?  If you want to re-Insert them in the same place, it would be easy to come up with something that doesn't do that, but simply Erases all the rest except for the selected ones.  And if you don't want them in the same place, do you want to Insert all 3 at once, keeping their positional relationship to each other, or do you want to Insert each one in its own new location?

 

And when you say "10 Blocks", are those all the Blocks in the drawing of any name, or 10 insertions of the same Block name?  That would affect what you should use in a selection-set filter in (ssget) to find them all.  You also say "on the screen," which makes me wonder whether you want to work with only those that are currently visible, or with all such Blocks in the drawing, whether visible at the moment or not.

Kent Cooper, AIA
Message 8 of 9
safcadd08
in reply to: safcadd08

Kent,

This might be a better explanation::
1.> I have 10 blocks (1x to 10x) on the screen.
2.> I want to pick any 3 at random, write the block names to a file. For future use.
3.> Be able to read the file and insert the 3 blocks at 3 user specified points.

 

Thanks,

Steve

Message 9 of 9
pbejse
in reply to: safcadd08


@safcadd08 wrote:

Kent,

This might be a better explanation::
1.> I have 10 blocks (1x to 10x) on the screen.
2.> I want to pick any 3 at random, write the block names to a file. For future use.
3.> Be able to read the file and insert the 3 blocks at 3 user specified points.

 

Thanks,

Steve


I personally would prefer a list of blocks hardcoded on a routine.

Example

 

(defun c:Ib  ( / blks blklst cnt blknum)

(vl-load-com)
      (setq blks   '("Block1" "Block2" "Block3" "Block4" "Block5"
                     "Block6" "Block7" "Block8" "Block9" "Block10")
            blklst nil)
      (textscr)
      (while
            (or (initget 6)
                (and (foreach
                            nme  blks
                           (print (setq cnt (1+ cnt)))
                           (princ (strcat "\t" nme)))
                     (setq cnt    0
                           blknum (getint
                                        (strcat
                                              "\nEnter Block index number "
                                              (if blklst
                                                    (strcat
                                                          "<Enter when done>: "
                                                          (vl-prin1-to-string blklst)
                                                          ": ")
                                                    ": ")))))
                )
                 (if (<= blknum 5)
                       (setq blklst
                                  (append blklst
                                          (list (nth (1- blknum) blks))))
                       (princ "\nIndex number does not exist")
                       ))
      (graphscr)
      (foreach
             itm
                blklst
            (command "_Insert" itm "_Scale" "1" "_non" pause pause)
            )
      )

 

HTH

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

Post to forums  

Autodesk Design & Make Report

”Boost