Jump to content

Recommended Posts

Posted (edited)

.....

Edited by ryankevin15
Posted

Check this in your code I got a smiley face (>= tmp 4:) (

 

Would it not be easier to use a table rather than text and use formulas like excel.

Posted

Interesting. I was jumping back and forth between ACAD and BricsCAD and couldn't get your ADD program to show "0 items selected" and keep prompting for text selection while in BricsCAD. Try this and let me know what it does. I kept your comma code in this, although you don't show any commas in your example...

 

(princ "\nEnter \"208\" To Start Program.")

(defun comma ( / nc nt m tmp ntext )

 (setq nc 0)                   ;set counter to 0
 (setq m T)                    ;set m to true
 (setq ntext "")               ;blank out ntext
 (setq nt (strlen text1))      ;initalize counter (text1 from calling program)

 ; while loop test for ascii decimal point or number between 0 and 9 and eliminates none decimal or number char.

 (while m
   (setq nc (+ nc 1))
   (setq tmp (ascii (substr text1 nc 1)))
   (if (or (= tmp 46) (and (>= tmp 48) (<= tmp 57)))
     (setq ntext (strcat ntext (substr text1 nc 1)))
   )
   (if (= tmp 46)          ;this will adjust the decimal point to 1 if a decimal is present in the number.
     (setvar "luprec" 1)
   )
 (setq nt (- nt 1))
 (if (= nt 0) (setq m F))
 )

(setq text1 ntext)
)
ntext

;below is the original program
;end of by me


;dxf function takes an integer dxf code & ent data list and
;returns the value for that dxf code.


(defun dxf (code elist)
  (cdr (assoc code elist))
);defun
;*************************************************************
;ss1   - selection set
;n     - number of items in selection set (counter)
;total - total of float numbers in selection set
;e     -
;au    - current unit precision

(defun c:208 (/ en1 en2 ed1 ed2 et1 et2 watts amps ent text1)

 ;added by me to remove the trailing zeros
 (setq lu (getvar "luprec")) ; save current precision
 (setvar "luprec" 0) ; set precision to 0

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(while
 (not
   (and
     (setq
       en1 (entsel "\nSelect DEMAND WATTS: ")
       ed1 (if en1 (entget (car en1)))
       et1 (cdr (assoc 0 ed1))
     )
     (= et1 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(setq watts (cdr (assoc 1 ed1))
     text1 watts
)

(comma)

(setq amps (rtos (/ (atof text1) 360) 2 1))

(princ (strcat "\nTOTAL DEMAND AMPS = " amps))

(while
 (not
   (and
     (setq
       en2 (entsel "\nSelect DEMAND AMPS: ")
       ed2 (if en2 (entget (car en2)))
       et2 (cdr (assoc 0 ed2))
     )
     (= et2 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(entmod (setq ed2 (subst (cons 1 amps) (assoc 1 ed2) ed2)))

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(setvar "luprec" lu) ;return precision to it's original value
(princ)
);defun
(princ)

Posted

Sometimes there is a comma sometimes there is not. It really just depends on who was working on it. Thank you for your help.

Posted

Please read the Code Posting Guidelines and edit your Code to be included in Code Tags (not Quote Tags).[NOPARSE]

Your Code Here[/NOPARSE]

=

Your Code Here

Posted

Sorry about that. Thanks for the tip!

Posted
Check this in your code I got a smiley face (>= tmp 4:) (

 

Would it not be easier to use a table rather than text and use formulas like excel.

 

It would be easier to link an excel file, yes. But, only for us. It looks better, and is easier to read in CAD.

Posted

Using Code Tags will remove the smiley faces.

Posted
It would be easier to link an excel file, yes. But, only for us. It looks better, and is easier to read in CAD.

OP, did you try the code I posted in #3?

Posted
OP, did you try the code I posted in #3?

 

Oh, wow just tried it. Works great! Everything I needed. Thank you.

Posted

Would it be possible to make a similar command to the ADD command that will put in a comma for the answer? Maybe call it AddC.

Posted

There's a nice piece of code written by John Uhden over on the Autodesk Community Forums that puts commas into strings. I've integrated his code into the ADD program here. Give it a try:

 

;******************************************************************
;AddC.lsp 6/17/96
;v1.01 7/2/96 fixed to use local variables
;v1.02 1/15/97 Cleaned up commented out code. Added more instructions.
;v1.03 10/3/06 revised the program to work with numbers that include commas.
;v1.04 11/20/06 revised the program to stop adding zeros on the end.
;*****************************************************************
;Add string lisp routine will take a selection of text and add the
;numbers together.
;Use:
;Select some stuff. All non-text items are ignored. Any numbers in
;the selected text will be added together. Select a text item to be
;updated. The selected text item will be replaced with the result of
;the addition.
;
;Note that the units command will affect the format of the results.
;If you get a number will a bunch of trailing 0's then change units
;to fix the problem.
;
;*************************************************************
; below is the subroutine that removes the commas from the numbers and changes decimal points
; added by me

(princ "\nEnter \"addc\" To Start Program.")

(defun comma ( / nc nt m tmp ntext )

 (setq nc 0)                   ;set counter to 0
 (setq m T)                    ;set m to true
 (setq ntext "")               ;blank out ntext
 (setq nt (strlen text1))      ;initalize counter (text1 from calling program)

 ; while loop test for ascii decimal point or number between 0 and 9 and eliminates none decimal or number char.

 (while m
   (setq nc (+ nc 1))
   (setq tmp (ascii (substr text1 nc 1)))
   (if (or (= tmp 46) (and (>= tmp 48) (<= tmp 57)))
     (setq ntext (strcat ntext (substr text1 nc 1)))
   )
   (if (= tmp 46)          ;this will adjust the decimal point to 1 if a decimal is present in the number.
     (setvar "luprec" 1)
   )
 (setq nt (- nt 1))
 (if (= nt 0) (setq m F))
 )

(setq text1 ntext)
)
ntext

;below is the original program
;end of by me


;dxf function takes an integer dxf code & ent data list and
;returns the value for that dxf code.


(defun dxf (code elist)
  (cdr (assoc code elist))
);defun
;*************************************************************
;ss1   - selection set
;n     - number of items in selection set (counter)
;total - total of float numbers in selection set
;e     -
;au    - current unit precision

(defun C:addc ( / lu ed en et i n num ss1 text1 total # p#)

 ;added by me to remove the trailing zeros
 (setq lu (getvar "luprec")) ; save current precision
 (setvar "luprec" 0) ; set precision to 0


  (setq ss1 (ssget '((0 . "TEXT"))))     ; Select objects, only text
  (if ss1                        ; If any objects selected
     (progn
        (setq i 0
              total 0
              n (sslength ss1)); reset tot, set n to number of items
        (while (< i n)             ; For each selected object...
           (setq text1 (cdr (assoc 1 (setq e (entget (ssname ss1 i))))))

           ;below is the subroutine call to remove the commas

           (comma)


           (setq total (+ total (atof text1)))
           (setq i (1+ i))          ; increment counter
        );while
     );progn
  );if
  (princ "Total ")
  (princ total)
  (terpri)
  (setq en (entsel "\nSelect text to update to total")
        ed  (entget (car en))
        et  (dxf 0 ed)
  )
  (if (= et "TEXT") ; verify text was selected
;(rtos total 2) returns total formated as a string in decimal format
;substitute the new text for the old text...


;*************************************************************
; RTOC Comma code by: John Uhden (Autodesk Community Forums)

    (progn
      (setq num total)
      (setq # 1)
      (setq num (rtos num 2 #) # 1)
        (while (and (/= (substr num # 1) ".")(<= # (strlen num)))
          (setq # (1+ #))
        )
      (setq # (1- #) p# #)
        (if (= (setq # (rem # 3)) 0)(setq # 3))
        (while (< # p#)
          (setq num (strcat (substr num 1 #) "," (substr num (1+ #)))
                # (+ 4 #)
                p# (1+ p#)
          )
        )

;*************************************************************

      (entmod (setq ed (subst (cons 1 num) (assoc 1 ed) ed)))
    )

  );if

(setvar "luprec" lu) ;return precision to it's original value
(princ)
);defun
(princ)

Posted

Thanks! How do I get it to do that without the decimal point?

Posted
Thanks! How do I get it to do that without the decimal point?

 

Change the "1" to a "0" here:

 

; RTOC Comma code by: John Uhden (Autodesk Community Forums)

    (progn
      (setq num total)
      [color=red](setq # 0)[/color]
      (setq num (rtos num 2 #) # 1)
        (while (and (/= (substr num # 1) ".")(<= # (strlen num)))
          (setq # (1+ #))
        )
      (setq # (1- #) p# #)
        (if (= (setq # (rem # 3)) 0)(setq # 3))
        (while (< # p#)
          (setq num (strcat (substr num 1 #) "," (substr num (1+ #)))
                # (+ 4 #)
                p# (1+ p#)
          )
        )

Posted

So, this is the code to find 25% continuous lighting load. Could you help make it to where it will round to the nearest whole number and insert a comma?

 

(princ "\nEnter \"208\" To Start Program.")

(defun comma ( / nc nt m tmp ntext )

 (setq nc 0)                   ;set counter to 0
 (setq m T)                    ;set m to true
 (setq ntext "")               ;blank out ntext
 (setq nt (strlen text1))      ;initalize counter (text1 from calling program)

 ; while loop test for ascii decimal point or number between 0 and 9 and eliminates none decimal or number char.

 (while m
   (setq nc (+ nc 1))
   (setq tmp (ascii (substr text1 nc 1)))
   (if (or (= tmp 46) (and (>= tmp 48) (<= tmp 57)))
     (setq ntext (strcat ntext (substr text1 nc 1)))
   )
   (if (= tmp 46)          ;this will adjust the decimal point to 1 if a decimal is present in the number.
     (setvar "luprec" 1)
   )
 (setq nt (- nt 1))
 (if (= nt 0) (setq m F))
 )

(setq text1 ntext)
)
ntext

;below is the original program
;end of by me


;dxf function takes an integer dxf code & ent data list and
;returns the value for that dxf code.


(defun dxf (code elist)
  (cdr (assoc code elist))
);defun
;*************************************************************
;ss1   - selection set
;n     - number of items in selection set (counter)
;total - total of float numbers in selection set
;e     -
;au    - current unit precision

(defun c:25 (/ en1 en2 ed1 ed2 et1 et2 watts amps ent text1)

 ;added by me to remove the trailing zeros
 (setq lu (getvar "luprec")) ; save current precision
 (setvar "luprec" 0) ; set precision to 0

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(while
 (not
   (and
     (setq
       en1 (entsel "\nSelect TOTAL LIGHTING LOAD: ")
       ed1 (if en1 (entget (car en1)))
       et1 (cdr (assoc 0 ed1))
     )
     (= et1 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(setq watts (cdr (assoc 1 ed1))
     text1 watts
)

(comma)

(setq amps (rtos (/ (atof text1) 4) 2 1))

(princ (strcat "\n25% LIGHTING LOAD = " watts))

(while
 (not
   (and
     (setq
       en2 (entsel "\nSelect DEMAND AMPS: ")
       ed2 (if en2 (entget (car en2)))
       et2 (cdr (assoc 0 ed2))
     )
     (= et2 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(entmod (setq ed2 (subst (cons 1 amps) (assoc 1 ed2) ed2)))

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(setvar "luprec" lu) ;return precision to it's original value
(princ)
);defun
(princ)

Posted
Using Code Tags will remove the smiley faces.

 

Fixed, finally understood what the problem was. haha.

Posted

This should work. I added a function that rounds up at 0.5 or greater since you're dividing by 4.

(princ "\nEnter \"25\" To Start Program.")

(defun comma ( / nc nt m tmp ntext )

 (setq nc 0)                   ;set counter to 0
 (setq m T)                    ;set m to true
 (setq ntext "")               ;blank out ntext
 (setq nt (strlen text1))      ;initalize counter (text1 from calling program)

 ; while loop test for ascii decimal point or number between 0 and 9 and eliminates none decimal or number char.

 (while m
   (setq nc (+ nc 1))
   (setq tmp (ascii (substr text1 nc 1)))
   (if (or (= tmp 46) (and (>= tmp 48) (<= tmp 57)))
     (setq ntext (strcat ntext (substr text1 nc 1)))
   )
   (if (= tmp 46)          ;this will adjust the decimal point to 1 if a decimal is present in the number.
     (setvar "luprec" 1)
   )
 (setq nt (- nt 1))
 (if (= nt 0) (setq m F))
 )

(setq text1 ntext)
)
ntext

;below is the original program
;end of by me


;dxf function takes an integer dxf code & ent data list and
;returns the value for that dxf code.


(defun dxf (code elist)
  (cdr (assoc code elist))
);defun
;*************************************************************
;ss1   - selection set
;n     - number of items in selection set (counter)
;total - total of float numbers in selection set
;e     -
;au    - current unit precision

(defun c:25 (/ en1 en2 ed1 ed2 et1 et2 num rndamps watts amps text1)

 ;added by me to remove the trailing zeros
 (setq lu (getvar "luprec")) ; save current precision
 (setvar "luprec" 0) ; set precision to 0

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(while
 (not
   (and
     (setq
       en1 (entsel "\nSelect TOTAL LIGHTING LOAD: ")
       ed1 (if en1 (entget (car en1)))
       et1 (cdr (assoc 0 ed1))
     )
     (= et1 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(setq watts (cdr (assoc 1 ed1))
     text1 watts
)

(comma)

(setq amps (rtos (/ (atof text1) 4) 2 2))

(princ (strcat "\n25% LIGHTING LOAD = " watts))

(while
 (not
   (and
     (setq
       en2 (entsel "\nSelect DEMAND AMPS: ")
       ed2 (if en2 (entget (car en2)))
       et2 (cdr (assoc 0 ed2))
     )
     (= et2 "TEXT")
   )
 )
 (prompt "\n-- 0 items selected, or not TEXT --")
)

(setq amps (/ (atof text1) 4))
(if (< (- amps (fix amps)) 0.5)(setq rndamps (fix amps))(setq rndamps (1+ (fix amps)))) ;Rounding
(setq rndamps (rtos rndamps 2 0))

  (if (= et2 "TEXT")

;*************************************************************
; RTOC Comma code by: John Uhden (Autodesk Community Forums)
; Changing the "#" from 1 to 0 removes the decimal place.

    (progn
      (setq # 1)
      (setq num rndamps)
        (while (and (/= (substr num # 1) ".")(<= # (strlen num)))
          (setq # (1+ #))
        )
      (setq # (1- #) p# #)
        (if (= (setq # (rem # 3)) 0)(setq # 3))
        (while (< # p#)
          (setq num (strcat (substr num 1 #) "," (substr num (1+ #)))
                # (+ 4 #)
                p# (1+ p#)
          )
        )

;*************************************************************

(entmod (setq ed2 (subst (cons 1 num) (assoc 1 ed2) ed2)))

    )
  )

;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

(setvar "luprec" lu) ;return precision to it's original value
(princ)
);defun
(princ)

Posted

xWSSCRJ.png

 

Using these all on a daily basis. Thanks!!

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