Author Topic: need help with trimming and adding numbers  (Read 2832 times)

0 Members and 1 Guest are viewing this topic.

lispman21

  • Guest
need help with trimming and adding numbers
« on: November 20, 2006, 03:00:51 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 the insertion of a number inside the circle. All help is appreciated.

Here is the code that i have started.
Code: [Select]
(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

I have revised the code some what but it is still not trimming because it does not recognize my variable PNT.

Code: [Select]
(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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: need help with trimming and adding numbers
« Reply #1 on: November 20, 2006, 03:08:21 PM »
Don't have time to write the code, but here is how I would do it.

Pick the line near the end point to insert the circle.
Draw the circle
Move the endpoint of the line by the radius of the circle and the angle of the line
Add text at the center point of the circle.
Put all in a loop with 'entsel' and check 'errno' system variable

Here is how I would write the loop.
Code: [Select]
(setvar "errno" 0)
(while (not (equal (getvar "errno") 52))
 (if (setq Sel (entsel "\n Select line near end point to add circle: "))
  (progn
  )
 )
)

Hope that helps.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

lispman21

  • Guest
Re: need help with trimming and adding numbers
« Reply #2 on: November 20, 2006, 03:32:01 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
Code: [Select]
(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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: need help with trimming and adding numbers
« Reply #3 on: November 20, 2006, 04:04:12 PM »
Ok, here is what you do ...

Select the line
grab the endpoint of the line using the osnap command
create your circle at 4" away from the end of the line using the angle of the selected line.

Code: [Select]
(defun C:BOM( / index )
;initialize our counter
 (setq index 1)
;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)
)


Now to add a number, simply create the text you need there (middle center justified) at the point identified by PT3.

Code: [Select]
(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)
    )
)
)

Enjoy ..

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

scottcd

  • Newt
  • Posts: 52
Re: need help with trimming and adding numbers
« Reply #4 on: November 20, 2006, 05:22:46 PM »
Another way to skin the cat is to insert a circle block with an elevation and just below this have a circular wipeout.
This way the line remains the correct length.

Then add your text as previously suggested.

Cheers

Scott
AutoCAD Dos R9 - 2018 and BricCAD 18.2

T.Willey

  • Needs a day job
  • Posts: 5251
Re: need help with trimming and adding numbers
« Reply #5 on: November 20, 2006, 05:38:51 PM »
Another way to skin the cat is to insert a circle block with an elevation and just below this have a circular wipeout.
This way the line remains the correct length.

Then add your text as previously suggested.

Cheers

Scott
Or just use an attributed circle block.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: need help with trimming and adding numbers
« Reply #6 on: November 21, 2006, 12:47:23 AM »
You may be able to modify this routine.
It is used to select the center, the the lines to have the bubbles added to.
Then CW or CCW & the bubbles are added to the outside points & the lines trimmed.

You will need to adjust the text height & Bubble size.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

lispman21

  • Guest
Re: need help with trimming and adding numbers
« Reply #7 on: November 21, 2006, 08:09:08 AM »
Thanks keith, your code did exactly what i needed it to do.  Now to take it just a step further is there anyway that when the user ends the program and then calls it again in the same drawing that it can distinguish the last number created and start from the point on.  For example if the number 10 was the last created and the user had eneded the program. Then a few minutes later the program was called again the next number should be 11.  Right now the program starts back over at 1.  This might be possible or it might not.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: need help with trimming and adding numbers
« Reply #8 on: November 21, 2006, 08:21:43 AM »
It is possible, but I might suggest that you make it so that you can enter the value as an override instead. That way you can start where you want, back up if needed or skip ahead.
Code: [Select]
(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 bomindex (1+ bomindex))
 )
)

I have not checked the code .. but I believe it to be correct. Just replace the original C:BOM with this one. If tere are soome problems perhaps a kind soul would be willing to look over the code and fix any glaring errors ... I am off to the airport this morning ... flying out to Seattle for some much needed R&R ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

lispman21

  • Guest
Re: need help with trimming and adding numbers
« Reply #9 on: November 21, 2006, 08:31:29 AM »
good point. entering the number to start with might work better.  I haven't checked the code yet but will and will see if it works.

lispman21

  • Guest
Re: need help with trimming and adding numbers
« Reply #10 on: November 21, 2006, 08:39:54 AM »
I have tested your code and at first it didn't work properly.  Because when you enterd the number it would put that number in each circle. But it only needed a minor change to get it working correctly.  Again i thank you for your help.

Changed code

Code: [Select]
(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));; [color=red]At first the variable was "bomindex" and it jsut needed to be "index"[/color]
 )
)
« Last Edit: November 21, 2006, 08:41:06 AM by lispman21 »