Jump to content

Explode (replace ?) Solid and Gradient Hatches


Recommended Posts

Posted

More importantly, I need them as dense color matching lines, so replacing them is just fine.

 

Solid is fairly straight forward, just replace with a line style hatch scaled to be nearly solid and match the color. 

 

Tougher is matching the gradient hatching to the varying colors the same, my brain is drawing a blank on if that can be easily done.

 

Main problem is, I need these logos/designs as different vector types and solid and gradient hatches are just left out when importing/converting.

 

This is a fairly simple example. I currently have to redo them in Illustrator, Inkscape etc. and just have to eyeball match the colors.

 

I included a sample .dwg and a PNG of the AI Illustrator file I made of one of the logos.

 

 

Logo 072022.png

Logo 072022.dwg

Posted

Hi SLW

 

This one works OK with LINEAR gradients, but for some reason, it doesn't match exactly the Cylindrical ones.

I tried various interpolation methods, but none seems accurate.

 

;Replace gradient Hatch with lines
;Stefan M - 12.08.2023
(defun c:gradline ( / *error* o ss i e a col1 col2 en l c x1 x2
                   c1 c2 rgb r m
                  )
;;;  (setq *error* (err))
  (setq o (vlax-3d-point 0.0 0.0 0.0))

  (or *spacing* (setq *spacing* 0.1))
  (or *del* (setq *del* "No"))

  (if
    (and
      (setq ss (ssget "_:L" '((0 . "HATCH") (450 . 1) (470 . "LINEAR,CYLINDER,INVCYLINDER"))))
      (progn
        (initget 6)
        (setq *spacing*
          (cond
            ((getdist (strcat "\nSpecify line spacing <" (rtos *spacing*) ">: ")))
            (*spacing*)
          )
        )
      )
      (progn
        (initget "Yes No")
        (setq *del*
          (cond
            ((getkword (strcat "\nDelete original hatch [Yes/No] <" *del* ">: ")))
            (*del*)
          )
        )
      )
    )
    (repeat (setq i (sslength ss))
      (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            a (vla-get-gradientangle e)
            col1 (vla-get-gradientcolor1 e)
            col2 (vla-get-gradientcolor2 e)
      )
      
      (setq en (entlast) l nil)
      
      (setq c (vla-copy e))
      (vla-rotate c o (- a))
      (vla-getboundingbox c 'x1 'x2)
      (setq x1 (car (vlax-safearray->list x1))
            x2 (car (vlax-safearray->list x2))
      )
      (if
        (> (- x2 x1) *spacing*)
        (progn
          (vla-put-HatchObjectType c acHatchObject)
          (vla-setpattern c acHatchPatternTypeUserDefined "_USER")
          (vla-put-patternangle c (/ pi 2))
          (vla-put-patternscale c *spacing*)

          (setq c1 (mapcar '(lambda (p) (vlax-get col1 p)) '(red green blue))
                c2 (mapcar '(lambda (p) (vlax-get col2 p)) '(red green blue))
          )
          
          (if
            (eq (vla-get-gradientname e) "INVCYLINDER")
            (mapcar 'set '(c1 c2) (list c2 c1))
          )
          
          (vla-put-truecolor c col1)

          (command "_explode" (vlax-vla-object->ename c)) 
          (while
            (setq en (entnext en))
            (setq l (cons
                      (list
                        (car (vlax-curve-getstartpoint en))
                        (vlax-ename->vla-object en)
                      )
                      l
                    )
            )
          )

          (foreach x l
            (if
              (eq (vla-get-gradientname e) "LINEAR")
              (setq rgb
                (mapcar
                 '(lambda (c1 c2)
                    (fix (+ 0.5 c1 (/ (* (- c2 c1) (- (car x) x1)) (- x2 x1))))
                  )
                  c1 c2
                )
              )
              (progn
                (setq r (/ (- x2 x1) 2.0)
                      m (/ (+ x2 x1) 2.0)
                      rgb (mapcar
                           '(lambda (c1 c2 / q u)
                              (setq q (abs (- m (car x)))
                                    u (atan (/ (sqrt (- (* r r) (* q q))) q))
                              )
                              (fix (+ 0.5 c1 (/ (* (- c2 c1) 2 u) pi)))
                            )
                            c1 c2
                           )
                )
              )
            )
            
            (vla-setrgb col1 (car rgb) (cadr rgb) (caddr rgb))
            (vla-put-truecolor (cadr x) col1)
            (vla-rotate (cadr x) o a)
          )
          
          (if (eq *del* "Yes") (vla-delete e))
          
        )
      )
    )
  )
;;;  (*error* nil)
  (princ)
)

 

Gradient to Lines.png

  • Like 1
  • Thanks 1
Posted

That looks great to me. I'll check it at work tomorrow.

 

Thanks!!

 

 

Posted (edited)

Hi SLW

 

Here is a better approximation of cylindrical gradients.

Don't ask what those numbers are. Long story.

 

I forgot to tell you, the spherical gradients family is ignored. That would be the challenge...

Also, there is a property of gradient, "Centered", which in your case is always true. If you change it to not centered, the gradient is shifted and that's another story for another day.

 

;Replace gradient Hatch with lines
;Stefan M - 12.08.2023
(defun c:gradline ( / *error* o ss i e a col1 col2 en l c x1 x2
                   c1 c2 rgb r m q
                  )
  ;(setq *error* (err))
  (setq o (vlax-3d-point 0.0 0.0 0.0))

  (or *spacing* (setq *spacing* 0.1))
  (or *del* (setq *del* "No"))

  (if
    (and
      (setq ss (ssget "_:L" '((0 . "HATCH") (450 . 1) (470 . "LINEAR,CYLINDER,INVCYLINDER"))))
      (progn
        (initget 6)
        (setq *spacing*
          (cond
            ((getdist (strcat "\nSpecify line spacing <" (rtos *spacing*) ">: ")))
            (*spacing*)
          )
        )
      )
      (progn
        (initget "Yes No")
        (setq *del*
          (cond
            ((getkword (strcat "\nDelete original hatch [Yes/No] <" *del* ">: ")))
            (*del*)
          )
        )
      )
    )
    (repeat (setq i (sslength ss))
      (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            a (vla-get-gradientangle e)
            col1 (vla-get-gradientcolor1 e)
            col2 (vla-get-gradientcolor2 e)
      )
      
      (setq en (entlast) l nil)
      
      (setq c (vla-copy e))
      (vla-rotate c o (- a))
      (vla-getboundingbox c 'x1 'x2)
      (setq x1 (car (vlax-safearray->list x1))
            x2 (car (vlax-safearray->list x2))
      )
      (if
        (> (- x2 x1) *spacing*)
        (progn
          (vla-put-HatchObjectType c acHatchObject)
          (vla-setpattern c acHatchPatternTypeUserDefined "_USER")
          (vla-put-patternangle c (/ pi 2))
          (vla-put-patternscale c *spacing*)

          (setq c1 (mapcar '(lambda (p) (vlax-get col1 p)) '(red green blue))
                c2 (mapcar '(lambda (p) (vlax-get col2 p)) '(red green blue))
          )
          
          (if
            (eq (vla-get-gradientname e) "INVCYLINDER")
            (mapcar 'set '(c1 c2) (list c2 c1))
          )
          
          (vla-put-truecolor c col1)

          (command "_explode" (vlax-vla-object->ename c)) 
          (while
            (setq en (entnext en))
            (setq l (cons
                      (list
                        (car (vlax-curve-getstartpoint en))
                        (vlax-ename->vla-object en)
                      )
                      l
                    )
            )
          )

          (foreach x l
            (if
              (eq (vla-get-gradientname e) "LINEAR")
              (setq rgb
                (mapcar
                 '(lambda (c1 c2)
                    (fix (+ 0.5 c1 (/ (* (- c2 c1) (- (car x) x1)) (- x2 x1))))
                  )
                  c1 c2
                )
              )
              (progn
                (setq r (/ (- x2 x1) 2.0)
                      m (/ (+ x2 x1) 2.0)
                      q (/ (- m (car x)) r)
                      rgb (mapcar
                           '(lambda (c1 c2)
                              (fix (+ 0.5 c1 (* (- c2 c1) (+ (* 0.2684 (expt q 4)) (* -1.2598 (expt q 2)) 0.9954))))
                            )
                            c1 c2
                           )
                )
              )
            )
            
            (vla-setrgb col1 (car rgb) (cadr rgb) (caddr rgb))
            (vla-put-truecolor (cadr x) col1)
            (vla-rotate (cadr x) o a)
          )
          
          (if (eq *del* "Yes") (vla-delete e))
          
        )
      )
    )
  )
  ;(*error* nil)
  (princ)
)

 

Gradient to Lines.png

Edited by Stefan BMR
edit
  • Like 1
  • Thanks 1
Posted

Thank you very much! 

 

These should do the trick.

Posted

That works very well.

 

I'll check it later on some different logos.

 

The file size is 1/4 the size of the .ai file. Very nice!!

 

 

Posted

problem has already been solved by the comments above, 

but I tried changing png to 24bit bmp in Windows Painter

and using the bmp to polyline routine I wrote before.

(Input 255, 255, 255, 30% in exclusion color, keep true color)

 

2023-08-17124540.thumb.PNG.9f7c54225fd66b8ed0a7d29b89a77d57.PNG

left : true color, right : aci color for ctb

 

In this case, there is already a gradient hatch on the CAD

so there is no need to perform this additional process.

but this routine can be applied to any image and it doesn't matter what shape it is

 

Drawing2.dwg

  • Thanks 1
Posted

This instance was to convert vector files with gradient hatches.

 

I'll try it, I do sometimes need to get image files to vector.

 

Exactly what I had to do for the example here was, I got the logos approved, but what ever company (companies) they were using couldn't use a .dwg or image files, they needed .svg or .ai or similar. The .dwg and several image types all didn't look very accurate when converted to vector in Illustrator, I ended up printing to PDF, importing the PDF into Illustrator and it only needed a little extra work. This example is just a portion of the entire logo. The .svg was too large to email so they used the .ai, AFAIK it worked okay, though.

 

Basically, I get files so they can be used by companies to place logos, etc. on T-shirts, awards and other products (I think one similar to this was also used in a video). 

 

I have no clue why those companies can't just use the image file, nor do I know why the "bought and paid for" logos didn't come to the company as a vector file ( I actually completely made this particular one with instructions from the person wanting it completely in AutoCAD), but alas, I am just the lowly draftsman, they even turned down my request for Illustrator and Photoshop, so I have to send the files home and work on them. I need to learn to tell them no, not my problem. 

 

This particular one, the co-worker in charge of the project was particular in getting the shading spot on, so I had very little leeway in the results, and they needed to look the correct shades and colors when printed on paper. One of the posters they designed, the printing company messed up the colors and shading slightly on the first few.

 

So any AutoCAD solution works for me. I do have a program "Pixel Extractor" by Highflybird, it is useful at times.

 

Thank you!!

 

 

  • Like 1
Posted

These both are working pretty well. 

 

It may be a while before I can test the results of outputs to .ai, .svg, etc. fully, but so far they seem sufficient for my purposes, until someone moves the goal posts on me.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...