Author Topic: Draw line after choosing a color  (Read 1569 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Draw line after choosing a color
« on: March 27, 2019, 06:17:32 PM »
It'll draw the line but not set the color. The numbers indicate AutoCAD color numbers.
Sooo...choose the color and draw the line.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Hline (/ hcol)
  2.  (initget 1 "1 56 136 191")
  3.   (setq hcol (getkword "\nEnter COLOR [1/56/136/191]: "))
  4.    (cond
  5.      ((eq hcol "1") 1)
  6.      ((eq hcol "56") 56)
  7.      ((eq hcol "136") 136)
  8.      ((eq hcol "191") 191)
  9.      (T hcol)
  10.       )
  11.    (command "_Line" pause hcol)
  12.    (princ)
  13.  )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Draw line after choosing a color
« Reply #1 on: March 27, 2019, 06:52:59 PM »
Try the code below. You cannot just put the color into the line command and expect it to know what to do with it.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:hline (/ hcol p1 p2)
  2.   ;; RJP » 2019-03-27
  3.   (initget 1 "1 56 136 191")
  4.   (if (setq hcol (getkword "\nEnter COLOR [1/56/136/191]: "))
  5.     (while (and (or p1 (setq p1 (getpoint "\nSpecify start point: ")))
  6.                 (setq p2 (getpoint p1 "\nSpecify next point: "))
  7.            )
  8.       (entmakex (list '(0 . "line") (cons 10 p1) (cons 11 p2) (cons 62 (atoi hcol))))
  9.       (setq p1 p2)
  10.     )
  11.   )
  12.   (princ)
  13. )

Line command:
Quote
Command: LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Specify next point or [Close/Undo]:
Specify next point or [Close/Undo]:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Draw line after choosing a color
« Reply #2 on: March 27, 2019, 08:50:37 PM »
You can use -color prior to line call then dont need to entmake.

Code: [Select]
(defun test (  / oldcol hcol p1 p2)
(initget 1 "1 56 136 191")
  (setq hcol (getkword "\nEnter COLOR [1/56/136/191]: "))
  (setq oldcol (getvar 'cecolor))
  (setvar 'cecolor" (atoi hcol))
  (while (and (or p1 (setq p1 (getpoint "\nSpecify start point: ")))
(setq p2 (getpoint p1 "\nSpecify next point: "))
   )
      (command "line" p1 p2 "")
      (setq p1 p2)
    )
  (setvar 'cecolor oldcol)
  (princ)
)
(test)

My version of initget look at image uses a library multi button lsp
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: Draw line after choosing a color
« Reply #3 on: March 29, 2019, 11:42:05 AM »
Thanks guys, both are right in line with what I was thinking. I need to "remember" last input and do some layer creation stuff, but this gets me closer.

Thanks again.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10