(1) First off, to change your function into a command, add a C: prefix to the defun's name, i.e.: (defun C:Pipe ....)
(2) Then, I'm assuming the 1st (getstring "\nLayer for the Pipe :") is intended for the user to specify RR/RS/Ef/FT. If so then I'd suggest you look into the initget function in the developer help and use the getkword instead of getstring. This could ensure that the user doesn't enter something different from what's intended. You may even want to do the same with the pipe dia.
(3) The PipeDiameter seems to be a list of ID / OD pairs. Maybe you should have both as strings, or do you want to find the closest match to what the user entered? If the ID is a string it makes it a lot simpler to add it to the layer name. You can always use angtof to convert the string back to a number. But using rtos to convert the number into a string might cause some formatting issues. But, lets keep this as is for the moment, see (6), (7) & (8 ) below.
(4) The cond seems to check something strange. I thin what you intended was something like this:
Code:
(cond
((= PipeLayer "RR") (setq PipeLayerFormat "Pi-RR-"))
((= PipeLayer "RS") (setq PipeLayerFormat "Pi-RS-"))
((= PipeLayer "Ef") (setq PipeLayerFormat "Pi-Ef-"))
((= PipeLayer "FT") (setq PipeLayerFormat "Pi-FT-"))
(setq PipeLayerFormat "Pi-")
)
(5) Nearly there ... You use the member function to get the match of diameter from the list. I think what you're after is this:
Code:
(if (setq PipeDiam (member PipeSize PipeDiameter))
(setq PipeDiam (car PipeDiam))
)
(6) The append function works for lists, what you want is the strcat (short for String Concatenate). But also, since you have obtained the ID/OD pair you want the layer to only use the ID. So:
Code:
(setq PipeLayer (strcat PipeLayerFormat (car (rtos (car PipeDiam)))))
Note the number needs to be converted to a string for this. The rtos may convert some numbers incorrectly formatted, e.g. 10 may become "10.00" or 0.75 may become "0.8" - it all depends on your units settings. You could change it to (rtos (car PipeDiam) 2 2) to enforce a decimal with 2 digits to the right of the point, but then what about those diameters like 10, 12, 14 ...?
(7) Therefore I'd suggest using string in the list instead. Thus:
Code:
(setq PipeDiameter
'(("0.5" "0.840")
("0.75" "1.050")
...
Then you'd also have a slight difference in point (6) above: You won't need the rtos anymore, and you can have the formatting exactly as you'd like it. But the major change would be to the portion of point (2) where you get the diameter from the user ... see below:
(8 ) Using initget to ensure the user picks only one of a set of diameters:
Code:
(initget "0.5 0.75 1 1.25 1.5 2 2.5 3 4 5 6 8 10 12 14 16 18 20 22 24")
(setq PipeSize (getkword "\nDiameter of the Pipe [0.5|0.75|1|1.25|1.5|2|2.5|3|4|5|6|8|10|12|14|16|18|20|22|24]: "))
This will ensure that the user can only pick one from that list. Same thing can be done with the RR/RS/Ef/FT.
(9) Lastly (I think) you set the current layer using something like (setvar "CLAYER" PipeLayer). If you want to return the current layer back to what it was you need to save it to a variable first (using getvar)then use setvar to reset it after you've finished creating the cylinder. And then to create the cylinder:
Code:
(command "._CYLINDER" InsertionPoint "_Diameter" (cadr PipeDiam) PipeLength)
I'm assuming you want to draw the OD of the pipe. If the ID use (car PipeLength) instead.