Jump to content

Recommended Posts

Posted

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
)

 

Posted

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

Posted

With specifies true color i can create layer with layer, but i want get hatch color to match layer color

Posted

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
Posted

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
Posted

Thanks Lee - I learn something every time you post!

Posted

Thank Lee Mac, I'm happy to get your feedback, it works great, I used many of your lisp. 

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