Jump to content

Add ssget to select specific Blocks


Michaels

Recommended Posts

Hello. :)

 

How can I add selection set to these codes to get a specific block(s) ?

 

 (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
   (progn

  (vlax-for blocks (vla-get-blocks (setq M:cad (vla-get-activedocument (vlax-get-acad-object))))
    (if
       (and
           (eq :vlax-false (vla-get-isLayout blocks))
           (eq :vlax-false (vla-get-isXref blocks))
       )
            (vlax-for o blocks
        (if (wcmatch (vla-get-objectname o) "AcDbCircle")
              (vla-put-color o 2))
        )
      ))
 (vla-regen M:cad acActiveViewport)

Many Thanks.

Link to comment
Share on other sites

 
(ssget "_x" '((0 . "INSERT")(2 .  "Blockname,Blockname")));<------ your blockname/s

 

add (66 . 1) if it includes attributes

 

and if by chance you ran into anonymous blocks

 
'((0 . "INSERT")(2 .  "*U*,Blockname,Blockname"));<------ your blockname/s

 

then check for Effectivename before processing the block

 

 ;; Returns list of the Anonymous names taken by a Dynamic Block (if any) - Lee Mac 2011 - www.lee-mac.com
;; Arguments: block - name of Dynamic Block.

(defun AnonymousInstancesof ( block / def rec nme ref lst )
(while (setq def (tblnext "BLOCK" (null def)))
(if (= 1 (logand 1 (cdr (assoc 70 def))))
(progn
(setq rec
(entget
(cdr
(assoc 330
(entget
(tblobjname "BLOCK" (setq nme (cdr (assoc 2 def))))
)
)
)
)
)
(while (setq ref (assoc 331 rec))
(if
(and
(eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref))))
(not (member nme lst))
)
(setq lst (cons nme lst))
)
(setq rec (cdr (member (assoc 331 rec) rec)))
)
)
)
)
(reverse lst)
)

Link to comment
Share on other sites

FYI, the "_:L" portion of your ssget selection is to filter objects on locked layers. I keep noticing other people posting code that includes this filter when it is not needed. Just wanted to make sure you actually understood it instead of using it blindly.

Link to comment
Share on other sites

FYI, the "_:L" portion of your ssget selection is to filter objects on locked layers. I keep noticing other people posting code that includes this filter when it is not needed. Just wanted to make sure you actually understood it instead of using it blindly.

 

Thanks.

 

I do know that it is for filtering Locked layers and I got used it to it because it is important .

Link to comment
Share on other sites

 
(ssget "_x" '((0 . "INSERT")(2 .  "Blockname,Blockname")));<------ your blockname/s

 

add (66 . 1) if it includes attributes

 

and if by chance you ran into anonymous blocks

 
'((0 . "INSERT")(2 .  "*U*,Blockname,Blockname"));<------ your blockname/s

 

then check for Effectivename before processing the block

 

 ;; Returns list of the Anonymous names taken by a Dynamic Block (if any) - Lee Mac 2011 - www.lee-mac.com
;; Arguments: block - name of Dynamic Block.

(defun AnonymousInstancesof ( block / def rec nme ref lst )
(while (setq def (tblnext "BLOCK" (null def)))
(if (= 1 (logand 1 (cdr (assoc 70 def))))
(progn
(setq rec(entget(cdr(assoc 330(entget(tblobjname "BLOCK" (setq nme (cdr (assoc 2 def)))))))))
(while (setq ref (assoc 331 rec))
(if
(and
(eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref))))
(not (member nme lst)))
(setq lst (cons nme lst)))
(setq rec (cdr (member (assoc 331 rec) rec)))))))
(reverse lst)
)

 

Great work pBe. thank you so much.

 

But that's not what I am looking forward .

 

As you for sure know that the second part of my codes is to change the color of circles in Block Definitions , but I want to change the color of circles

in the selected Blocks only by the use of "ssget" to be able to select two to three blocks at the same time .

 

Appreciated a lot.

Link to comment
Share on other sites

Lol what's with the 'M:CAD' (you) or 'TH:CAD' (Tharwat) for your variables? You guys must think the same way... :roll: [or are the same person]

 

Back to the original question -

 

Note that you won't be able to change specific Inserts since you are modifying the block definition - which will be applied to all Inserts for that definition.

 

You will need to add a filtered selection using ssget, perhaps with the DXF Group 2 as pBe correctly states, then, when iterating through the set, check that you haven't already processed the block name by checking against a list of processed block names, and if not, retrieve the block definition and perform your modifications, then when done, add the block name to the list of blocks already processed.

 

Lee

Edited by Lee Mac
Link to comment
Share on other sites

Lee .

 

My poor experience with lisp forced me to copy and paste things like that sometimes .

 

And what is the logic of these Men's codes ?

 

(defun HSN:...... ()

; @ HasanCAD

..........

......

(KDUB:ucs:Move_X))

......

...

