Jump to content

Assigning Values to Block for Flow Calculation


suriwaits

Recommended Posts

Hi,

 

I would like to have a lisp for calculating flow of Irrigation sprinklers in a click.

 

There are different blocks in a drawing. I would like to assign 0.23 to block1 and 0.12 to block 2 and 0.06 to block3.

 

The lisp required is calculate flow by Number of Block1 x 0.23 + Nr. of Block2 x 0.12 + Nr of block 3 x 0.06, when finished selecting blocks.

 

If someone could write this in Autolisp, I would appreciate it.

 

Thanks, and let me know if the explanation was not clear

Link to comment
Share on other sites

Welcome to Cadtutor :)

 

Does it mean that you have block ( not attributed blocks ) and you want to calculate the values in the selected blocks ?

 

If not , please be more specific to your aim of the routine .

 

Tharwat

Link to comment
Share on other sites

Try this draft at the moment ...

 

(defun c:Test (/ *error* IfBlockhasSingleTextObject _sum j ss i sn l)
 ;;--- Tharwat 31. March, 2013 ---;;
 (defun *error* (msg)
   (princ
     "\n*Cancelled by user or by coincidence ,Nothings more*"
   )
 )
 (defun IfBlockhasSingleTextObject (e / i)
   (setq i 0)
   (setq e (tblobjname "BLOCK" (cdr (assoc 2 (entget e)))))
   (while (and    (setq e (entnext e))
       (not (eq (cdr (assoc 0 (entget e))) "SEQEND"))
      )
     (if (wcmatch (cdr (assoc 0 (entget e))) "*TEXT")
   (setq i (1+ i))
     )
   )
   i
 )
 (defun _sum (en / sm)
   (setq sm 0.)
   (setq en (tblobjname "BLOCK" (cdr (assoc 2 (entget en)))))
   (while (and    (setq en (entnext en))
       (not (eq (cdr (assoc 0 (entget en))) "SEQEND"))
      )
     (if (and (wcmatch (cdr (assoc 0 (entget en))) "*TEXT")
          (numberp (read (cdr (assoc 1 (entget en)))))
     )
   (setq sm (+ (read (cdr (assoc 1 (entget en)))) sm))
     )
   )
   sm
 )
 (if (setq j  0.
       ss (ssget "_:L" '((0 . "INSERT")))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (eq (IfBlockhasSingleTextObject sn) 1)
   (setq j (+ (_sum sn) j))
   (setq l (cons sn l))
     )
   )
 )
 (if l
   (alert
     (strcat "You have < "
         (itoa (length l))
         " > Blocks doesn't have or have more than one Text entity "
     )
   )
 )
 (if (> j 0)
   (alert (strcat "Total Values : " (rtos j 2 4)))
 )
 (princ "\nWritten by Tharwat Al Shoufi")
 (princ)
)

Link to comment
Share on other sites

Dear Mr.Tharwat

 

It seems nice lisp. Thanks

I will try your lisp in the morning when reaching my office.

 

By seeing your lisp and also my insufficient input given to you, this won't work as i would like to,

 

Since My blocks don't have any text value or attribute in it

 

say for example,

for the block with block name is BLK1, it should have value of 0.23

similarly for BLk2 - 0.12 and for BLK3 - 0.06 (the value not necessarily to be shown in the DWG, it should take this value and multiply by number of corresponding block and sum it with other blocks x value and display as Flow is "value of the sum"

 

I will use your program posted here, if it is not possible how i want..

 

Suriwaits

Link to comment
Share on other sites

Dear Mr.Tharwat,

 

Your program works flawlessly when the block has text of desired value.

 

In the attached drawing, 3 different blocks are there

and following is the qty

15 Nr of 180DEG

9 Nr of 360DEG

2 Nr of 90DEG

 

now i want program to calculate

 

15x0.12 + 9x0.23 + 2x0.06

 

0.12, 0.23 & 0.06 are respective flow of 180deg, 360 deg and 90 deg irrigation spray nozzles.

Sprayer1 - Copy.dwg

Link to comment
Share on other sites

If I got you well . :)

 

(defun c:Test (/ *error* j ss i e)
 ;;--- Tharwat 31. March, 2013 ---;;
 (defun *error* (msg)
   (princ
     "\n*Cancelled by user or by coincidence ,Nothings more*"
   )
 )
 (if (setq j  0.
       ss (ssget "_:L" '((0 . "INSERT") (2 . "180DEG,360DEG,90DEG")))
     )
   (repeat (setq i (sslength ss))
     (setq e (entget (ssname ss (setq i (1- i)))))
     (cond ((eq (cdr (assoc 2 e)) "90DEG")
        (setq j (+ 0.12 j))
       )
       ((eq (cdr (assoc 2 e)) "180DEG")
        (setq j (+ 1.8 j))
       )
       (t
        (eq (cdr (assoc 2 e)) "360DEG")
        (setq j (+ 2.07 j))
       )
     )
   )
 )
 (if (> j 0)
   (alert (strcat "Total Values : " (rtos j 2 4)))
 )
 (princ)
)

Link to comment
Share on other sites

Fabulous stuff.

 

Thank you for time you have spent on my request and i appreciate it.

 

works very well

 

i have changed the value as i wanted it

 

(defun c:Test (/ *error* j ss i e)
 ;;--- Tharwat 31. March, 2013 ---;;
 (defun *error* (msg)
   (princ
     "\n*Cancelled by user or by coincidence ,Nothings more*"
   )
 )
 (if (setq j  0.
       ss (ssget "_:L" '((0 . "INSERT") (2 . "180DEG,360DEG,90DEG")))
     )
   (repeat (setq i (sslength ss))
     (setq e (entget (ssname ss (setq i (1- i)))))
     (cond ((eq (cdr (assoc 2 e)) "90DEG")
        (setq j (+ 0.06 j))
       )
       ((eq (cdr (assoc 2 e)) "180DEG")
        (setq j (+ 0.12 j))
       )
       (t
        (eq (cdr (assoc 2 e)) "360DEG")
        (setq j (+ 0.23 j))
       )
     )
   )
 )
 (if (> j 0)
   (alert (strcat "Total Values : " (rtos j 2 4)))
 )
 (princ)
)

Edited by SLW210
Added Code Tags!!
Link to comment
Share on other sites

Hi,

 

I am in need of a lisp to do the following for placing placing block on a pline boundary:

 

 

Step1

 

1. Command to ask to pick a pline/line (Command line or alert)

2.Display List length of the objects picked (Alert msg).

Ask the user to input " Enter Spacing of head" (input should be either on of these numbers)

3.divide the displayed value by user input value

4.Display the divide value as "No of Possible heads are . (Alert msg )

5.Ask the user to input "Desired no of heads are (this will be rounded value of the above). (Alert msg )

 

6.Calculate Length divided by Desired no heads, is within +-0.25 from the input value (inputs are 1.25,2.25,2.75,3.25,4.25)

then proceed to step 7

 

if it is not within +-0.25 from the input value, ask the user to " Enter to different value or ESC to cancel the operation

 

If different value is entered, repeat step 6

 

 

7. Use the autocad divide command, take the input as the number of segment from step 6 once it passed the criteria.

 

8. Use Block option

 

9. if the user input is 1.25 then input the block name as 5-180

2.25 then input the block name as 8-180

2.75 then input the block name as 10-180

3.25 then input the block name as 12-180

4.25 then input the block name as 15-180

10. End

 

 

 

Thanks in advance

 

Suriwaits.

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