Jump to content

Changing a hatch pattern scale, from a solid hatch


CesarA

Recommended Posts

I've read the documentation in the autocad site and to change from solid to other kind of hatch you must mess up 2 dxf codes. 70 is 1 or 0 accordingly to solid or not. 2 is the hatch patern indeed. and finally 41 is the dxf for the scale of the pattern.

 

So I tried to do the following:

 

 

(defun c:efg ( / trama solido e o s x texto tipodepeca z y)
   (if (setq s (ssget "_:L" '((0 . "HATCH"))))
       (repeat (setq i (sslength s))
           (setq e (ssname s (setq i (1- i)))
                 x (entget e)
                 trama (cdr (assoc 2 x))
			  solido (cdr (assoc 70 x))
			 

           )

		(setq z (entmod (subst 0 solido x))) ;;;; change the dxf 70 from 1 (solid) to 0 (not solid)
	
		
			
			(if (= trama "SOLID") 
				
				(progn
					(setq y (entmod (subst '(8 . "est.Trama") (assoc 8 x) z))) ;;;; Changes layer
					
					(setq w (entmod (subst '(2 . "AR-CONC") (assoc 2 x) y))) ;;;;Changes type of hatch
					
					(entmod (subst '(41 . 0.01) (assoc 41 x) w)) ;;;;Changes pattern scale (or shouldn't?)
 			
					
				)
			)
           
       )
   )

   (princ)
)

Basically I change the dxf 70 from 1 to 0 (so that I can enable a not-solid hatch) and then change the dxf 2 to other pattern.

 

The problem is that everything works allright, but the scale pattern doesnt change. (the layer and the hatch name are correct).

 

Does this have to do with the order in which I modify the settings?

Edited by CesarA
Link to comment
Share on other sites

By the way I'm also trying to delete some hatches using

(ssdel x s)

which translantes to (ssdel ename sslist) or something similar. I think the command is correctly written, but he doesnt delete the hatch regardless.

 

Edit: solution for removal:

(command "erase" e "") 

 

The pattern scale problem persists somehow, any hint?

Edited by CesarA
Link to comment
Share on other sites

damn Lee mac, when I've seen you replied I hoped you had a hint on the pattern scale, the deletion is taken care of, the first problem persists tough..

Link to comment
Share on other sites

damn Lee mac, when I've seen you replied I hoped you had a hint on the pattern scale, the deletion is taken care of, the first problem persists tough..

 

Excuse me?

Link to comment
Share on other sites

hmm.. yes? I didn't mean "damn you lee mac", but rather "damn my luck, lee mac" if that's what is bothering you :) I'm more than happy with your help

Link to comment
Share on other sites

I don't believe that you can modify a HATCH entity in this way in order for the pattern to display correctly, as the DXF data for a pattern filled hatch contains separate pattern data which is not present for a solid hatch. Furthermore, the pattern name and pattern type ActiveX properties are read-only, which would indicate that such objects cannot be tranformed into each other.

 

I believe you would instead need to rebuild the HATCH to include this additional data - for this, I would strongly recommend using the ActiveX(COM) methods offered by Visual LISP, as entmake'ing a HATCH entity can be troublesome.

 

Here are some examples of how to create a hatch using Visual LISP:

 

Isometric Hatched Triangle

Offset & Hatch Polylines

Solid Hatch in Visual LISP

Link to comment
Share on other sites

You are probably right.. anyways I checked a dxf list of a hatch and something strange happens

 

 

((-1 . ) (0 . "HATCH") (330 . ) (5 . "5F4761") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "est.Trama") (100 . "AcDbHatch") (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (2 . "AR-CONC") (70 . 0) (71 . 0) (91 . 1) (92 . 3) (72 . 0) (73 . 1) (93 . 4) (10 3891.11 -3551.41 0.0) (10 3890.86 -3551.41 0.0) (10 3890.86 -3551.11 0.0) (10 3891.11 -3551.11 0.0) (97 . 0) (75 . 0) (76 . 1) (52 . 0.0) (41 . 0.01) (77 . 0) (78 . 13) (53 . 0.872665) (43 . 0.0) (44 . 0.0) (45 . 0.071726) (46 . -0.00627521) (79 . 2) (49 . 0.0075) (49 . -0.0825) (53 . 6.19592) (43 . 0.0) (44 . 0.0) (45 . -0.0138751) (46 . 0.0752192) (79 . 2) (49 . 0.006) (49 . -0.066) (53 . 1.75321) (43 . 0.00597717) (44 . -0.000522934) (45 . 0.0578509) (46 . 0.068944) (79 . 2) (49 . 0.00637402) (49 . -0.0701142) (53 . 0.806066) (43 . 0.0) (44 . 0.02) (45 . 0.106724) (46 . -0.0165519) (79 . 2) (49 . 0.01125) (49 . -0.12375) (53 . 1.68661) (43 . 0.00889367) (44 . 0.0186207) (45 . 0.0934662) (46 . 0.0974119) (79 . 2) (49 . 0.00956103) (49 . -0.105171) (53 . 6.12932) (43 . 0.0) (44 . 0.02) (45 . 0.0934662) (46 . 0.0974119) (79 . 2) (49 . 0.009) (49 . -0.099) (53 . 0.366519) (43 . 0.01) (44 . 0.015) (45 . 0.0596907) (46 . -0.0402619) (79 . 2) (49 . 0.0075) (49 . -0.0825) (53 . 5.68977) (43 . 0.01) (44 . 0.015) (45 . 0.0243315) (46 . 0.072515) (79 . 2) (49 . 0.006) (49 . -0.066) (53 . 1.24706) (43 . 0.0149742) (44 . 0.0116448 ) (45 . 0.0840222) (46 . 0.0322531) (79 . 2) (49 . 0.00637402) (49 . -0.0701142) (53 . 0.654498 ) (43 . 0.0) (44 . 0.0) (45 . 0.00121599) (46 . 0.0332894) (79 . 6) (49 . 0.0) (49 . -0.0652) (49 . 0.0) (49 . -0.067) (49 . 0.0) (49 . -0.06625) (53 . 0.1309) (43 . 0.0) (44 . 0.0) (45 . 0.026307) (46 . 0.0394412) (79 . 6) (49 . 0.0) (49 . -0.0382) (49 . 0.0) (49 . -0.0637) (49 . 0.0) (49 . -0.02525) (53 . 5.71595) (43 . -0.0223) (44 . 0.0) (45 . 0.0533822) (46 . -0.00225549) (79 . 6) (49 . 0.0) (49 . -0.025) (49 . 0.0) (49 . -0.078 ) (49 . 0.0) (49 . -0.1035) (53 . 5.54142) (43 . -0.0323) (44 . 0.0) (45 . 0.0583186) (46 . 0.0100105) (79 . 6) (49 . 0.0) (49 . -0.0325) (49 . 0.0) (49 . -0.0518 ) (49 . 0.0) (49 . -0.0735) (98 . 0))

 

A lot of the codes repeat themselves.. shouldn't it be one code group for each parameter? Does anyone knows why this happens?

Link to comment
Share on other sites

A lot of the codes repeat themselves.. shouldn't it be one code group for each parameter? Does anyone knows why this happens?

 

There will be a set of 'pattern' DXF groups for each edge definition for the HATCH entity, so yes, the DXF groups will be repeated (this is similar to how DXF groups 10, 40, 41, 42 & 91 are repeated for each vertex of an LWPOLYLINE).

Link to comment
Share on other sites

Hmm this is interesting, this means i can probably create a similar list beyond the identity and coordinates of the hatch, and that way I'd probably have exactly what I want. Thanks Lee

Link to comment
Share on other sites

This was so easy...

 

(vl-load-com)
(defun c:efg ( / trama e o s x z y w obj patternName)
   (if (setq s (ssget "_:L" '((0 . "HATCH"))))
       (repeat (setq i (sslength s))
           (setq e (ssname s (setq i (1- i)))
                 x (entget e)
			  obj (vlax-ename->vla-object e)
			  patternName (vla-get-patternName obj)
           )
		    (prin1 "allright till here")
			(vla-setpattern obj acHatchPatternTypePreDefined "AR-CONC" )
			(vla-put-PatternScale obj 0.01)
		
       )
   )
   (princ)
)

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