(defun LM:grX ( p s c / -s r q )

;; © Lee Mac .....

...........

..........

(and TH:UnDo (vla-EndUndoMark TH:CAD))

.......

Is it one man way or experts' way ?

 

I promise you that I would get my won way when I become at least able to write small routine .:)

 

Michaels

Edited by Michaels
Link to comment
Share on other sites

This makes it easy to determine functions that have been developed by you in support of the main code

 

-Good Habits for Coding in Visual LISP® - Robert Bell -

Link to comment
Share on other sites

This makes it easy to determine functions that have been developed by you in support of the main code

 

-Good Habits for Coding in Visual LISP® - Robert Bell -

 

I did not get the point well ! :?

Link to comment
Share on other sites

In programming in general. its always a good practice to make names of routines as long as necessary that clearly describes everything the routine does (a description of the return value)

as for adding the prefix... i.e (defun LM:WhatMyFunctionIs )

 

These prefixes may help you when posting code on forums or discussion groups

for support. As you get ready to post your code you may notice those toolbox functions due to

their prefix and include those external functions. This makes it easier to get support.

 

now as for this..

 

what's with the 'M:CAD' (you) or 'TH:CAD' (Tharwat) for your variables?

 

Beacuse those prefix are normally associated with routine names and not for variable names.

now variable naming convention is another thing..

 

simply put. its a good practice for programemrs all over the world to follow.

you dont have to do this is what i'm trying to tell you.. but then again,... see previous post

 

 

 

Hope this helps

 

:)

 

Link to comment
Share on other sites

Exactly pBe.

 

But for me as a beginner of Lisp , I am trying to get used to things that most of excellent programmers do .

 

So that's why I have been trying to use some of others' ways of handling things like that .

 

Greatly appreciated pBe.

 

Thank you . :)

Link to comment
Share on other sites

Since you aren't willing to give it a try, or indicate which part of my explanation wasn't clear, here is an example for you to copy/paste into your code whilst still not understanding its inner workings:

 

[color=RED]([/color][color=BLUE]defun[/color] [color=black]c:test[/color] [color=RED]([/color] [color=BLUE]/[/color] acdoc acblk acsel name done [color=RED])[/color] [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]

 [color=#990099];;---------------------------------------------;;[/color]
 [color=#990099];; Example © Lee Mac 2011  -  www.lee-mac.com  ;;[/color]
 [color=#990099];;---------------------------------------------;;[/color]

 [color=RED]([/color][color=BLUE]setq[/color] acdoc [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED]))[/color]
       acblk [color=RED]([/color][color=BLUE]vla-get-Blocks[/color] acdoc[color=RED])[/color]
 [color=RED])[/color]
 
 [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]ssget[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"INSERT"[/color][color=RED])))[/color]
   [color=RED]([/color][color=BLUE]progn[/color]
     [color=RED]([/color][color=BLUE]vlax-for[/color] block [color=RED]([/color][color=BLUE]setq[/color] acsel [color=RED]([/color][color=BLUE]vla-get-ActiveSelectionSet[/color] acdoc[color=RED]))[/color]
       [color=RED]([/color][color=BLUE]if[/color]
         [color=RED]([/color][color=BLUE]not[/color]
           [color=RED]([/color][color=BLUE]member[/color]
             [color=RED]([/color][color=BLUE]setq[/color] name
               [color=RED]([/color][color=BLUE]vlax-get-property[/color] block
                 [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]vlax-property-available-p[/color] block [color=DARKRED]'[/color]effectivename[color=RED])[/color]
                   [color=DARKRED]'[/color]effectivename
                   [color=DARKRED]'[/color]name
                 [color=RED])[/color]
               [color=RED])[/color]
             [color=RED])[/color]
             done
           [color=RED])[/color]
         [color=RED])[/color]
         [color=RED]([/color][color=BLUE]progn[/color]
           [color=RED]([/color][color=BLUE]vlax-for[/color] obj [color=RED]([/color][color=BLUE]vla-item[/color] acblk name[color=RED])[/color]
             [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]eq[/color] [color=#a52a2a]"AcDbCircle"[/color] [color=RED]([/color][color=BLUE]vla-get-Objectname[/color] obj[color=RED]))[/color]
               [color=RED]([/color][color=BLUE]vla-put-color[/color] obj [color=BLUE]acred[/color][color=RED])[/color]
             [color=RED])[/color]
           [color=RED])[/color]
           [color=RED]([/color][color=BLUE]setq[/color] done [color=RED]([/color][color=BLUE]cons[/color] name done[color=RED]))[/color]
         [color=RED])[/color]
       [color=RED])[/color]
     [color=RED])[/color]
     [color=RED]([/color][color=BLUE]vla-delete[/color] acsel[color=RED])[/color] [color=RED]([/color][color=BLUE]vla-regen[/color] acdoc [color=BLUE]acallviewports[/color][color=RED])[/color]
   [color=RED])[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

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