Jump to content

Recommended Posts

Posted

Hello,

 

I am hoping I could get some help with this problem. Any help would be greatly appreicated. I am writing a lisp routine to count blocks by there attribute value. The blocks will have the same attribute tags, But different values. I am looking to get the quantity of each type of block in any combination of attribute values. I have arranged the statement below, But I am not sure if it is written correctly. Do I need to call this with logical operators or will this do fine?

 

                           BLOCK    ATTDEF  ATTDEF  ATTDEF
                           NAME
(setq DOWM (ssget "x" ' ((2 . bname)(1 . DT)(1 . MT)(1 . ST))))

 

Again the help would be great,

Thanks in advance,

The Buzzard

  • Replies 61
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    31

  • Lee Mac

    22

  • David Bethel

    6

  • borgunit

    1

Posted

Thanks very much borgunit!

 

I believe I can get my answer there. Lots of info.

I will check it out.

 

The Buzzard

Posted

Buzzard,

 

You can filter BLOCK names but not ATTDEF or ATTRIB tags or values. You will have to step thru a selection set and test for these.

 

You can add a SEQ filter to make sure that blocks have ATTRIButes. (66 . 1)

 

So to select all INSERTS with ATTRIButes in the current space with block_name:

[b][color=BLACK]([/color][/b]setq ss [b][color=FUCHSIA]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=MAROON])[/color][/b]
                         [b][color=MAROON]([/color][/b]cons 2 block_name[b][color=MAROON])[/color][/b]
                         [b][color=MAROON]([/color][/b]cons 66 1[b][color=MAROON])[/color][/b]
                         [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=GREEN])[/color][/b]
                             [b][color=GREEN]([/color][/b]cons 410 [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                             [b][color=GREEN]([/color][/b]cons 67 [b][color=BLUE]([/color][/b]- 1 [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"TILEMODE"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Posted

As far as I know, with vlisp, you cannot filter selections based on the attributes, as those are "sub-properties" (my term) of block inserts.

 

You can filter for multiple values similar to your code, here's an example for text:

 

(setq selset (ssget "x" '((0 . "TEXT") (1 . "text1,text2"))))

 

**edit** I see I'm a dollar late & short, my cue to get back to work :)

Posted

Wow, I seem to be making a deeper hole.

This is very involved.

Just keep pushing on.

 

Looks as if I will be doing alot of reading.

 

Thanks for help guys.

The Buzzard

Posted

An example of stepping throught the set and various "sub-entities."

(defun c:attribext    (/ ss i bEnt aEnt aEntlist attlist)
   (vl-load-com)
   (if    (setq ss (ssget    "X"
           (list (cons 0 "INSERT")
                 (cons 66 1)
                 (if (getvar "CTAB")
                 (cons 410 (getvar "CTAB"))
                 (cons 67 (- 1 (getvar "TILEMODE")))
                 )
           )
        )
   )
   (progn
       (setq i (sslength ss))
       (while (not (minusp (setq i (1- i))))
       (setq bEnt (ssname ss i)
             aEnt (entnext bEnt)
       )
       (while (/= "SEQEND" (cdr (assoc 0 (entget aEnt))))
           (setq aEntlist (entget aEnt)
             attlist  (cons (cons (cdr (assoc 2 aEntlist)) (cdr (assoc 1 aEntlist))) attlist)
           )
           (setq aEnt (entnext aEnt))
       )
       )
   )
   (princ "\n<!> No Attributed Blocks Found <!>")
   )
   (alert (vl-princ-to-string attlist))
   (princ)
)

Posted

Nice code Lee_Mac,

 

But not exactly what Im after.

I am using four named blocks.

Data, Voice, Voice/Data, & Fiber

 

Within each block are three attribute Tags.

DT = Drop Type DATA, VOICE, VOICE/DATA FIBER

MT = Mount Type WALL, CLNG, FLOR, FURN

ST = System Type A, C P, W, WP, SL, WS - Etc. Etc.

 

I want to count the blocks by any combination of how the

attributes are filled in.

 

Would be nice if I could figure out this filtering thing, But Ill get there someday.

 

I when I grow up I want to be just like Lee_Mac then my problems will be over.

 

Thanks,

The Buzzard

Posted
Nice code Lee_Mac,

 

But not exactly what Im after.

I am using four named blocks.

Data, Voice, Voice/Data, & Fiber

 

Within each block are three attribute Tags.

DT = Drop Type DATA, VOICE, VOICE/DATA FIBER

MT = Mount Type WALL, CLNG, FLOR, FURN

ST = System Type A, C P, W, WP, SL, WS - Etc. Etc.

 

I want to count the blocks by any combination of how the

attributes are filled in.

 

Would be nice if I could figure out this filtering thing, But Ill get there someday.

 

Sorry Buzzard, I only posted the code as an example of how one can step through a selection set and retrieve the various entities. - not specifically for your LISP. I noticed in your original post that you mention that you are writing a LISP and wanted help - so I didn't just want to write the whole LISP for you, but offer some advice instead.

 

If you would like me to carry on and (try to) write the LISP to suit your needs, I shall.

 

 

I when I grow up I want to be just like Lee_Mac then my problems will be over.

 

Haha, nice one. :lol:

Posted

I am not sure if you are human,

 

I get the impression you have ten 500 GHz microprocessors built into that mind of yours.

Posted
I am not sure if you are human,

 

I get the impression you have ten 500 GHz microprocessors built into that mind of yours.

 

Many have said the same on here o:)

 

Although there are many on here better than me.... perhaps with ten THz processors... Take ReMark for instance - he's a cyborg anyway.

Posted

I want to do this on my own of course.

 

And I shall.

 

I just need to be pointed in the right direction sometimes.

Posted

No Probs, I always think its better if you work it out for yourself - sinks in that way :thumbsup:

 

If you need any further help - just ask.

 

Cheers

 

Lee

Posted

Thanks

 

Its nice to know your a few keyboard strokes away.

Posted

Ok, so I couldn't resist:

 

(defun c:blkattlist (/ bName ss dt mt st iblk blkcnt bEnt aEnt
              dtcnt mtcnt stcnt tagval attval)

   (while (or (not bName) (not (snvalid bName)))
   (setq bName (getstring "\nSpecify Name of Block for Which to Search: ")))

   (if    (setq ss (ssget    "X" (list (cons 0 "INSERT") (cons 2 bName) (cons 66 1)
                 (if (getvar "CTAB")
                 (cons 410 (getvar "CTAB"))
                 (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn

   (while (or (not dt)(not mt)(not st))
   (princ "\nSearch for Blocks with Attribute Values...")
   (setq dt (getstring "\nDrop Type:  ")
         mt (getstring "\nMount Type:  ")
         st (getstring "\nSystem Type:  ")))


       (setq iblk (sslength ss) blkcnt iblk dtcnt 0 mtcnt 0 stcnt 0)
       (while (not (minusp (setq iblk (1- iblk))))
       (setq bEnt (ssname ss iblk) aEnt (entnext bEnt))
       (while (/= "SEQEND" (cdr (assoc 0 (entget aEnt))))
           (setq tagval (cdr (assoc 2 (entget aEnt)))
             attval (cdr (assoc 1 (entget aEnt))))
           (cond ((and (= tagval "DT") (= attval dt))
              (setq dtcnt (1+ dtcnt)))
             ((and (= tagval "MT") (= attval mt))
              (setq mtcnt (1+ mtcnt)))
             ((and (= tagval "ST") (= attval st))
              (setq stcnt (1+ stcnt))))
           (setq aEnt (entnext aEnt))))

   (alert (strcat (rtos blkcnt) " Blocks Found with Name: " bName
          "\n\n" (rtos dtcnt) " With Drop Type: " dt
          "\n" (rtos mtcnt) " With Mount Type: " mt
          "\n" (rtos stcnt) " With System Type: " st)))
   (alert (strcat "No Blocks Found with Name: \n" bName)))
   (princ))
              

 

And yes, it is 1:35am here and I have nothing better to do than write LISPs :P

Posted
Ok, so I couldn't resist..............And yes, it is 1:35am here and I have nothing better to do than write LISPs :P

 

 

 

time is not wasted when you wasted it on the most enjoyable things that you do...............:)

Posted

Look like Santa arrived early,

 

Lee this is very much appreciated, But you did not need to bother yourself with this. Any other kind of direction would be welcomed.

I tested the routine out on mulltiple blocks, Anyway for the most part it works great, But at the same time it reports back blocks with the same block name that did not match the other criteria.

 

I realized earlier that it was important to use the filtering with logical operators, But as you are aware, This will not work with attribute. I also begun to realize that I would need to change the strategy by naming the blocks differently and making use of the way I name the layer to give me an additional filter to work with. I believe this will find blocks with the same name, But different layers down to the one & only insertion of it if that is the case.

 

In any event I will make good use of the code you provided. I can see that with some modifications I can get close to what it is that I wanted to do. You may be aware that most of the codes I put together are for entity creation. I decided to try something different for a change and like before when I started learning lisp, I know it will take some time for me to get it down right.

 

Thank You So Much,

Well Done!

The Buzzard

 

Oh by the way, I am curious. Can you write code and hop on one leg at the same time? Just wondering.

Posted

Buzzard,

 

This is a fairly complex task for a first attempt:

 

Assumptions:

  • All INSERTs are model space entities
  • You use just the 4 BLOCK names listed
  • You are very consistent with ATTRIBute values ie spelling spaces etc

[b][color=BLACK]([/color][/b]defun c:phonecnt [b][color=FUCHSIA]([/color][/b]/ ss i en an ad dt mt st pt fl tn av[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b]
                                [b][color=BLUE]([/color][/b]cons 2 [color=#2f4f4f]"DATA,VOICE,VOICE/DATA,FIBER"[/color][b][color=BLUE])[/color][/b]
                                [b][color=BLUE]([/color][/b]cons 66 1[b][color=BLUE])[/color][/b]
                                [b][color=BLUE]([/color][/b]cons 67 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   dt nil mt nil st nil[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq tn [b][color=BLUE]([/color][/b]strcase [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 2 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                          av [b][color=BLUE]([/color][/b]strcase [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]cond [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= tn [color=#2f4f4f]"DT"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setq dt av[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                          [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= tn [color=#2f4f4f]"MT"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setq mt av[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                          [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= tn [color=#2f4f4f]"ST"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setq st av[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]and dt mt st
                 [b][color=GREEN]([/color][/b]setq pt [b][color=BLUE]([/color][/b]strcat dt [color=#2f4f4f]","[/color] mt [color=#2f4f4f]","[/color] st[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]assoc pt fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                     [b][color=BLUE]([/color][/b]setq fl [b][color=RED]([/color][/b]cons [b][color=PURPLE]([/color][/b]cons pt 1[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                     [b][color=BLUE]([/color][/b]setq fl [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons pt [b][color=TEAL]([/color][/b]1+ [b][color=OLIVE]([/color][/b]cdr [b][color=GRAY]([/color][/b]assoc pt fl[b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                     [b][color=PURPLE]([/color][/b]assoc pt fl[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 fl[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

What this gives you is an associative list ( fl ) with the attribute string values concatenated and then number of times that exact combination was found.

 

If you need to break out the block names with it, it becomes even more complex.

 

You'll need to do something with list but it is a start. Good Luck -David

Posted

David,

 

That's on the mark, Excellent!

I believe I can get this from here.

 

Thank You & Also Lee

Now I got some serious coding to do.

The Buzzard

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