Author Topic: Diesel Expression for a block count  (Read 10463 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
Diesel Expression for a block count
« on: October 06, 2005, 09:43:14 AM »
Can someone pen me a diesel expression to count the number of blocks in a drawing?

Block name is "12X12".

Thank You,

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #1 on: October 06, 2005, 11:48:46 AM »
If I wrote an AutoLisp function to be called using diesel can I pass it an argument?

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #2 on: October 06, 2005, 03:25:31 PM »
Did I do something wrong on the boards here?  It seems like I can't get anybody to respond to my posts.

If you don't have an answer please point me in the right direction.

deegeecees

  • Guest
Re: Diesel Expression for a block count
« Reply #3 on: October 06, 2005, 03:29:24 PM »
The Right Direction --------------------------------------------->

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #4 on: October 06, 2005, 03:34:58 PM »
 :realmad:

 :pissed:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Diesel Expression for a block count
« Reply #5 on: October 06, 2005, 05:03:47 PM »
Diesel cannot do data collection .. it can only do variable processing
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Bob Wahr

  • Guest
Re: Diesel Expression for a block count
« Reply #6 on: October 06, 2005, 05:10:33 PM »
What exactly are you needing from it?  If all you need is a one time or periodic count of the block, you could use FILTER.  If you need a running total, it would be a fairly easy undertaking in VBA and probably lisp.

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #7 on: October 06, 2005, 05:41:12 PM »
I made a dynamic block with a 12" square block inside it called "12X12".  I put an array parameter with a spacing of 12".  I put some mtext in the block to label what it was and I was trying to get it to count the number of "12X12" blocks inside the dynamic block.  Sounds easy right?  Not!  Dynamic blocks allow you to get autolisp system variables and allow you to input any diesel expression.  Since I couldn't find what I needed I thought I would try to get the number of blocks with diesel, but I don't know diesel.  I wrote a small lisp file to count the blocks but I couldn't get it to work thru diesel.

Does that make any sense at all? :|

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #8 on: October 10, 2005, 11:44:08 PM »
whdjr ...


why using diesel expression...
sur you can....but not very useful..

try the FIELD option...or BCOUNT.
Keep smile...

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #9 on: October 11, 2005, 09:54:28 AM »
whdjr ...


why using diesel expression...
sur you can....but not very useful..

try the FIELD option...or BCOUNT.

I was using the field option but it doesn't let you run acad commands (unless I missed something) only get system variables - same as with diesel.  I wrote a lisp prog to count my blocks and didn't know if there was a way to call a lisp file with diesel.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #10 on: October 11, 2005, 10:38:56 AM »
ok...
but...

Why exaclty use diesel ??

In your lisp program you must have your block count in a variable right ?
try to use this variable with..

$(GETVAR, your variable)

or...there is my block count program.

Code: [Select]
;| ;
B L I S T ;
Par: Andrea Andreetti ;
2005-08-4 ;
;
Programme permettant de calculer le nombre ;
de bloc selon la couche spécifié. |;


;| ;
;
EXÉCUTION MBLIST ;
|;
(defun c:MBlist ()
 
(setq la1 nil)
(setq la3 nil)
  
 (setq bname (ssget))
  (if (not bname)
    (progn
      (alert " No entity was selected.")
      (exit)
    )
  ) 
 (setq sscount (sslength bname))
 (setq val1 (- sscount 1))
 (setq tlen 0)       
 (repeat sscount
   (setq a1 (entget (ssname bname val1)));;détail de l'entité
   (setq a2 (cdr (assoc 2 a1)));;nom du block
   (if a2
     (progn
     (setq a3 (cdr (assoc 8 a1)));;nom du de la couche
     (setq BLitem (strcat a2 "," a3))
     (setq la1 (append la1 (list BLitem)))
     
;;;     (createfile)
     );;progn
   );;if
   (setq val1 (- val1 1))
 );;end repeat
 
(if (not a3)
  (progn
    (alert " No Block was detected in this selection.")
    (exit)
  )
)
   
(setq la1 (acad_strlsort la1))
  (setq cont 1)
 
    (setq itemp (car la1))
    (setq lalist (cdr la1))
  
  (foreach a la1
 
    (if (= itemp (car lalist))
      (progn
      (setq cont (+ cont 1))
      (setq itemp (car lalist))
      (setq lalist (cdr lalist))
      )
      (progn
      (setq la2 (strcat (rtos cont) "," itemp))
      (setq la3 (append la3 (list la2)))
      (setq itemp (car lalist))
      (setq lalist (cdr lalist))
      (setq cont 1)
      )
    );;if
  );;foreach

(setq F_space "                              ")
(setq dwglengt (- (strlen (getvar "DWGNAME")) 4))
(setq MBfilename (substr (getvar "DWGNAME") 1 dwglengt)) 
(setq MBlistfilename (strcat (getvar "DWGPREFIX") MBfilename ".txt"))  
(setq projetname (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))
 
(initget 1 "Yes No")
(setq question1 (strcase (getkword "Do you want to export the result in txt file ? (Yes/No) ")))
(if (= question1 "YES") (MBexportlist))
(if (= question1 "NO") (MBscreenonly))

(MBresetvar) 
)

(defun MBresetvar ()
  (setq la1 nil
la3 nil
bname nil
sscount nil
val1 nil
tlen nil
a1 nil
a2 nil
a3 nil
BLitem nil
la1 nil
la2 nil
la3 nil
val1 nil
cont nil
        projetname nil
itemp nil
lalist nil
F_space nil
dwglengt nil
MBfilename nil
MBlistfilename nil
FLA1 nil
virgule1 nil
virgule2 nil
vig1 nil
vig2 nil
MBi1 nil
MBi2 nil
MBi3 nil
MBi1# nil
space1 nil
space2 nil)
  (princ)
)

;| ;
SCREEN ONLY ;
|;
(defun MBscreenonly ()

 
(princ
"
                   Block List RESULT with MBlist
                   _____________________________

")
                   
;;(princ (strcat "\n\nProjet:      " projetname))
(princ (strcat "\n\nDWG File: " projetname))
(princ (strcat "\n\nDate:        " (menucmd "M=$(edtime,$(getvar,date),YYYY MON D H:MMam/pm)")))
(princ "


______________________________________ 
Qty:        Block name:         Layer:" )


 
(foreach b la3
(setq FLA1 (car la3))
  (setq virgule1 (vl-string-position 44 FLA1))
  (setq virgule2 (vl-string-position 44 (substr FLA1 (+ virgule1 2))))
  (setq vig1 (+ virgule1 2))
  (setq vig2 (+ virgule1 virgule2 3))
 
  (setq MBi1 (substr b 1 virgule1)
MBi2 (substr b vig1 virgule2)
MBi3 (substr b vig2)
  );;setq

(setq MBi1# (- 12 (strlen MBi1)))
(setq space1 (substr F_space 1 MBi1#))

(setq MBi2# (- 20 (strlen MBi2)))
(setq space2 (substr F_space 1 MBi2#)) 
 
 
(princ (strcat "\n" MBi1 space1 MBi2 space2 MBi3))

(setq la3 (cdr la3)) 
);;foreach

  (textscr)
)
 
;| ;
EXPORTATION dans un fichier TXT ;
|;
(defun MBexportlist ()

(setq MBfile (open MBlistfilename "w"))
(write-line "                  Block List RESULT with MBlist" MBfile)
(write-line "                  ___________________________________" MBfile)   
;;(write-line (strcat "\n\nProjet:      " projetname) MBfile)
(write-line (strcat "\nDWG File: " projetname) MBfile)
(write-line (strcat "\nDate:        " (menucmd "M=$(edtime,$(getvar,date),YYYY MON D H:MMam/pm)")) MBfile)
(write-line "\n\n\n______________________________________" MBfile) 
(write-line "\nQty:        Block name:         Layer:" MBfile)

 
(foreach b la3
(setq FLA1 (car la3))
  (setq virgule1 (vl-string-position 44 FLA1))
  (setq virgule2 (vl-string-position 44 (substr FLA1 (+ virgule1 2))))
  (setq vig1 (+ virgule1 2))
  (setq vig2 (+ virgule1 virgule2 3))
 
  (setq MBi1 (substr b 1 virgule1)
MBi2 (substr b vig1 virgule2)
MBi3 (substr b vig2)
  );;setq

(setq MBi1# (- 12 (strlen MBi1)))
(setq space1 (substr F_space 1 MBi1#))

(setq MBi2# (- 20 (strlen MBi2)))
(setq space2 (substr F_space 1 MBi2#)) 
 
 
(write-line (strcat "\n" MBi1 space1 MBi2 space2 MBi3) MBfile)

(setq la3 (cdr la3)) 
);;foreach
 

(close MBfile)

(command "start" (strcat MBfilename ".txt"))
  (princ)
)

(PRINC
"
________________________________________By Andrea Andreetti
Programme MBlist version 1.0
write \"MBlist\" to start")
 

hope this will help
Keep smile...

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #11 on: October 11, 2005, 10:56:41 AM »
This is what I was going to use and just pass it the name of my block so that I could use it in other places.
Code: [Select]
(defun c:bcount (str)
  (rtos
    (sslength (ssget "x" (list '(0 . "INSERT") (cons 2 str))))
    2
    0
  )
)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #12 on: October 11, 2005, 11:20:21 AM »
whdjr...

be careful..there is already a command in autocad called BCOUNT.

i'm not sure exactly what you need to do...
can you explain ?
my english is like my spanish some time.. :|
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Diesel Expression for a block count
« Reply #13 on: October 11, 2005, 11:28:09 AM »
Will,
FYI
That will fail if there are no such block in the drawing.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #14 on: October 11, 2005, 11:51:00 AM »
if you have 2006..

you can also use
eattext function to associate # of block in table.
just for info.
Keep smile...

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #15 on: October 11, 2005, 11:53:50 AM »
Will,
FYI
That will fail if there are no such block in the drawing.
Yeah, I know it will fail under the proper circumstances.  I just wanted something lean and mean.

Here is a few pictures of the block:
« Last Edit: October 11, 2005, 11:57:20 AM by whdjr »

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #16 on: October 11, 2005, 12:01:23 PM »
This is what I was going to use and just pass it the name of my block so that I could use it in other places.
Code: [Select]
(defun c:bcount (str)
  (rtos
    (sslength (ssget "x" (list '(0 . "INSERT") (cons 2 str))))
    2
    0
  )
)

try this...

Code: [Select]
(setq str (getstring "Block name : "))
(if str
  (progn
(setq str1 (ssget "X" (list (cons 0 "INSERT") (cons 2 str))))
(alert (strcat "You have " (rtos (sslength str1)) " of " str ))
))
Keep smile...

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #17 on: October 11, 2005, 12:18:55 PM »
You can't input that in a block.

I want it to be generic so if I have that block in a plan 5 times and 3 times there are 5 lockers and 2 times there are 10 lockers then it will give the correct count in the text for each block.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #18 on: October 11, 2005, 01:57:35 PM »
You can't input that in a block.

why not ?
Keep smile...

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #19 on: October 11, 2005, 03:24:26 PM »
How are you going to put your routine in a block so that it updates as the block updates?

I would like to know how because I have yet to see it done.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Diesel Expression for a block count
« Reply #20 on: October 11, 2005, 04:15:32 PM »
Will, what type of object is your locker block? You could do something really simple with an object reactor similar to what Luis did with the persistent lisp. Once it is loaded, all you need to so is update the block and let the persistent lisp program do the rest.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #21 on: October 11, 2005, 04:41:33 PM »
I have never written a reactor so I would have to look into that.

Will a reactor keep the count seperate if the block is inserted multiple times in a dwg?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Diesel Expression for a block count
« Reply #22 on: October 11, 2005, 07:08:06 PM »
I have never written a reactor so I would have to look into that.

Will a reactor keep the count seperate if the block is inserted multiple times in a dwg?
It depends on how you implement the reactor ... the reactor is simply a program ... you can have the reactor attached to a specific block, thus when that block is edited, the reactor will fore for that particular block. Of course it all means nothing if you explode the block ...

I developed a program for church pews some time ago, while it didn't use reactors, it did allow the user to edit the blocks individually, thus you could extend or trim the block and the associated attribute would update.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Diesel Expression for a block count
« Reply #23 on: October 11, 2005, 09:13:35 PM »
How are you going to put your routine in a block so that it updates as the block updates?

I would like to know how because I have yet to see it done.


Wh....   i'm trying to understand what exactly you need to do.
Yes you can't put entire code in a block
but you can use variable on it.

also,

the eattext can do your block count..(if your block was created to insert block depending the length)
otherwise you can use reactor or make your lisp dependind the block size.

You can also use invisible attribute can allow to count your block.
depending exactly what you need to do with it.
need more info... :-o
Keep smile...

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Diesel Expression for a block count
« Reply #24 on: October 12, 2005, 09:47:45 AM »
Will,

So you need text in a drawing that always has the current number for a certain amount of blocks?

If so, couldn't you just put the text in the drawing on a specific layer or add xdata or both (so you can filter it later).

Then at startup run your (ssget "x" '((....))) and update the value of your text.

Just thinking out loud here.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

whdjr

  • Guest
Re: Diesel Expression for a block count
« Reply #25 on: December 14, 2005, 02:58:13 PM »
Ok here's an update guys.  The other day I was on the Autodesk newsgroups and I was watching some of the posts for DB's and I noticed one similar to mine.  the guy with the solution recommended to the other guy to use a dimension for the counting.  Turn off all the linework for the Dim.  Then you have the text and it is already set up for a prefix or a suffix.  I thought that was ingenius.


That truely was thinking outside the box(or getting below the surface). :-)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Diesel Expression for a block count
« Reply #26 on: December 14, 2005, 03:08:35 PM »
Ingenious indeed ... if your lockers are 12" each, simply make the linear dimension scale 1/12th, set the units to decimal, no trailing or leading zeros, precision set to whole numbers, and add your custom prefix or suffix ... should do nicely ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie