Author Topic: Block Colour  (Read 1762 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Block Colour
« on: May 19, 2009, 10:16:43 AM »
I am entmake-ing blocks into a drawing, but I can't seem to get the colour of the block correct.

I am using:

Code: [Select]
(defun mkblk  (col pt rot scl)
  (entmake
    (list
      (cons 0 "INSERT")
      (cons 2 "MYBLK")
      (cons 8 "MYLAYER")
   [color=red]   (cons 62 col)     ; <<---- Colour Argument Set.[/color]
      (cons 10 pt)
      (cons 41 scl)
      (cons 42 scl)
      (cons 43 1)
      (cons 50 rot))))

(defun blkdef  ()
  (entmake '((0 . "BLOCK") (10 0.0 0.0 0.0) (2 . "MYBLK") (70 . 0)))
  (entmake '((0 . "LWPOLYLINE")
             (100 . "AcDbEntity")
             (67 . 0)
             (8 . "0")
             (100 . "AcDbPolyline")
             (90 . 3)
             (70 . 0)
             (43 . 0.0)
             (38 . 0.0)
             (39 . 0.0)
             (10 -9.65926 -2.58819)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)
             (10 0.0 0.0)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)
             (10 -9.65926 2.58819)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)))
  (entmake '((0 . "ENDBLK") (8 . "0"))))


But, even with the block colour argument set to say "green", the block still comes in white (the layer colour).

This may be a amateur question  -  but I haven't done this all that much  :oops:

Cheers

Lee
« Last Edit: May 19, 2009, 10:27:58 AM by Lee Mac »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Block Colour
« Reply #1 on: May 19, 2009, 10:33:43 AM »
Since you are creating the polyline within the block on layer zero, the block will inherit the color of the layer it's placed on.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Block Colour
« Reply #2 on: May 19, 2009, 10:46:57 AM »
Ah, OK thanks Ron.

So if I create it on another layer (not "0"), then I can use the colour argument?

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Block Colour
« Reply #3 on: May 19, 2009, 10:53:44 AM »
Also,

if I were to create it on another layer, do I just change the part highlighted in blue, or that in green as well?

Code: [Select]
(defun blkdef  ()
  (entmake '((0 . "BLOCK") (10 0.0 0.0 0.0) (2 . "MYBLK") (70 . 0)))
  (entmake '((0 . "LWPOLYLINE")
             (100 . "AcDbEntity")
             (67 . 0)
             [color=blue](8 . "0")[/color]
             (100 . "AcDbPolyline")
             (90 . 3)
             (70 . 0)
             (43 . 0.0)
             (38 . 0.0)
             (39 . 0.0)
             (10 -9.65926 -2.58819)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)
             (10 0.0 0.0)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)
             (10 -9.65926 2.58819)
             (40 . 0.0)
             (41 . 0.0)
             (42 . 0.0)))
  (entmake '((0 . "ENDBLK") [color=green](8 . "0")[/color])))


ronjonp

  • Needs a day job
  • Posts: 7531
Re: Block Colour
« Reply #4 on: May 19, 2009, 10:58:28 AM »
I'd manage the colors of the sub objects bylayer, but you could add the 62 code to them and hardcode the colors. i believe you only have to change the item in blue.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Block Colour
« Reply #5 on: May 19, 2009, 11:02:44 AM »
Lee,

You might also want to check if the block definition exists, or you'll trash any changes made to the block (if any).

Code: [Select]
(defun blkdef ()
  (if (not (tblsearch "block" "MYBLK"))
    (progn (entmake '((0 . "BLOCK") (10 0.0 0.0 0.0) (2 . "MYBLK") (70 . 0)))
           (entmake '((0 . "LWPOLYLINE")
                      (100 . "AcDbEntity")
                      (67 . 0)
                      (8 . "0")
                      (100 . "AcDbPolyline")
                      (90 . 3)
                      (70 . 0)
                      (43 . 0.0)
                      (38 . 0.0)
                      (39 . 0.0)
                      (10 -9.65926 -2.58819)
                      (40 . 0.0)
                      (41 . 0.0)
                      (42 . 0.0)
                      (10 0.0 0.0)
                      (40 . 0.0)
                      (41 . 0.0)
                      (42 . 0.0)
                      (10 -9.65926 2.58819)
                      (40 . 0.0)
                      (41 . 0.0)
                      (42 . 0.0)
                     )
           )
           (entmake '((0 . "ENDBLK") (8 . "0")))
    )
  )
)
(blkdef)
(mkblk 1 (getpoint) 0 1)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Block Colour
« Reply #6 on: May 19, 2009, 11:28:40 AM »
Yes, I do perform that check - but in the main function, before I call the sub-function to create the defintion.

Thanks for your input Ron, it is much appreciated :)