PDA

View Full Version : Help with a number tag routine


Lions60
2006-11-20, 07:28 PM
I am trying to write a lisp that will create a circle on the end of a selected line and place a number in sequential order on every line selected. The user will select one line at a time. Currently the program draws a circle with its center point on the end of the selected line and then the program trims the wrong part of the line back to the circle. Also at the code's current state it will not allow the user to keep selecting lines after the first one is done. I have not yet tried to tackle th einsertion of a number inside the circle. All help is appreciated.

Here is the code that i have started.

(defun BOM ()
(setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
(while
(if (> SS1 nil)
(progn
(setq SS1(car(entsel "Select BOM Line: ")))
(setq ent1 (entget SS1))
(setq end (cdr (assoc 11 ent1)))
(command "circle" end "4" "")
(setq ent(entlast))
(command "trim" ent "" SS1 "")
)
)
)
(setvar "CMDECHO" OLDVAR1)
(princ) ; end program
(terpri)
); end convert.lsp

Lions60
2006-11-20, 08:57 PM
Here is a more revised code. The problem i am having right now is that the variable PNT is not being recognized so that the trim command can finish.


(defun BOM ()
(setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
(while
(if (>= SS1 nil)
(progn
(setq SS1(car(entsel "Select BOM Line: ")))
(setq ent1 (entget SS1))
(setq end (cdr (assoc 11 ent1)))
(command "circle" end "4" "")
(setq ent(entlast))
(setq pnt (* end 6))
)
)
(command "trim" ent "F" end pnt "")
)
(setvar "CMDECHO" OLDVAR1)
(princ) ; end program
(terpri)
); end convert.lsp

Lions60
2006-11-20, 09:31 PM
OK, i have gotten the circle to be drawn on the line and the line trimmed back to where it should be. now i jsut need to know how to insert a number in the center of the circle and have it start with 1 and every the user selects it will go up in increments of 1. For example the first line selected will have number one, second line selected will be number 2 so on and so forth.

Updated Code

(defun BOM ()
(setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
(while
(if (>= SS1 nil)
(progn
(setq SS1(car(entsel "Select BOM Line: ")))
(setq ent1 (entget SS1))
(setq end (cdr (assoc 11 ent1)))
(command "circle" end "4" "")
(setq ent(entlast))
)
)
(command "lengthen" "DE" "-4" end "")
)
(setvar "CMDECHO" OLDVAR1)
(princ) ; end program
(terpri)
); end convert.lsp

Lions60
2006-11-21, 02:27 PM
Thanks to some help from the swamp and some code by Keith from the swamp the program works exactly as i want. But there is one thing i would like to change about it. Is there a way to store a variable that has the last number created. and then if the program is called in the same drawing then it will start with that number +1. For example the last number created was 10 and then the user ended the program but wasn't done. So the program is called again and should start with 11 (10+1) at its current state it starts over at 1. Some direction on how this could be done would be appreciated.

most recent code

(defun C:BOM( / index )
;initialize our counter
(setq index 1)
;while we are selecting an object
(while (setq ent (entsel "\n Select BOM Line: "))
;call the BOM routine with the entity and point
(bom ent)
;increment our counter
(setq index (1+ index))
)
)

(defun BOM( myentity )
;grab the name just in case we need it
;and the point selected, snapping to the nearest point on the line
(setq ename (car myentity)
pt1 (osnap (cadr myentity) "_near"))
;now lets get the end of the line closest to where we picked
(setq pt2 (osnap pt1 "_end"))
;get the angle of the line using the points we selected
(setq ang (angle pt1 pt2))
;create a new point 4 units from the end of the line nearest where we selected
(setq pt3 (polar pt2 ang 4))
;create a circle at that point
(entmake
(list
'(0 . "CIRCLE")
'(67 . 0)
'(100 . "AcDbCircle")
(cons 10 pt3)
'(40 . 4.0)
)
)
;call the sub to make the text passing the point and value needed
(mtxt (rtos index 2 0) pt3)
)

(defun mtxt ( mytext mypoint )
(entmake
(list
'(0 . "TEXT")
'(67 . 0)
'(100 . "AcDbText")
(cons 10 mypoint)
'(40 . 3.0)
(cons 1 mytext)
'(50 . 0.0)
'(41 . 1.0)
'(51 . 0.0)
'(71 . 0)
'(72 . 1)
(cons 11 mypoint)
'(73 . 2)
)
)
)

****** EDITED****** Problem fixed again with the help of keith.


(defun C:BOM( )
;initialize our counter
(if (not bomindex)
(setq bomindex 1)
)
;ask for a starting number or use the existing one
(setq index (getint (strcat "\nStarting number <" (rtos bomindex 2 0) ">: ")))
;if the user entered a number
(if index
;set it as the starting number
(setq bomindex index)
)
;while we are selecting an object
(while (setq ent (entsel))
;call the BOM routine with the entity and point
(bom ent)
;increment our counter
(setq index (1+ index))
)
)

(defun BOM( myentity )
;grab the name just in case we need it
;and the point selected, snapping to the nearest point on the line
(setq ename (car myentity)
pt1 (osnap (cadr myentity) "_near"))
;now lets get the end of the line closest to where we picked
(setq pt2 (osnap pt1 "_end"))
;get the angle of the line using the points we selected
(setq ang (angle pt1 pt2))
;create a new point 4 units from the end of the line nearest where we selected
(setq pt3 (polar pt2 ang 4))
;create a circle at that point
(entmake
(list
'(0 . "CIRCLE")
'(67 . 0)
'(100 . "AcDbCircle")
(cons 10 pt3)
'(40 . 4.0)
)
)
;call the sub to make the text passing the point and value needed
(mtxt (rtos index 2 0) pt3)
)

(defun mtxt ( mytext mypoint )
(entmake
(list
'(0 . "TEXT")
'(67 . 0)
'(100 . "AcDbText")
(cons 10 mypoint)
'(40 . 3.0)
(cons 1 mytext)
'(50 . 0.0)
'(41 . 1.0)
'(51 . 0.0)
'(71 . 0)
'(72 . 1)
(cons 11 mypoint)
'(73 . 2)
)
)
)