Jump to content

Routine that works in R14, not so well in 2007


chudney31

Recommended Posts

We use a LISP routine that was made for r14 and works great, but when we try it in 2007, it only partially works. I'll explain:

 

It's an irrigation pipe sizing routine. When it is started we are to click on the sprinkler head label. Each label has an attribute, which is a number. You click on the first label, it gives you a pipe size (1/2") based on the number attribute. Then it loops and you click on the next label, it adds the previous number attribute to the current attribute and gives you the appropriate pipe size, and so on until you are done.

 

The problem in 2007 is that when you click on the head label, it is not reading the number attribute, it shows as 0.

 

So what would be the difference between using it in r14 and 2007? I know there are going to be alot of differences between 2 versions 10 years apart, but its not that the routine is not working completely, it simply won't read the attributes on the head labels

 

If you need me to post the lisp, I will. Just wanted to see if anyone had any ideas right off the bat.

 

Thanks a bunch in advance.

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • chudney31

    10

Top Posters In This Topic

Posted Images

The only thing I can think of straight off, is that there may be a mix up between INTegers and REALs - perhaps the LISP is using a integer conversion function instead of a real conversion. This would cause a return of 0.

 

But if you post the LISP, I could see what might be wrong :)

 

Lee

Link to comment
Share on other sites

Thanks for the help. Please see below. The author was an employee of our company who unfortunately passed away recently.

 

;;1998 by David Brown
;;Provides a calculated pipe size using the 'headlbl' block with attributes containing
;;gallon per minute nozzle output for each sprinkler head selected. As the heads
;;are selected, the accumulated output is calculated and the correct pipesize
;;provided automatically. When the 'pipesize' block is inserted an opportunity
;;is provided to give it a length by picking two points which is used later for
;;pipe quantity takeoffs. The formula used is a standard calculation for a maximum
;;5 feet per second velocity.
(defun pipesizer ()
(setq clayer (getvar "clayer"))
;;LCA - COMMENT: The LAYER command has new options.
 (command "-layer" "s" "0285-pipesize" "")
 (setq ans (strcase (getstring "\nAdd heads or Reset <A>: ")))
 (if (/= ans "R")
     (progn
       (highlite 3)
       (setq ss2 (ssget))
       (setq num2 0 ent2 (ssname ss2 num2))
       (while ent2
          (ssadd ent2 ss1)
          (setq num2 (1+ num2))
          (setq ent2 (ssname ss2 num2))
       )
       (highlite 4)
     )
     (setq ss1 (ssget))
 )
 (setq num 0 gpmsum 0 ent (ssname ss1 num))
 (while ent
   (setq entyp (cdr (assoc 2 (entget ent))))
   (if (= entyp "HEADLBL") 
       (setq entatt (entnext ent)))
   (while entatt
     (setq entyp2 (cdr (assoc 2 (entget entatt))))
     (if (= entyp2 "GPM")
         (progn
          ; (ssadd ent ss2)
           (setq gpmsum (+ gpmsum 
           (atof (cdr (assoc 1 (entget entatt))))))
           (setq entatt nil)
           )
         (if (= entatt (ssname ss1 (1+ num)))
             (setq entatt nil)
             (setq entatt (entnext entatt)))
     ))  
   (setq num (1+ num))
   (setq ent (ssname ss1 num))
 )
 (prompt "Sum of gpm's: ") 
 (prin1 gpmsum)
 (calcpipe)
)
(defun psize (di)
 (* 0.408 (/ gpmsum (expt di 2.0)))
)
(defun pipelbl (ps)
 (setq plngth (getdist "\n Pipe length: "))
 (setq p "")
    (print (strcat "Current pipesize is <" ps ">"))
    (menucmd "s=psize")
    (setq p (getstring " To adjust pipesize type y (yes) and return! <n> "))
 (if (/= p "")
     (setq psx (getstring "Pick adjusted size on screen menu: "))
     (setq psx ps))
     (setq scl (getvar "userr2")) 
 (command ".insert" "/gcirr/pipesize" (getvar "viewctr") ds ds "0" psx plngth)
 (command "move" "last" "" (getvar "viewctr") pause)
 (pipesizer)
)
(defun calcpipe ()
 (if (> 3.2 (psize 0.710)) (pipelbl "1/2\""))
 (if (> 3.8 (psize 0.930)) (pipelbl "3/4\""))
 (if (> 4.3 (psize 1.189)) (pipelbl "1\""))
 (if (> 5.0 (psize 1.502)) (pipelbl "1-1/4\""))
 (if (> 5.0 (psize 1.720)) (pipelbl "1-1/2\"")) 
 (if (> 5.0 (psize 2.149)) (pipelbl "2\""))
 (if (> 5.0 (psize 2.601)) (pipelbl "2-1/2\""))
 (if (> 5.0 (psize 3.166)) (pipelbl "3\""))
 (if (> 5.0 (psize 4.072)) (pipelbl "4\""))
 )
