TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: duyhung on December 22, 2010, 05:01:57 AM

Title: Help about print hatch in block!
Post by: duyhung on December 22, 2010, 05:01:57 AM
I want to choose all hatch in my drawing and i want set them in colour 250 but I can't choose hatch in block. Please give me a solution to solve problems (one lisp).
I want print all hatch is translucent.
Thanks all.
Sorry I'm not good at English!
Title: Re: Help about print hatch in block!
Post by: pBe on December 22, 2010, 06:16:25 AM
Not sure what you mean by that but...

This will select all hatch (quick and dirty)

Code: [Select]
(ssget "_X" '((0 . "HATCH")))
(command "_chprop" "p" "" "c" "250" "")

You want it printed transluscent (????)  , i suggest you use TrueColor and send your hatch patterns  back (Draw Order)
there are better ways on doing this but.. :roll:



Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 07:33:23 AM
Check this out Buddy.  :-)

Code: [Select]
(defun c:test (/ ss )
 ; Tharwat Dec. 22 . 2010
  (if (setq ss (ssget "_x" '((0 . "HATCH"))))
  ((lambda (i / a e)
   (while
     (setq a (ssname ss (setq i (1+ i))))
       (setq e (entget a))
           (entupd (cdr (assoc -1 (entmod (subst (cons 62 250)(assoc 62 e) e)))))
         )
        )
     -1
    )
       
    (Alert " No Hatches Found")
    )
  (princ)
  )

Tharwat
Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 08:22:47 AM
I want to choose all hatch in my drawing and i want set them in colour 250 but I can't choose hatch in block.

You may mean this .  :-)

Code: [Select]
(defun c:test (/ ss)
 ; Tharwat Dec. 22 . 2010
  (vl-load-com)
  (if (setq ss (nentsel "\n Select Object :"))
    (progn
      (vla-put-color (vlax-ename->vla-object (car ss)) 250)
       (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)
      )
    )
    (princ "Written by Tharwat")
  (princ)
  )

Tharwat
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 08:25:32 AM
Check this out Buddy.  :-)

Code: [Select]
(defun c:test (/ ss )
 ; Tharwat Dec. 22 . 2010
  (if (setq ss (ssget "_x" '((0 . "HATCH"))))
  ((lambda (i / a e)
   (while
     (setq a (ssname ss (setq i (1+ i))))
       (setq e (entget a))
           (entupd (cdr (assoc -1 (entmod (subst (cons 62 250)(assoc 62 e) e)))))
         )
        )
     -1
    )
       
    (Alert " No Hatches Found")
    )
  (princ)
  )

Tharwat

What if DXF 62 isn't present?  :wink:
Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 08:34:21 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Tharwat
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 08:39:22 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Yes, those with a colour set to ByLayer  :-)
Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 08:54:04 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Yes, those with a colour set to ByLayer  :-)

That's related to color No. 256 , so does it mean that it does not have a DXF 62 ? :|
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 08:55:45 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Yes, those with a colour set to ByLayer  :-)

That's related to color No. 256 , so does it mean that it does not have a DXF 62 ? :|

Query it and you shall see  :-)
Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 09:00:53 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Yes, those with a colour set to ByLayer  :-)
That's related to color No. 256 , so does it mean that it does not have a DXF 62 ? :|

Query it and you shall see  :-)

It would be also nice if it is supported with an example.  :-)
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 09:05:10 AM
What if DXF 62 isn't present?  :wink:

Is there any entity which do not have a DXF 62 with it ? : :-)

Yes, those with a colour set to ByLayer  :-)
That's related to color No. 256 , so does it mean that it does not have a DXF 62 ? :|

Query it and you shall see  :-)

It would be also nice if it is supported with an example.  :-)

Create any object, set the colour to ByLayer and use entget or this (http://lee-mac.com/entitylist.html) to query it.
Title: Re: Help about print hatch in block!
Post by: Tharwat on December 22, 2010, 09:14:42 AM
I guess it would give the DXf (67 . 0) as ByLayer .

I faced that before, and sometimes were working and sometimes weren't .
And I had to replace the (cons 62 250) to be (cons 67 250) which kept me nervious with changing colours for entities in general.  :-)

Regards.
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 09:25:23 AM
I guess it would give the DXf (67 . 0) as ByLayer .

I faced that before, and sometimes were working and sometimes weren't .
And I had to replace the (cons 62 250) to be (cons 67 250) which kept me nervious with changing colours for entities in general.  :-)

When set the ByLayer, the DXF 62 code will not be present in the DXF Data list.

How might you go about updating the value should it not be present? Perhaps by adding it to the list?

Say:

Code: [Select]
(if (assoc 62 <entitylist>)
  (subst (cons 62 <NewValue>) (assoc 62 <entitylist>) <entitylist>)
  (append <entitylist> (list (cons 62 <NewValue>)))
)

That would work, but I think there is a better way to approach it, consider this function:

Code: [Select]
(defun c:test ( / ss i )
 
  (if (setq ss (ssget "_:L" '((0 . "HATCH"))))
   
    (repeat (setq i (sslength ss))     
      (_UpdateDXF 62 250 (entget (ssname ss (setq i (1- i)))))
    )   
  )
  (princ)
)

(defun _UpdateDXF ( code value elist )
  (if
    (setq elist
      (entmod (list (assoc -1 elist) (cons code value)))
    )
    (entupd (cdr (assoc -1 elist)))
  )
)
Title: Re: Help about print hatch in block!
Post by: T.Willey on December 22, 2010, 11:27:13 AM
None of those will work on the level the OP is asking.  If you want to change all hatch patterns ( nested also ), then you will have to step through all the block definitions.  Since layouts are defined by blocks, then those that are not thought of as nested will change also.

Code: [Select]
(vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for i blk
        (if (= (vla-get-ObjectName i) "AcDbHatch")
            (vla-put-Color i 250)
        )
    )
)

May need a regen after.
Title: Re: Help about print hatch in block!
Post by: T.Willey on December 22, 2010, 11:28:27 AM
And Lee is correct about the dxf code not being there is the color of an entity is ByLayer.  You will have to put it in the dxf code list like he shows.
Title: Re: Help about print hatch in block!
Post by: Lee Mac on December 22, 2010, 11:34:56 AM
And Lee is correct about the dxf code not being there is the color of an entity is ByLayer.  You will have to put it in the dxf code list like he shows.

Thanks Tim, I completely overlooked the original request with my explanations...  :oops:
Title: Re: Help about print hatch in block!
Post by: duyhung on December 22, 2010, 12:41:11 PM
Thanks all.
Hey I don't know much about advance lisp. I write lisp as beginner, apload and run lisp. Can you give me one complete lisp?
In my country it's 0 hour 37 minutes. When you are working I'm sleep  :-)
Thanks!
Title: Re: Help about print hatch in block!
Post by: T.Willey on December 22, 2010, 12:54:58 PM
Usually we help, we don't give, but since you are new here, here is a complete lisp.

Code: [Select]
(defun c:ChangeHatchColor ()

    (vl-load-com)
    (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
        (vlax-for i blk
            (if (= (vla-get-ObjectName i) "AcDbHatch")
                (vla-put-Color i 250)
            )
        )
    )
    (command "_.regenall")
    (princ)
)
Title: Re: Help about print hatch in block!
Post by: duyhung on December 22, 2010, 01:02:24 PM
Thanks Tim I know and I'll study more about lisp!.
Title: Re: Help about print hatch in block!
Post by: pBe on December 23, 2010, 12:45:54 AM
Hence the 2nd post

plain and simple  :-)
and it works
except the nested part of course: