Jump to content

Recommended Posts

Posted

I wrote this as a quick fix to an issue...

It selects all the blocks on the current tab and moves them to an existing layer (MyLayer)

It works fine for me..

(defun c:tbv ()
(setq xxx (ssget "X" (list '(0 . "INSERT") (cons 410 (getvar "ctab"))))) ;;select all blocks in current tab
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

How can I modify this to have it only apply to SPECIFIC blocks?

 

ie: block names =  Door, Window, Sink

 

I saw some posts with something like this but I could not make it work

(setq xxx (ssget "X" (list '(0 . "INSERT") (2 . "Door,Window,Sink") (cons 410 (getvar "ctab")))))

 

Please advise..

Posted

That should work of course, but it did not work for you due to the blocks themselves are dynamic and not regular ones - so in this case you need to have more codes to iterate through each selected block along with modifying the filter to get dynamic blocks as well.

Posted

For dynamic blocks you need to test for their effective name. BircsCAD doesn't "have" dynamic blocks so i couldn't test this lisp.

 

(defun c:TBV (/ SS xxx blk ss)
  (setq SS (ssadd))
  (if (setq xxx (ssget "X" (list '(0 . "INSERT") (cons 410 (getvar "ctab")))))
    (foreach blk (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex xxx))))
      ;Test if dynamic block then checks name agains list
      (if (and (= :vlax-true (vla-get-IsDynamicBlock blk)) (member (vla-get-Effectivename blk) '("Door" "Window" "Sink"))) ;update list to select other dynamic blocks
        (ssadd (vlax-vla-object->ename blk) SS)
      )
    )
  )
  (if (/= 0 (sslength ss)) 
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex xxx)))
      (entmod (subst (cons 8 "MyLayer") (assoc 8 (entget ent)) (entget ent)))
    )
    (prompt "\nNo Dynamic Block found")
  )
  (princ)
)

 

 

Posted (edited)

These are not dynamic blocks.

(they are just examples that I made...)

 

image.thumb.png.cd2b574c0d8617485e2e20d0c9b22703.png

 

 List in AutoLISP format *((-1 . <Entity name: 1d009d8d4b0>) (0 . INSERT) (330 . <Entity name: 1cf8af28ad0>) 
(5 . 2BB) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . 0) (100 . AcDbBlockReference) (2 . Door) 
(10 3.32774 2.17718 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
Variable name is ENT

* List in AutoLISP format *((-1 . <Entity name: 1d009d8d1e0>) (0 . INSERT) (330 . <Entity name: 1cf8af28a80>) 
(5 . 28E) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . Window) 
(10 5.26034 2.46249 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
Variable name is ENT

* List in AutoLISP format *((-1 . <Entity name: 1d009d8d1f0>) (0 . INSERT) (330 . <Entity name: 1cf8af28a80>) 
(5 . 28F) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . Sink) 
(10 6.81052 2.36626 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
Variable name is ENT

 

This is not what I want but it does work

(defun c:t123 () ;;**WORKS
(setq xxx (ssget "X" (list '(0 . "INSERT") (cons 410 (getvar "ctab"))))) ;;select all blocks in current tab
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

image.thumb.png.3a12b303f133ac6847f496c1089496a4.png

 

I loaded this and it returns "Unknown Command"

(defun c:m1234 ()
(setq xxx (ssget "X" (list '(0 . "INSERT") (2 . "Door,Window,Sink") (cons 410 (getvar "ctab")))))
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

image.thumb.png.c93c42848bae219c95b9100a06167fee.png

 

I tried this and it also returns "Unknown Command"

(defun c:m4321 ()
(setq xxx (ssget "X" (list '(0 . "INSERT") '(2 . "Door,Window,Sink") (66 .1) (cons 410 (getvar "ctab")))))
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

image.thumb.png.4b31c126b1ca8f6d4e759910bb953099.png

 

Even this does not work

 

(setq xxx (ssget "X" (list '(0 . "INSERT") '(2 . "Door") (66 .1) (cons 410 (getvar "ctab")))))

 

This is part is a larger routine, I just pulled this part out since it's not working..

Autocad 2024 if it matters

 

 

 

image.png

Edited by ILoveMadoka
Posted (edited)

I got this partially working using this method..

BUT!

It selects all blocks regardless of layer.

 

(defun c:m1234 ()
(setq xxx (ssget "X" (list '(0 . "INSERT") (cons 2 "Door,Window,Sink"))))
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

What I need to add to this is the filter to select ONLY only blocks on layer 0

 

This attempt still selected ALL blocks regardless of layer

(defun c:m1234 ()
(setq xxx (ssget "X" (list '(0 . "INSERT") (cons 2 "Door,Window,Sink") (cons 410 (getvar "ctab")))))
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

Sigh...

 

HELP!!

 

Edited by ILoveMadoka
Posted (edited)

I guess I'm just talking to myself here but in case it helps someone in the future here is how I got it working..

 

Selects blocks named: Door, Window, Sink

Located on Layer 0

Current tab/layout only

Changes them to another layer.

 

(defun c:m4321 ()
(setq xxx (ssget "X" (list '(0 . "INSERT") (cons 2 "Door,Window,Sink") (cons 8 "0") (cons 410 (getvar "ctab")) )))
(command "_change" xxx "" "p" "la" "MyLayer"  "")
(princ))

 

Edited by ILoveMadoka
  • Like 1
Posted

does this expression <(cons 2 "Door,Window,Sink")>  really work?

Posted

It does work but there is something wonky about it.
I just did 3 tests, It didn't work one time and worked the other two times.

No matter how many times I try these they do not work..

 

(setq xxx (ssget "X" (list '(0 . "INSERT") (2 . "001",002,003") (cons 410 (getvar "ctab")))))

(setq xxx (ssget "X" (list '(0 . "INSERT") (2 . "001" "002" "003") (cons 410 (getvar "ctab")))))

(setq xxx (ssget "X" (list '(0 . "INSERT") (2 . "001","002","003") (cons 410 (getvar "ctab")))))

 

**** So what is the correct way to select multiple blocks by name?

I've got something that works for me but if there is a more "correct" way..

I definitely would love to know..

 

I just tested it again two more times

first time I manually set xxx to nil first to be sure

and creating a new drawing from scratch the second time..
 

(setq xxx (ssget "X" (list '(0 . "INSERT")  (cons 2 "001,002,003")   (cons 8 "0") (cons 410 (getvar "ctab")) )))

 

It works (for me)

Posted

I wish one of these guys who know what they are doing would step in 

(again these are not dynamic blocks)

 

It would be very appreciated...

Posted

These work as well (for me anyway)

 


(setq SSX (ssget "_X" '((0 . "INSERT") (2 . "`001,002,003"))))


(setq xxx (ssget "X" (list '(0 . "INSERT")  (cons 2 "`001,002,003")   (cons 8 "0") (cons 410 (getvar "ctab")) )))

 

 

Posted
5 hours ago, ILoveMadoka said:

It does work but there is something wonky about it.

 

I think its solidworks being wonky since they use VBA macro's mostly. and until recently nothing before 2019 didn't have lisp support.  Also by default doesn't Solidworks not use layers?

don't get me wrong there are commands that I can't use in BricsCAD that you can in AutoCAD. or require the same inputs but in a different order.

 

the "," means "or" and you have to feed it multiple strings inside one quote. their are other wild cards you could use like ~

 

for instance

(setq xxx (ssget "X" (list '(0 . "INSERT")  '(2  . "001,002,003")  '(8 . "~MyLayer") (cons 410 (getvar 'ctab)))))

 

This will select any block named 001, 002 , or 003 that isn't on Mylayer on the current tab.

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