Entmake HATCH entity - Part 2

Regarding yesterday's post....what I failed to cover with any detail was the fact that the example code posted in the CADTutor forum post was strictly for a closed area defined by four lines. Of course that isn't the only area you may need to hatch. Today, I needed to adapt this code to hatch an area defined by an ellipse.

The AutoCAD DXF reference goes into a fair amount of detail, but not necessarily everything you need to know. What I have found over the last few days is the best advice comes from querying an existing entity and studying the return values. For an ellipse, you need to tell AutoCAD the center point of the ellipse, the distance from the center point to the upper quadrant, the ratio of the width to the height, and the angle of the imaginary elliptical arc. Remember, we are hatching an area, not necessarily an entity. The code ends up looking like this:

(entmake
  (list
	   (cons 0 "HATCH")
	   (cons 100 "AcDbEntity")
	   (cons 8 "0")
	   (cons 100 "AcDbHatch")
	   (cons 62 13)
	   (cons 10 cenpt)
	   (cons 210 (list 0.0 0.0 1.0))
	   (cons 2 "SOLID")
	   (cons 70 1)
	   (cons 71 0)
	   (cons 91 1)
	   (cons 92 1)
	   (cons 93 1)
           ; the "3" designates this is an elliptical shape	 
	   (cons 72 3)
           ; center point of ellipse
	   (cons 10 cenpt)   
           ; point of top quad
	   (cons 11 otherpt) 
           ; ratio of width to height
	   (cons 40 0.1)     
           ; start angle
	   (cons 50 0.0)     
           ; end angle (full ellipse)
	   (cons 51 (* pi 2.0))  
           ; counterclockwise flag
	   (cons 73 1)       
	   (cons 97 0)       
	   (cons 75 0)
	   (cons 76 1)
	   (cons 98 1)
	   (cons 10 (list 0.0 0.0 0.0))
	 )
)

If you are hatching using lisp and the slow (command) or (vl-cmdf) functions, you won't believe the speed difference until you see it. Maybe this will help someone else down the road.

 


All content is copyright © CAD Panacea 2008-2010 unless otherwise noted.
All content of CAD Panacea is solely my own personal thoughts and opinions and do not represent my employer or any others.
All comments posted to this blog are the sole responsibility of the person making the comment.

 

Google, as a third party vendor, uses cookies to serve ads on this site. Google's use of their cookies enables it to serve ads to users based on their visit to your sites and other sites on the Internet. You may opt out of the use of these cookies by visiting the Google ad and content network privacy policy.

free hit counters

Powered by Drupal, an open source content management system