Jump to content

Dynamic block counting!


CadFrank

Recommended Posts

just another question like that and i only want the answer no code if i would like for some dynamic blocks not to be count would they be a possible way of doing it even so they are in the drawing.

 

Yes, you could add both a filter for DXF group 2 (block name) to the ssget expression and an additional check for the effectivename property of the dynamic block when iterating through the SelectionSet (since dynamic blocks become anonymous when the visibility state is changed).

 

I could post an example if necessary.

Link to comment
Share on other sites

Well im completly new at Lisp and im in the process of learning. what i really want is to learn those codes. So i can myself create a routine.

 

I will receive a book today on autolisp / visual lisp / vba so ill start my learning process with this i hope its a good book. but it's in french so im not sure you know the book

 

The book name is "Programmer autocad avec diesel" it is mostly sold in France i think since i can only find a library in Franec that has it. lol I live in Quebec Canada.

 

I was a hard book to find i couldn't find it in any librarie. Could only get it online.

 

so thank for the offer of the exemple i think ill start by learning the language then ill ask if i get lost

 

cheers

Link to comment
Share on other sites

Wow, I've missed lots of posts :oops:... in short (as I run out of the office for lunch):

 

@ Lee - Your input & (polite! LoL) nitpicks are always welcomed :lol:... I've learned much from your hard work in the past, and as shown today, I continue to do so regularly.

 

@ CadFrank - I'm glad I was able to show you *some* of what's possible. I hope you find your book educational, and look forward to seeing your development initiatives soon. Good luck!

 

All, cheers! :beer:

Link to comment
Share on other sites

  • 4 weeks later...
Hello,

the code not count the visibility state on this block.

 

Could you not attach the block using the forum's upload system? I'm hesitant to use other such sharing sites...

 

@Lee Mac

make you a code with "count" and "dbcount"?

 

Do you mean modify my 'count' program to include 'dbcount'? Its possible, although I'm not sure how I would represent the count in the table...

Link to comment
Share on other sites

The program is reading the Lookup parameter instead of the Visibility parameter, but I do not know of a way to distinguish between a Lookup parameter and Visibility parameter as both have identical properties... :unsure:

Link to comment
Share on other sites

The program is reading the Lookup parameter instead of the Visibility parameter, but I do not know of a way to distinguish between a Lookup parameter and Visibility parameter as both have identical properties... :unsure:

 

Perhaps by including a check for known, Allowed Values?

Link to comment
Share on other sites

Perhaps by including a check for known, Allowed Values?

 

But that requires knowing the list of Allowed Values for the Visibility Parameter for each and every block, which the user would have to add to the code manually...

Link to comment
Share on other sites

But that requires knowing the list of Allowed Values for the Visibility Parameter for each and every block, which the user would have to add to the code manually...

 

Correct, the user would have to open the Dynamic block in the Block Editor, and make a list of each parameter once... you know, hypothetically speaking.

Link to comment
Share on other sites

Correct, the user would have to open the Dynamic block in the Block Editor, and make a list of each parameter once... you know, hypothetically speaking.

 

Yeah, ideally the program wouldn't need to be modified in any way :(

Link to comment
Share on other sites

Yeah, ideally the program wouldn't need to be modified in any way :(

 

I can't really argue with that! LoL

 

So, Mexxx_ 'don't worry be happy' :rofl:

 

bobbydont-worry-be-happy%20jan21.jpg

Link to comment
Share on other sites

the code "dbcount" is ok - but not to my block.

 

I need

Visibility State...................Count
========================================
OT-Rauchmelder ZD......................1

 

but I get

Visibility State...................Count
========================================
0,0m...................................1

Link to comment
Share on other sites

Having finally figured out how to distinguish between the various parameters in a dynamic block, try this updated code:

 

