Saturday, January 20, 2024

Autolisp Routines for labelling piping PIDs

I am now working at a product process consultancy and one of the tasks is to 
look at a PID, and work out where the pipes on the diagram go.

Sometimes, there are no line numbers, so to make things easier on me, I decided to give all the pipes line numbers.  Normally these look like HW-50-001, ie they give an idea of what is in the pipe, it's size and lastly a number.

In line with my dubious philosophy of keeping life simple, I made a copy of the PID and set about numbering all the pipes with just a simple number , ie 1,2 and so on.

My cunning plan was to have an Excel spreadsheet with a From/To list, which would have product and size on there instead.

I also set up the 3d drawing of the pipes with a set of layers labelled 1, 2 and so on.

To save my sanity, I developed several lisp routines to help automate this process as the plant was quite large.

This first one sets up layer numbers in the 3D drawing.  It asks you for the first number and the last number. Then it creates all the layers, and makes the colour of the layer to be the colour number.  Yes, you are correct....this limits this idea to 250 layers.

I could modify the routine to allow for this at some stage.  I did notice that some colours are pretty dark, so this is a drawback that might have to be addressed.

(defun c:laysnum()
  (setq startno (getint "/n Start no: "))
  (setq finishno (getint "/n Finish no: "))
  (setq thenolayers (- finishno startno))

  (while (< startno finishno)
    (progn
      (setq thelayers (itoa startno))
      (command "-layer" "m" thelayers "c" thelayers "" "")
      (setq startno (+ startno 1))
    ) ; end progn
  ) ; end while
  (princ)
)

The second is for use on the PID and asks the user to select a line, then key in a number, eg 4, and then asks for a text position.  The routine changes the layer of the line to 4 and puts the text of "4" above the line.

All while assuming zero height text of course;)

(defun c:CLAT ()
(setq theent (car (entsel "\nSelect a line: ")))
(setq layerNumbers (getstring "\nEnter a number (X): "))
(setq textPosition (getpoint "\nSpecify text position: "))
(setq edata(entget theent))
(setq edata (subst (cons 8 layerNumbers) (assoc 8 ed) edata ))
(entmod edata)
(command "text" textPosition "" "" layernumbers)
  (princ)
);end defun

The next one does the same, just that it does not ask for a text position-this is for when you have the numbers already on the drawing.

(defun c:zzCLAT ()
(setq theent (car (entsel "\nSelect a line: ")))
(setq layerNumbers (getstring "\nEnter a number (X): "))
(setq edata(entget theent))
(setq edata (subst (cons 8 layerNumbers) (assoc 8 ed) edata ))
(entmod edata)
(princ)
);end defun

This one just puts in numbers only, sequentially.

(defun C:zzn( /  z b x y )
(setvar "CMDECHO" 0)
(command "osnap" "none")
(setq oldsnap (getvar "osmode"))
    (if (equal numberf nil)
        (setq numberf 1)
    )
(setq numbers (rtos numberf))
(while (not(equal numbers "299"))
(progn
(setq x (getpoint "\n Pick Number Position "))
(command "Text" x "" "" numbers)
(setq numberf(atof numbers))
(setq numberf (+ numberf 1))
(setq numbers (rtos numberf))
);end progn
);end while
(setvar "osmode" oldsnap)
(setvar "CMDECHO" 1)
 (princ)
)

Notice that there is a variable in there called numberf.  If you have used the routine once, it will persist and will pick up again where you left off.  To start again at a specified number use:

(defun  c:zzNUM()
(setq numberf (getreal "/nEnter your start number "))
(princ)
 )

If all this is confusing, try blecouteur14 the at thing at jeeeeemail, asking me to do a short video.




No comments: