Jump to content

Hatch True Color to layer


Dien nguyen

Recommended Posts

I'm trying to write a lisp to create a layer with color and name from an existing hatch and text, however I can't get the true hatch color to put in the layer color, here is my lisp, showing hatch -color is just the ACI color. How to get true color for hatch-color? And can hatch pick first.

 

(defun C:HN (/ obj hatch-name hatch-color new-layer)
	(setq sset (car (entsel)))

	(setq obj (vlax-ename->vla-object sset))
	(setq hatch-color (vla-get-color obj))

	(setq ent (entsel "Pick text"))
	(setq txt (cdr (assoc 1 (entget (car ent)))))

;	(createlayer test '(100 150 200) "Continuous" aclnwtbylwdefault)	
	(createlayer txt hatch-color "Continuous" aclnwtbylwdefault)

	(command "chprop" sset "" "la" txt  "")
)

(defun createlayer ( name color linetype lineweight / lay tru )
    (setq lay (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) name))
    (if (listp color)
        (progn
            (setq tru (vla-get-truecolor lay))
            (apply 'vla-setrgb (cons tru color))
            (vla-put-truecolor lay tru)
        )
        (vla-put-color lay color)
    )
    (vla-put-linetype lay linetype)
    (vla-put-lineweight lay lineweight)
    lay
)

 

Link to comment
Share on other sites

Have a look at this to create a true colour layer:

 

(createlayer "Layer" '(75 150 225) "Continuous" 0)

 

Noting that colour is a list of RGB variables, so all you need to search out is the conversion from what the hatch colour gives you that

Link to comment
Share on other sites

You can get the hatch colour something like this

 

(defun c:getcolour ( / MyEnt MyColour)
  (setq MyEnt (entget (car (entsel "Select Entity"))))
  (if (= (assoc 420 MyEnt) nil)
    (setq MyColour (cdr (assoc 62 MyEnt)))
    (setq MyColour (cdr (assoc 420 MyEnt)))
  ) ; end if
  MyColour
)

 

then convert thrue colour to rgb

  • Like 1
Link to comment
Share on other sites

An AcCmColor object is independent of the entity (graphical/non-graphical) to which it applies; hence, you can skip the testing for colour type altogether:

 

(defun c:hn ( / e h n x )
    (if
        (and (setq h (car (entsel "\nSelect hatch: ")))
            (progn
                (while
                    (and (setq e (car (entsel "\nSelect text: ")))
                        (not
                            (and
                                (= "TEXT" (cdr (assoc 0 (setq x (entget e)))))
                                (snvalid (setq n (cdr (assoc 1 x))))
                            )
                        )
                    )
                    (princ "\nText not valid for use as a layer name.")
                )
                e
            )
        )
        (vla-put-truecolor
            (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) n)
            (vla-get-truecolor (vlax-ename->vla-object h))
        )
    )
    (princ)
)

 

  • Like 2
Link to comment
Share on other sites

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...