PDA

View Full Version : Help With String Manipulation


vferrara
2006-12-05, 12:14 AM
Hello AUGI Members:

I am trying to develop a routine that will determine the proper format of a text callout for a footing on a drawing. For example: when the Xsize of the footing is 5'-0" and the Ysize of the footing is 5'-0" the callout should be F5. When the Xsize of the footing is 5'-0" and the Ysize of the footing is 8'-0" then the callout should be F58. There is also a condition as follows: When the Xsize of the footing is 5'-0" and the Ysize of the footing is 8'-6" then the callout would be F58.5 and if the Xsize of the footing is 5'-6" and the Ysize of the footing is 8'-6" then the callout would be F5.58.5......and so on....!

Here is the piece of code where I try to setup the callouts but there is a problem with the code.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;
(Defun Fdntag ()

(setq SX (/ Xxsf 12))
(setq SY (/ Yysf 12))

;;;;;;
;;;;;;COMPOSE CALL OUT
;;;;;;
(setq SizX (rtos SX 2 2))
(setq SizY (rtos SY 2 2))

(If (= SizX SizY)(Fdntag1))

(If (/= SizX SizY)(Fdntag2))

)

;;;;;;
;;;;;;LENGTH = WIDTH
;;;;;;
(defun Fdntag1 ()

(setq SizX2 (rtos SX 2 0))
(setq SizY2 (rtos SY 2 0))

(setq Tnam (strcat "F" SizX2))
)

;;;;;;
;;;;;;LENGTH / = WIDTH
;;;;;;
(defun Fdntag2 ()

(setq SizX (rtos SX 2 2))
(setq SizY (rtos SY 2 2))

(setq SizX2 (rtos SX 2 0))
(setq SizY2 (rtos SY 2 0))

(setq Xend (substr SizX 4 2))
(setq Yend (substr SizY 4 2))

(If (And (= Xend "00")(/= Yend "00")) (Setq Tnam (strcat "F" SizX2 SizY)))
(If (And (/= Xend "00")(= Yend "00")) (Setq Tnam (strcat "F" SizX SizY2)))
(If (And (/= Xend "00")(/= Yend "00")) (Setq Tnam (strcat "F" SizX SizY)))
(If (And (= Xend "00")(= Yend "00")) (Setq Tnam (strcat "F" SizX2 SizY2)))

)


Any assistance in resolving this problem would be appreciated....!!!

Regards,
Vince

T.Willey
2006-12-05, 01:42 AM
Try this.

(defun FootingCallout (Xstr Ystr / Xnum Ynum)

(setq Xnum (distof Xstr 4))
(setq Ynum (distof Ystr 4))
(setq Rtn (strcat "F" (itoa (fix (/ Xnum 12)))))
(if (not (equal (rem Xnum 12) 0.0))
(setq Rtn (strcat Rtn (itoa (fix (* 10 (/ (rem Xnum 12) 12))))))
)
(if (not (equal Xnum Ynum))
(progn
(setq Rtn (strcat Rtn (itoa (fix (/ Ynum 12)))))
(if (not (equal (rem Ynum 12) 0.0))
(setq Rtn (strcat Rtn (itoa (fix (* 10 (/ (rem Ynum 12) 12))))))
)
)
)
Rtn
)

Returns

Command: (footingcallout "5\'-0\"" "8\'-0\"")
"F58"

Command: (footingcallout "5\'-0\"" "8\'-6\"")
"F585"

Command: (footingcallout "5\'-6\"" "8\'-6\"")
"F5585"

Command: (footingcallout "8\'-6\"" "8\'-6\"")
"F85"

Command: (footingcallout "8\'-0\"" "8\'-0\"")
"F8"

CAB2k
2006-12-05, 04:51 AM
Another way to skin the cat.
(defun c:ftg (/ x y callout precx precy)
(initget 7)
(setq x (getdist "\nEnter the Footing width (x) :"))
(initget 7)
(setq y (getdist "\nEnter the Footing length (y) :"))
(setq precx (if (zerop (rem x 12)) 0 1))
(setq precy (if (zerop (rem y 12)) 0 1))

(if (equal x y)
(setq callout (strcat "F" (rtos (/ x 12) 2 precx)))
(setq callout (strcat "F" (rtos (/ x 12) 2 precx) (rtos (/ y 12) 2 precy)))
)
callout
)

vferrara
2006-12-05, 04:37 PM
Hi Tim and CAB:

Thank you for your quick response.....!

I tested both methods but the one that seemed to work better in my environment was the solution provided by CAB.

Once again, thank you both for your assistance regarding this matter, it was appreciated...!!!

Regards,
Vince