Jump to content

Recommended Posts

Posted

I have a lisp file the inserts lot numbers in ascending order. My problem is that this lisp is not applicable in numbering sublots, because for sublots, lot numbering will be alphabetical. For example, A mother lot has a lot number of 234 and is divided into two lots. The first lot number would be "234-A" and the second would be "234-B". Can someone help me with this? Just a newbie in lisp programming. Thanks in advance!

lot number.lsp

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • makimaki

    11

  • pBe

    7

  • BIGAL

    4

  • Tharwat

    2

Top Posters In This Topic

Posted

A couple of things your while you can make it (while (setq p1 (getpoint "\nText location: ")) this will exit if you press enter .

 

not sure why done this way

(command "text"
              "J"
              "MC"
              (setq p p1)
              (setq p "")
              (setq p "")
              (setq p n1)
           )

(command "text" "J" "MC" p1 "" "" n) ; my version

;sublot do a press <CR> for next lot any key for a [b]sub lot[/b] this would drop to A and keep going till you do a sub lot again then reset to A.

; maybe do defuns bit easier to do if's 

 

Need to have a think some one else may post an answer straight away.

Posted

Thanks for the help BIGAL. I'll try it. :)

Posted (edited)

(defun c:lotn ( / _text [color="blue"]_NextString [/color]mode opt str p1 p2 n1 str  a)
;;;		pBe 16 Mar2015		;;;
(defun _text (str pt)
 (entmakex (list (cons 0 "TEXT")
	  (cons 10 pt)
	  (cons 11 pt)
	  (cons 40 (getvar 'textsize))
	  '(72 . 4)
	  '(73 . 2)
	  (cons 1 (strcat "LOT " str))
    )
 )
)
[color="blue"](defun _NextString (n m)
 (strcat n
  (if m
    (strcat "-" (setq a (chr (1+ (ascii a)))))
    ""
  )
 )
)[/color]
[color="blue"](setq mode '(( "S" "Sub-lot mode")( "L" "Lot mode")))
 	(initget "L S")
(setq opt (cond ( (getkword "\nChoose [Lot/Sub lot] <Lot>: ") ) ( "L" )))
 	(setq mode (if (setq l (eq opt "L")) mode (reverse mode)))
 	(princ (strcat "\n<<< " (cadr (assoc opt Mode)) " >>>"))[/color]
(setq a	  "@"
      n1  (getint "\nEnter starting lot number: ")
      str (itoa n1))
  (setq  p1 (getpoint "\nText location: "))
(_text [color="blue"](_NextString (itoa n1) (if l nil T))[/color] p1)
  (while
     (progn
       [color="blue"](princ (strcat "\n<<< " (cadadr mode) " >>>"))[/color]
       (initget [color="blue"](caar mode)[/color])
       (setq
	 p2 (getpoint
	      p1
	      (strcat
		"\nPick next location/Press \""
		[color="blue"](caar mode)[/color]
		 "\" for " [color="blue"](cadar mode) [/color]" : "
	      )
	    )
       )
     )
      (cond
	((listp p2)
	 (if (eq [color="blue"](caar mode)[/color] "L")
	     (_text (setq str [color="blue"](_NextString (itoa n1) T)[/color]) p2)
	     (_text[color="blue"] (_NextString (itoa (setq n1 (1+ n1)))[/color] nil) p2)
	   )
	   (setq p1 p2)
	 )
	 ((eq p2 "S")
	   (setq str [color="blue"](_NextString (itoa n1) T)[/color])
	  [color="blue"] (setq mode (reverse mode))[/color]
	 )
	 ((eq p2 [color="blue"]"L"[/color])
	   (setq [color="blue"]mode (reverse mode)[/color] a  "@"))
	 )
	)
 (princ)
)

 

"L" for Lot mode

"S" for Sub-lot mode

 

command: Lotn
Choose [Lot/Sub lot] <Lot>: [color="red"][b]S[/b][/color]
<<< Sub-lot mode >>>
Enter starting lot number: [b][color="red"]12[/color][/b]
Text location:
<<< Sub-lot mode >>>
Pick next location/Press "L" for Lot mode :
<<< Sub-lot mode >>>
Pick next location/Press "L" for Lot mode :  [b][color="red"]L[/color][/b]
<<< Lot mode >>>
Pick next location/Press "S" for Sub-lot mode : 

Edited by pBe
remove cmdecho
Posted

pBe

 

What is the use of the system variable cmdecho in your routine ?

If a user went with the option S and exceeded Y char while keep on picking points , they would face strange symbols face to face instead of alphabetical chars :shock: .

 

Good idea by the way . :thumbsup:

Posted
What is the use of the system variable cmdecho in your routine ?

 

(setq scmde (getvar "cmdecho"))

From the OP, no idea why either :D

 

If a user went with the option S and exceeded Y char while keep on picking points , they would face strange symbols face to face instead of alphabetical chars :shock: .

 

Thought about that too. I was counting on the sub-lots would not exceed the 26 letters of the alphabet. but we could modify the code to consider that scenario in the future if it comes to that. Good catch btw.

 

pBe

Good idea by the way . :thumbsup:

 

Thank you tharwat :)

Posted

c:lotn

simple but nice idea pBE :thumbsup:

my $0.02 by grread

mouse left for mother

right click for children ,can save one step 8)

Posted
simple but nice idea pBE :thumbsup:

 

Thank you for that hanhphuc :)

 

...grread...

 

I thought about that too. To preserved running osnaps and an easy to understand coding for the benefit of the OP is why i kept it simple.

Posted

Sorry guys 52 characters in alphabet :o but lower case would be confusing.

Posted

THank you so much pBe and all you guys. :)