[color=GREEN];;------------------=={ Dynamic Block Count }==---------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Counting all dynamic blocks by Visibility State.          ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] c:dbcount ( [color=BLUE]/[/color] _Assoc++ _PadBetween lst ss vis vl )

   ([color=BLUE]defun[/color] _Assoc++ ( key alist )
       (
           ([color=BLUE]lambda[/color] ( pair )
               ([color=BLUE]if[/color] pair
                   ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] key ([color=BLUE]1+[/color] ([color=BLUE]cdr[/color] pair))) pair alist)
                   ([color=BLUE]cons[/color]  ([color=BLUE]cons[/color] key 1) alist)
               )
           )
           ([color=BLUE]assoc[/color] key alist)
       )
   )

   ([color=BLUE]defun[/color] _PadBetween ( s1 s2 ch ln )
       (
           ([color=BLUE]lambda[/color] ( a b c )
               ([color=BLUE]repeat[/color] ([color=BLUE]-[/color] ln ([color=BLUE]length[/color] b) ([color=BLUE]length[/color] c)) ([color=BLUE]setq[/color] c ([color=BLUE]cons[/color] a c)))
               ([color=BLUE]vl-list->string[/color] ([color=BLUE]append[/color] b c))
           )
           ([color=BLUE]ascii[/color] ch)
           ([color=BLUE]vl-string->list[/color] s1)
           ([color=BLUE]vl-string->list[/color] s2)
       )
   )

   ([color=BLUE]if[/color] ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'CTAB))))
       ([color=BLUE]progn[/color]
           ([color=BLUE]vlax-for[/color] obj
               ([color=BLUE]setq[/color] ss
                   ([color=BLUE]vla-get-activeselectionset[/color]
                       ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))
                   )
               )
               ([color=BLUE]if[/color]
                   ([color=BLUE]and[/color]
                       ([color=BLUE]eq[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-isdynamicblock[/color] obj))
                       ([color=BLUE]setq[/color] vis
                           ([color=BLUE]cdr[/color]
                               ([color=BLUE]cond[/color]
                                   (   ([color=BLUE]assoc[/color] ([color=BLUE]vla-get-effectivename[/color] obj) vl)   )
                                   (   ([color=BLUE]car[/color]
                                           ([color=BLUE]setq[/color] vl
                                               ([color=BLUE]cons[/color]
                                                   ([color=BLUE]cons[/color]
                                                       ([color=BLUE]vla-get-effectivename[/color] obj)
                                                       (LM:GetVisibilityParameterName obj)
                                                   )
                                                   vl
                                               )
                                           )
                                       )
                                   )
                               )
                           )
                       )
                       ([color=BLUE]setq[/color] vis
                           ([color=BLUE]vl-some[/color]
                               ([color=BLUE]function[/color]
                                   ([color=BLUE]lambda[/color] ( prop )
                                       ([color=BLUE]if[/color] ([color=BLUE]eq[/color] vis ([color=BLUE]vla-get-propertyname[/color] prop))
                                           ([color=BLUE]vlax-get[/color] prop 'value)
                                       )
                                   )
                               )
                               ([color=BLUE]vlax-invoke[/color] obj 'getdynamicblockproperties)
                           )
                       )
                   )
                   ([color=BLUE]setq[/color] lst (_Assoc++ vis lst))
               )
           )
           ([color=BLUE]vla-delete[/color] ss)
           ([color=BLUE]princ[/color] (_PadBetween [color=MAROON]"\nVisibility State"[/color] [color=MAROON]"Count"[/color] [color=MAROON]"."[/color] 46))
           ([color=BLUE]princ[/color] (_PadBetween [color=MAROON]"\n"[/color] [color=MAROON]""[/color] [color=MAROON]"="[/color] 46))
           ([color=BLUE]foreach[/color] x ([color=BLUE]vl-sort[/color] lst '([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]<[/color] ([color=BLUE]car[/color] a) ([color=BLUE]car[/color] b))))
               ([color=BLUE]princ[/color] (_PadBetween ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] ([color=BLUE]car[/color] x)) ([color=BLUE]itoa[/color] ([color=BLUE]cdr[/color] x)) [color=MAROON]"."[/color] 46))
           )
           ([color=BLUE]textpage[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];;-----------=={ Get Visibility Parameter Name }==------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Returns the name of the Visibility Parameter of a         ;;[/color]
[color=GREEN];;  Dynamic Block (if present).                               ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Arguments:                                                ;;[/color]
[color=GREEN];;  block  -  VLA (Dynamic) Block Reference Object            ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Returns:  Name of Visibility Parameter, else nil          ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] LM:GetVisibilityParameterName ( block [color=BLUE]/[/color] visib )  
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]vlax-property-available-p[/color] block 'effectivename)
           ([color=BLUE]setq[/color] block
               ([color=BLUE]vla-item[/color]
                   ([color=BLUE]vla-get-blocks[/color] ([color=BLUE]vla-get-document[/color] block))
                   ([color=BLUE]vla-get-effectivename[/color] block)
               )
           )
           ([color=BLUE]eq[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-isdynamicblock[/color] block))
           ([color=BLUE]eq[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-hasextensiondictionary[/color] block))
           ([color=BLUE]setq[/color] visib
               ([color=BLUE]vl-some[/color]
                   ([color=BLUE]function[/color]
                       ([color=BLUE]lambda[/color] ( pair )
                           ([color=BLUE]if[/color]
                               ([color=BLUE]and[/color]
                                   ([color=BLUE]=[/color] 360 ([color=BLUE]car[/color] pair))
                                   ([color=BLUE]eq[/color] [color=MAROON]"BLOCKVISIBILITYPARAMETER"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] pair)))))
                               )
                               ([color=BLUE]cdr[/color] pair)
                           )
                       )
                   )
                   ([color=BLUE]dictsearch[/color]
                       ([color=BLUE]vlax-vla-object->ename[/color] ([color=BLUE]vla-getextensiondictionary[/color] block))
                       [color=MAROON]"ACAD_ENHANCEDBLOCK"[/color]
                   )
               )
           )
       )
       ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 301 ([color=BLUE]entget[/color] visib)))
   )
)

([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Link to comment
Share on other sites

Hey all,

 

Lee that seems to work just fine to me ...

But what if 2 or 3 blocks have the same visibilitystatename???

maybe, blockname + visibilitystate in overview?

 

greetz JOhn

 

not native enghlis

Link to comment
Share on other sites

  • 6 years later...

Hi Lee...

This is a good one and more useful for my job.

Really appreciate...

 

I have a request you that "can we add a selection option in order to select a specific area including the dynamic blocks within a drawing" ????

Presently this command is taking whole the drawing.

I mean instead an entire drawing selection can we select part areas from the drawing??

 

Thanks in advance...:D:D:D

Link to comment
Share on other sites

I just used this for the first time this morning, and while the default option is for ALL, you can also select specific areas of your drawing, instead of accepting the default.

Don't hit enter until you have selected the areas you want.

Did you download the latest version of this code, as shown in Post #55, or on Lee's website?

 

Thanks Lee, you're the best! :beer:

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