(defun highlite (hn)
 (setq num4 0 ent4 (ssname ss1 num4))
 (while ent4
   (redraw ent4 hn)
   (setq num4 (1+ num4))
   (setq ent4 (ssname ss1 num4))
 )

Link to comment
Share on other sites

This is one routine that is part of a custom program. It should run independently, but it is part of a program that we have to load a custom menu, load the profile, etc.

Link to comment
Share on other sites

I have attempted to re-write most of the LISP, but without the blocks to test it on, this is only theoretical, so there is a good chance that it won't work :P

 

(defun pipesizer (/ *error* vl ov et gpmsum tmp grdat gr dat ent cEnt inc)
 (vl-load-com)

 (defun *error* (msg)
   (if ov (mapcar 'setvar vl ov))
   (if
     (not
       (wcmatch
         (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ
       (strcat msg
         "\n<< Error: " msg " >>"))
     (princ "\n*Cancel*"))
   (princ))

 (setq vl '("CMDECHO" "CLAYER" "ATTREQ")
       ov (mapcar 'getvar vl))

 (if
   (not
     (or
       (tblsearch "BLOCK" "pipesize")
       (findfile "\\gcirr\\pipesize.dwg")))
   (progn
     (princ "\n** Block not Found **")
     (exit)))
 
 (hlite *Objlst 3)
 (and
   (not
     (vl-catch-all-error-p
       (vl-catch-all-apply
         (function
           (lambda ( )
             (acet-sys-shift-down))))))
   (setq et t))
 (or *def (setq *def "Add"))
 (setq gpmsum 0.)
 (while
   (progn
     (initget "Add Reset Calculate")
     (or
       (not
         (setq tmp
           (getkword
             (strcat "\nAdd Heads, Reset or Calculate <" *def "> : "))))
       (setq *def tmp))
     (cond
       ((eq "Add" *def)    
        (while
          (progn
            (setq grdat (grread t 15 2)
                  gr (car grdat) dat (cadr grdat))
            (hlite *Objlst 3)
            (cond
              ((and (eq 5 gr) (listp dat))
               (if (and (setq ent (car (nentselp dat)))
                        (eq "ATTRIB" (cdr (assoc 0 (entget ent))))
                        (eq "GPM" (strcase (cdr (assoc 2 (entget ent))))))
                 (not (redraw ent 3))
                 (if ent
                   (not (redraw ent 4)) t)))
              ((and (eq 3 gr) (listp dat))
               (if (and (setq cent (car (nentselp dat)))
                        (eq "ATTRIB" (cdr (assoc 0 (entget cent))))
                        (eq "GPM" (cdr (assoc 2 (entget cent)))))
                 (if (and et (acet-sys-shift-down))
                   (progn
                     (setq *Objlst (vl-remove cEnt *Objlst))
                     (redraw cEnt 4))
                   (progn
                     (setq *Objlst (cons cent *Objlst))
                     (if (setq inc
                           (txt2num
                             (vla-get-TextString
                                (vlax-ename->vla-object ent))))
                       (progn
                         (setq gpmsum (+ gpmsum inc))
                         (princ
                           (strcat
                             "\n<< GPM = " (rtos inc 2 2)
                             ", Total = " (rtos gpmsum 2 2) " >>")))
                       (princ "\n<< GPM Could not be Obtained >>"))))
                 (princ "\n** Invalid Object Selected **")))
              ((or (eq 25 gr)
                   (and (eq 2 gr)
                        (vl-position dat '(32 13))))
               nil) ; Exit Loop
              (t t)))))
       ((eq "Reset" *def)
        (hlite *Objlst 4)
        (setq *Objlst nil) t)
       ((eq "Calculate" *def)
        (calcpipe) t)
       (t t))))
 (mapcar 'setvar vl ov)
 (hlite *Objlst 4)
 (princ))

(defun calcpipe  ()
 (cond
   ((> 3.2 (psize 0.710))
    (pipelbl "1/2\""))
   ((> 3.8 (psize 0.930))
     (pipelbl "3/4\""))
   ((> 4.3 (psize 1.189))
     (pipelbl "1\""))
   ((> 5.0 (psize 1.502))
     (pipelbl "1-1/4\""))
   ((> 5.0 (psize 1.720))
     (pipelbl "1-1/2\""))
   ((> 5.0 (psize 2.149))
     (pipelbl "2\""))
   ((> 5.0 (psize 2.601))
     (pipelbl "2-1/2\""))
   ((> 5.0 (psize 3.166))
     (pipelbl "3\""))
   ((> 5.0 (psize 4.072))
     (pipelbl "4\""))
   (t (pipelbl ""))))

(defun psize  (di)
 (* 0.408 (/ gpmsum (expt di 2.0))))

(defun hlite (lst i)
 (if lst
   (mapcar
     (function
       (lambda (ent)
         (redraw ent i))) lst)))

(defun pipelbl (ps / plngth tmp2 psx scl)
 (or *pdef (setq *pdef "Yes"))
 (setq plngth (getdist "\nPipe length: "))
 (print (strcat "Current pipesize is <" ps ">"))
 ;(menucmd "s=psize")
 (initget "Yes No")
 (or
   (not
     (setq tmp2
       (getkword
         (strcat "\nAdjust Pipesize? [Y/N] <" *pdef "> : "))))
   (setq *pdef tmp2))
 (cond
   ((eq *pdef "Yes")
    (setq psx (getstring "Pick adjusted size on screen menu: ")))
   (t (setq psx ps)))
 (setq scl (getvar "userr2"))
 (mapcar 'setvar vl '(0 "0285-pipesize" 1))
 (command "_.-insert" "\\gcirr\\pipesize.dwg" (getvar "viewctr") scl scl 0.0 psx plngth)
 (command "_.move" (entlast) "" (getvar "viewctr") pause))

Link to comment
Share on other sites

Ok, loaded routine, starts out ok by asking if I want to add head, reset or calculate, I type in A for add, but when I try to select the head label (or block), it tells me invalid object selected. So I guess there's some tweaking needed. If you need something from me, let me know.

 

Thanks!

Link to comment
Share on other sites

Well, I only really had the old routine to go on - so I've just tried to decipher what you are trying to extract etc, so I've kept all the calculations mostly the same.

 

I've set it to detect the GPM attribute, but this may be wrong.

 

If possible, could you provide both the block that you want clicked and also the block to be inserted. :)

 

Thanks.,

 

Lee

Link to comment
Share on other sites

Oh trust me, I'm not complaining, you are already a hero in my book!

 

Ok, well I guess this is where it might get a little complicated. I can give you the blocks for the pipelbl and head label, but the head label block does not have attributes added to it. There is another lisp routine that we use to tell it what type of sprinkler head to use, what gpm, etc. And of course, this lisp routine fills in the pipelbl attributes. So I hope this is enough for you to work off of. Thanks a million.

HEADLBL2.dwg

Pipesize.dwg

Link to comment
Share on other sites

Ok, this is a much simpler (but less elegant) way of coding it.

 

I have set it to "remember" the heads and gpmsum that you have added, but I have left the rest of the code mostly how you had it with regards to calculating the pipelength etc.

 

(defun pipesizer (/ *error* vl ov tmp ent inc)
 (vl-load-com)

 (defun *error* (msg)
   (if ov (mapcar 'setvar vl ov))
   (hlite *objlst 4)
   (if
     (not
       (wcmatch
         (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ
       (strcat msg
         "\n<< Error: " msg " >>")))
   (princ))

 (setq vl '("CMDECHO" "CLAYER" "ATTREQ")
       ov (mapcar 'getvar vl))

 (if
   (not
     (or
       (tblsearch "BLOCK" "pipesize")
       (findfile "\\gcirr\\pipesize.dwg")))
   (progn
     (princ "\n** Block not Found **")
     (exit)))
 
 (hlite *Objlst 3)
 (or *def (setq *def "Add"))
 (or *gpmsum (setq *gpmsum 0.))
 (while
   (progn
     (initget "Add Reset Calculate")
     (or
       (not
         (setq tmp
           (getkword
             (strcat "\nAdd Heads, Reset or Calculate <" *def "> : "))))
       (setq *def tmp))
     (cond
       ((eq "Add" *def)    
        (while
          (and
            (Setq ent (car (entsel "\nSelect Head: ")))
            (eq "INSERT" (cdr (assoc 0 (entget ent))))
            (eq "HEADLBL2" (strcase (cdr (assoc 2 (entget ent))))))
          (setq *Objlst (cons ent *Objlst))
          (hlite *Objlst 3)
          (foreach att (vlax-safearray->list
                         (vlax-variant-value
                           (vla-GetAttributes
                             (vlax-ename->vla-object ent))))
            (if (eq "GPM"
                  (strcase
                    (vla-get-TAgString att)))
              (if (setq inc
                    (txt2num
                      (vla-get-TextString att)))
                (progn
                  (setq *gpmsum (+ *gpmsum inc))
                    (princ
                      (strcat
                        "\n<< GPM = " (rtos inc 2 2)
                          ", Total = " (rtos *gpmsum 2 2) " >>")))
                (princ "\n<< GPM not Numerical >>")))))
        t)
       ((eq "Reset" *def)
        (hlite *Objlst 4)
        (setq *Objlst nil *gpmsum 0.) t)
       ((eq "Calculate" *def)
        (calcpipe) t)
       (t t))))
 (mapcar 'setvar vl ov)
 (hlite *Objlst 4)
 (princ))

(defun calcpipe  ()
 (cond
   ((> 3.2 (psize 0.710))
    (pipelbl "1/2\""))
   ((> 3.8 (psize 0.930))
     (pipelbl "3/4\""))
   ((> 4.3 (psize 1.189))
     (pipelbl "1\""))
   ((> 5.0 (psize 1.502))
     (pipelbl "1-1/4\""))
   ((> 5.0 (psize 1.720))
     (pipelbl "1-1/2\""))
   ((> 5.0 (psize 2.149))
     (pipelbl "2\""))
   ((> 5.0 (psize 2.601))
     (pipelbl "2-1/2\""))
   ((> 5.0 (psize 3.166))
     (pipelbl "3\""))
   ((> 5.0 (psize 4.072))
     (pipelbl "4\""))
   (t (pipelbl ""))))

(defun psize  (di)
 (* 0.408 (/ *gpmsum (expt di 2.0))))

(defun hlite (lst i)
 (if lst
   (mapcar
     (function
       (lambda (ent)
         (redraw ent i))) lst)))
;CAB
(defun txt2num  (txt)
 (cond ((distof txt 5))
       ((distof txt 2))
       ((distof txt 1))
       ((distof txt 4))
       ((distof txt 3))
       (T nil)))

(defun pipelbl (ps / plngth tmp2 psx scl)
 (or *pdef (setq *pdef "Yes"))
 (setq plngth (getdist "\nPipe length: "))
 (print (strcat "Current pipesize is <" ps ">"))
 ;(menucmd "s=psize")
 (initget "Yes No")
 (or
   (not
     (setq tmp2
       (getkword
         (strcat "\nAdjust Pipesize? [Y/N] <" *pdef "> : "))))
   (setq *pdef tmp2))
 (cond
   ((eq *pdef "Yes")
    (setq psx (getstring "Pick adjusted size on screen menu: ")))
   (t (setq psx ps)))
 (setq scl (getvar "userr2"))
 (mapcar 'setvar vl '(0 "0285-pipesize" 1))
 (command "_.-insert" "\\gcirr\\pipesize.dwg" (getvar "viewctr") scl scl 0.0 psx plngth)
 (command "_.move" (entlast) "" (getvar "viewctr") pause))

Link to comment
Share on other sites

Ok, thanks for all your help first of all!

 

When I run it, it doesn't seem to be tallying up the gpm (or attribute) of each head I select. It will give me the option to Add, Replace or Calculate, I hit 'a' for add and click a head, then I can hit enter and hit the next head, and so forth. When I type in 'c' for calculate, it asks for pipe length, which I enter. And the result is 1/2", which is fine, but i know that the pipe size should have been bigger because the sum of the attributes clicked should have fallen in the range of a bigger size pipe.

 

The other problem is that the resulting pipe size label is coming out at the wrong scale. We set our drawings at decimal, and will do things at 1"=10', 20' or 30'. So at 1=10 the scale of labels would be .083. However, this scale is set in the drawing by yet another routine. So somehow with the old code, it knew which scale to use. These are coming out much bigger.

 

I wish there were a way for me to show you how the old program worked. That would probably make it much easier for you.

Link to comment
Share on other sites

I see, I didn't know about the scale being set by another routine. This means that the variables are global which isn't ideal. I have set the scale to be retrieved from the USER2 sys var, but I am not sure what that is being set to.

 

As for the GPM being collected, I tested it, and it seems to accumulate:

 

 

Test.gif

Link to comment
Share on other sites

Ok, well first off, I'm an idiot. I gave you the wrong head label block, once I changed it to the right block, it started adding the attributes. However, once it got to actually bringing in the pipe label, it was making me enter x, y, z size. But that is actually a secondary problem now :?.

 

When I first entered in the new lisp, I was in a drawing, I saved the lisp, and it recognized the command. But then when I went to another drawing, I had loaded the menu and everything the same way, it was not recognizing the command. So I closed all drawings, reopened, loaded the menu's, and now it gives the following in the command line:

 

Command:

Command: -Layer

 

Current layer: "0285-PIPESIZE"

Enter an option

[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock

/stAte]: s

 

Enter layer name to make current or

Enter an option

[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock

/stAte]:

 

Command: (if (not pipesize) (load"/gcirr/pipesize"))

 

Copyright - 1998 IRMASTER All rights reserved.

 

Command: PIPESIZE

Unknown command "PIPESIZE". Press F1 for help.

 

Command: r

nil

Is it a problem on my end now?
Link to comment
Share on other sites

That looks like it is part of a different program - as mine doesn't invoke the "-layer" command at all..

 

As for the x, y prompts, take a look at the pipelbl program within my code post, as I have kept this mostly the same as the original, as it contains custom menu's I believe. Oh, and uncomment the menucmd line also.

Link to comment
Share on other sites

Ok Lee, I'm back. A couple of issues, and if this is way too much for you, please let me know, I understand you are doing this in your spare time and I really appreciate what you do for "code challenged" people like me.

 

I seem to be having an inconsistency when the I try to load and run the routine. I can have a drawing open and open up the lsp file and substitue the old one with the new and save, then run it from the drawing and it works (although I'm still having trouble with the pipe label part of it, but I'll get to that in a second). But then when I close the drawing, and open another and load our menu's and what not, when I try the routing again it gives me the following:

 

Command: -Layer

 

Current layer: "0285-PIPESIZE"

Enter an option

[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock

/stAte]: s

 

Enter layer name to make current or

Enter an option

[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock

/stAte]:

 

Command: (if (not pipesize) (load"/gcirr/pipesize"))

 

Copyright - 1998 IRMASTER All rights reserved.

 

Command: PIPESIZE

Unknown command "PIPESIZE". Press F1 for help.

 

Command: r

REDRAW

 

The original lisp started out with a setq clayer and command "-layer" so I'm assuming maybe that has something to do with it. Any thoughts on that? For some reason, to get it work I have to literally sub out the old with the new everytime. I should also mention that we have a custom menu button to start the pipesize routine, but that seems to be ok.

 

Ok, second issue. When it does load up correctly, it will go thru the routine up to where it is supposed to give you the pipe label (1/2", 3/4", etc) and it says "Value must be nonzero. Enter X...etc." And at one time, it would output the label, but the scale was off, as I mentioned before. Any thoughts on that as well? Thank you again.

Link to comment
Share on other sites

The original lisp started out with a setq clayer and command "-layer" so I'm assuming maybe that has something to do with it. Any thoughts on that? For some reason, to get it work I have to literally sub out the old with the new everytime. I should also mention that we have a custom menu button to start the pipesize routine, but that seems to be ok.

 

This issue with the layer creation must be within another routine, as the code I posted assumes the pipesize layer to already exist (like the old code did). I'd be happy to look over the other code if you wish.

 

Ok, second issue. When it does load up correctly, it will go thru the routine up to where it is supposed to give you the pipe label (1/2", 3/4", etc) and it says "Value must be nonzero. Enter X...etc." And at one time, it would output the label, but the scale was off, as I mentioned before. Any thoughts on that as well? Thank you again.

 

As for the scale issue, I see you are using the USER2 sys var, and I have just use this value for the scale, but I am not sure what is being set to this sys var, as I don't know of the rest of the code. :)

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