AMMEND LISP FILE

AMMEND LISP FILE

lmoultonX6YLM
Participant Participant
728 Views
7 Replies
Message 1 of 8

AMMEND LISP FILE

lmoultonX6YLM
Participant
Participant

Hi,

Could anyone help ammend this lips file please. Its part of a longer file.

The lisp ( i think - i'm no programmer ) looks and returns the length of pipe by its name.

It was working fine...however we have now changed the block/file name FROM Pipe Cut To 1170mm - horizontal

TO Pipe-H-1170.

Thanks

Lee

 

code below


;;;--- Function to get the length from the block name
;;; Example Blockname = "pipe cut to 1170mm - horizontal"
;;; Returns 1170.0 as real number
(defun getLength(blkName)
(setq cnt 1 foundIt 0)
(while(< cnt (- (strlen blkName) 1))
(setq ch(substr blkName cnt 2))
(if(= ch "mm")
(setq foundIt cnt)
)
(setq cnt(+ cnt 1))
)
(if(> foundIt 0)
(progn
(setq nxtLen(substr blkName (- foundIt 2) 2))
(setq len(substr blkName (- foundIt 1) 1))
(setq incCnt 3)
(while(> (atof nxtLen) (atof len))
(setq len nxtLen)
(setq nxtlen(substr blkName (- foundit incCnt) incCnt))
(setq incCnt(+ incCnt 1))
)
)
)
(atof len)
)

0 Likes
Accepted solutions (3)
729 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Possibly like this which works for both

 

(defun getLength (n) (atof (vl-list->string (vl-remove-if-not '(lambda (x) (< 47 x 58)) (vl-string->list n)))))

0 Likes
Message 3 of 8

lmoultonX6YLM
Participant
Participant

Hi,

Thanks for the response -

i was hoping to keep the coding pretty much the same - could i just not remove / ammend certain lines

for example - would it work by just removing (if(= ch "mm") ??

That might sound stupid - but i donot understand what the code is looking for and just want to change it slightly then paste it back into the rest of lisp program. Does that make sense ?

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Ok, let's play your game.

The original code search for "mm" and then goes backward from it and grabs all numbers.

Now, since we don't have "mm" we don't know where the number ends. But you're saying that now you have

Pipe-H-1170.

Now see... should I search for "." instead of "mm". Or is it just your carelessness so "." really isn't there?

Or..... whatever......

I just made it my way by the clear input/output you gave me. It's a black box to you anyway.

0 Likes
Message 5 of 8

lmoultonX6YLM
Participant
Participant

Ah ok thanks - i understand a little more now. Great explanation thankyou.

0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

Pipe-HH-1170 use this returns -1170, use (abs so removes - sign.

 

 

;;-------------------=={ Parse Numbers }==--------------------;;`
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)

 

0 Likes
Message 7 of 8

john.uhden
Mentor
Mentor
Accepted solution

Have you tried...

(getlength "Pipe-H-1170")

?

John F. Uhden

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

; error : no function definition <GETLENGTH> ; expected FUNCTION at [eval]

0 Likes