PDA

View Full Version : Beginner LISP help - please


gfreddog
2008-07-30, 06:12 PM
I have an existing LISP that inserts a block with 1 attribute in it and can sequentially number it also:

;WIRE - drops in sequentially numbered WIRE NUMBER blocks
(DEFUN C:WIRE()
(COMMAND "LAYER" "SET" "OUR_Text""")
(setq prefix (getstring "Enter Prefix: (default=none) "))
(setq suffix (getstring "Enter Suffix: (default=none) "))
(setq nmber (getstring "Enter starting number: (default= 1) "))
(if (= nmber "")(setq nmber "1"))
(setq blok (getstring "Enter Block to use(WIRE NUMBER): (default= WIRE NUMBER) "))
(if (= blok "")(setq blok "WIRE NUMBER"))
(setq num (atoi nmber))
(setq p (getpoint "Location: "))
(while
(not (atom p))
(setq txt (strcat prefix (itoa num) suffix))
(setvar "attdia" 0)
(setvar "attreq" 1)
(COMMAND "INSERT" blok p 1 1 0 txt)
(setvar "attdia" 1)
(setvar "attreq" 1)
(setq num (1+ num))
(setq p (getpoint (getvar "lastpoint") "Location: "))
)
(COMMAND)
)


I'd like to use a different block with 2 Attributes.

Attribute 1 would be for a wire type which would stay the same for each insertion of the block during the instance the LISP is run.

Attribute 2 would be the wire number which would function as the it does in the original LISP.

I know I also have to change the block, but I need help with the LISP part.

Any ideas?

Lions60
2008-07-30, 06:55 PM
I believe everything you would need to change i have highlighted in red. I made a new variable for the Wire type attribute called txt2. If this attribute comes before the wire number then it needs to be listed before txt when the insert command is called. I believe this should get you the result needed


;WIRE - drops in sequentially numbered WIRE NUMBER blocks
(DEFUN C:WIRE()
(COMMAND "LAYER" "SET" "OUR_Text""")
(setq prefix (getstring "Enter Prefix: (default=none) "))
(setq suffix (getstring "Enter Suffix: (default=none) "))
(setq nmber (getstring "Enter starting number: (default= 1) "))
(if (= nmber "")(setq nmber "1"))
(setq blok (getstring "Enter Block to use(WIRE NUMBER): (default= WIRE NUMBER) "));; change the default block
(if (= blok "")(setq blok "WIRE NUMBER"));; change name of block here
(setq num (atoi nmber))
(setq p (getpoint "Location: "))
(while
(not (atom p))
(setq txt (strcat prefix (itoa num) suffix)) ;; wire number attribute text
(setq txt2 "add text here");; text for wire type attribute
(setvar "attdia" 0)
(setvar "attreq" 1)
(COMMAND "INSERT" blok p 1 1 0 txt2 txt);; add txt2 after or before txt depending on the order of the attributes
(setvar "attdia" 1)
(setvar "attreq" 1)
(setq num (1+ num))
(setq p (getpoint (getvar "lastpoint") "Location: "))
)
(COMMAND)
)

gfreddog
2008-07-30, 09:49 PM
That was it, just what I needed.

I tweaked it a bit

New Code:


;WIRE - drops in sequentially numbered WIRE NUMBER blocks
(DEFUN C:WIRE()
(COMMAND "LAYER" "SET" "OUR_Text""")
(setq prefix (getstring "Enter Prefix: (default=none) "))
(setq suffix (getstring "Enter Suffix: (default=none) "))
(setq nmber (getstring "Enter starting number: (default= 1) "))
(if (= nmber "")(setq nmber "1"))
(setq cbltype (getstring "Enter Wire Type: (default=none) "))
(setq blok (getstring "Enter Block to use(WIRE): (default= WIRE) "));; change the default block
(if (= blok "")(setq blok "WIRE"));; change name of block here
(setq num (atoi nmber))
(setq p (getpoint "Location: "))
(while
(not (atom p))
(setq txt (strcat prefix (itoa num) suffix)) ;; wire number attribute text
(setq txt2 (strcat cbltype));; text for wire type attribute
(setvar "attdia" 0)
(setvar "attreq" 1)
(COMMAND "INSERT" blok p 1 1 0 txt2 txt);; add txt2 after or before txt depending on the order of the attributes
(setvar "attdia" 1)
(setvar "attreq" 1)
(setq num (1+ num))
(setq p (getpoint (getvar "lastpoint") "Location: "))
)
(COMMAND)
)