Posted

pBe, about the code you posted, i've been trying to edit it but i failed, because what i want is that before you will pick the insertion point of the text, you must choose first if it is only a lot number (1,2,3) or sub lot(1-A, 1-B, etc).

lastly, how to insert the word "LOT" before the number/as prefix? because i would like my final output to be "LOT 1" for lot numbers and "LOT 1-A" for sublots.

Thank you so much sir pBe. I really need this. :)

Posted

Thank you so much sir pBe.

 

You are Welcome, Glad i could help.:)

 

...because what i want is that before you will pick the insertion point of the text, you must choose first if it is only a lot number (1,2,3) or sub lot(1-A, 1-B, etc)

 

That is exactly how the routine is setup now.

 

Pick next location/Press "S" for sub-lot: [b]S[/b] 

 

Or are you meaning before the very FIRST point?

 

Sure Pbe wont mind change this (cons 1 (strcat "LOT " str))

 

No worries BIGAL, Not at all :)

 

Cheers

 

pBe

Posted

yes sir pBe, before the very first point. i dont know how to re arrange the your code. :(

Also I don't know where to insert or put sir BIGAL's suggestion about inserting the word "LOT". Thank you so much again. :)

Posted
yes sir pBe, before the very first point. i dont know how to re arrange the your code. :(

Also I don't know where to insert or put sir BIGAL's suggestion about inserting the word "LOT". Thank you so much again. :)

 

Yes its easy to do that, but will that be it or there'll be more addition to this? and what of the prefix, will it be always "LOT" ? just make sure before we do any mod on the code.

Posted

Yes sir pBe. The prefix is always the word "LOT". so the output would be like "LOT 123" (for Lot numbers) or "LOT 123-A" (for Sub Lot Numbers). Again, before inserting the first number, the lisp routine will allow the user to select first if it will be a lot number or for sub lot number. Thanks again sir pBe. More power! :)

Posted

re change this

 

old code
(cons 1 str)
new code
(cons 1 (strcat "LOT " str))

Posted

Thank you sir BIGAL. much appreciated. :)

Posted
..The prefix is always the word "LOT"....Again, before inserting the first number,....

 

Updated Code at Post#4

 

Thanks again sir pBe. More power! :)

 

You are welcome. :)

Posted

That code at post #4 was perfect mr pBe, or shall I call you master pBe. you're my hero. A million thanks master and all you guys (BIGAL, tharwat, hanhphuc) who posted, and shared your thoughts with regards to my problem. :D

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