Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a block. circle hatched with solid pattern

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Mesut_Akcan
831 Views, 13 Replies

Create a block. circle hatched with solid pattern

My aim was to make a block consisting of a circle with a radius of 1 hatched with SOLID inside.
When I delete the hatch codes, the block consisting of the circle is formed, but there is a problem with the hatch codes, the block is not formed with the hatch codes.

 

(if (not (tblsearch "BLOCK" "NKT"))
	(progn
		(entmake ; block
			(list
				(cons 0 "BLOCK")
				(cons 100 "AcDbEntity")
				(cons 67 0) ; model space
				;(cons 8 "0") ; layer 0
				(cons 100 "AcDbBlockReference")
				(cons 2 "NKT") ; Blok name
				(cons 10 '(0 0 0)) ; base point
				(cons 70 0)
			)
		)
		(entmake ; circle
			(list
				(cons 0 "CIRCLE")
				(cons 100 "AcDbEntity")
				(cons 10 '(0.0 0.0 0.0)) ; center point
				(cons 67 0)
				(cons 40 1) ; radius
			)
		)
		(entmake ; hatch
			(list
				(cons 0 "HATCH")
				(cons 100 "AcDbHatch")
				(cons 100 "AcDbEntity")
				(cons 2 "SOLID") 
				(cons 10 '(0.0 0.0 0.0)) ; center point
				(cons 40 1)
				(cons 70 1) ;solid fill
				(cons 76 1)
				(cons 210 '(0.0 0.0 1.0))
				(cons 71 1)
				(cons 67 0)
			)
		)
		(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	)
)
Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
13 REPLIES 13
Message 2 of 14

Wouldn't this be simpler than hatching (with FILLMODE set to 1)?

 

(defun c:round_stiker ( / pt rad)
  (while (setq pt (getpoint "\nCentral point of round sticker?: "))
    (initget 7)
    (setq
      rad (getdist pt "\nRadius of round sticker?: ")
      pt (trans pt 1 (trans '(0 0 1) 1 0 T))
    )
    (entmake
      (list
        '(0 . "LWPOLYLINE")
        '(100 . "AcDbEntity")
        (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
        (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
        (cons 8 (getvar "CLAYER"))
        '(100 . "AcDbPolyline")
        '(90 . 2)
        '(70 . 1)
        (cons 43 rad)
        (cons 38 (getvar "ELEVATION"))
        (cons 39 (getvar "THICKNESS"))
        '(39 . 0.0)
        (cons 10 (list (+ (car pt) (* 0.5 rad)) (cadr pt)))
        (cons 40 rad)
        (cons 41 rad)
        '(42 . 1.0)
        '(91 . 0)
        (cons 10 (list (- (car pt) (* 0.5 rad)) (cadr pt)))
        (cons 40 rad)
        (cons 41 rad)
        '(42 . 1.0)
        '(91 . 0)
        (cons 210 (trans '(0 0 1) 1 0 T))
      )
    )
  )
  (prin1)
)
Message 3 of 14
komondormrex
in reply to: Mesut_Akcan

check vla* version

(defun c:circle_1_solid (/ block_to_add_name block_nkt circle_object hatch_object hatch_color hatch_layer)
  	(setq block_to_add_name "NKT")
	(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) block_to_add_name)))
	  (progn
	  	(setq block_nkt (vla-add (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point '(0 0)) block_to_add_name)
		      circle_object (vla-addcircle block_nkt
						   (vlax-3d-point '(0 0))
						   1
				    )
		      hatch_object (vla-addhatch block_nkt
						 achatchpatterntypepredefined
						 "SOLID"
						 :vlax-false
						 achatchobject
				   )
		      hatch_color 1
		      hatch_layer "Hatch_Layer"
		)
		(vlax-safearray-put-element (setq outer_loop (vlax-make-safearray vlax-vbobject '(0 . 0))) 0 circle_object)
		(vla-appendouterloop hatch_object outer_loop)
		(vla-put-color hatch_object hatch_color)
		(entmod (subst (cons 8 hatch_layer) (assoc 8 (entget (vlax-vla-object->ename hatch_object))) (entget (vlax-vla-object->ename hatch_object))))
	  	(vla-put-layer circle_object hatch_layer)
	  	(vla-put-color circle_object hatch_color)
	    	(princ (strcat "\nBlock \"" block_to_add_name "\" was created in this dwg"))
    	 )
	 (princ (strcat "\nBlock \"" block_to_add_name "\" already exists in this dwg"))
	)
	(princ)
)
Message 4 of 14

thanks @CADaSchtroumpf 

your alternative method is simpler and easier, but it's not what I wanted.

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
Message 5 of 14
Mesut_Akcan
in reply to: komondormrex

Thanks @komondormrex 

the codes in the answer you gave do the job I want, but I wonder why the codes I wrote do not do the same job.

can the codes I wrote be corrected?

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
Message 6 of 14
paullimapa
in reply to: Mesut_Akcan

This thread may provide some insight on what you’re trying to do

https://www.cadtutor.net/forum/topic/33743-entmake-of-a-hatch/


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 14
Mesut_Akcan
in reply to: Mesut_Akcan

I found a solution like this. it worked. the block I wanted was formed.
I drew a circle with r=1 at coordinate 0,0 in autocad drawing area and filled it with hatch. with SOLID pattern.
I have listed all the properties of the scanned object with this code:

(entget (car(entsel)))

I added all properties in this list to entmake.
final version of the code:

 

(if (not (tblsearch "BLOCK" "NKT")) 
(progn
	(entmake 
		(list
		(cons 0 "BLOCK") 
		(cons 100 "AcDbEntity") 
		(cons 67 0) 
		;(cons 8 "0") 
		(cons 100 "AcDbBlockReference")
		(cons 2 "NKT") 
		(cons 10 '(0 0 0)) 
		(cons 70 0)
		)
		)
	(entmake 
	(list
	(cons 0 "CIRCLE")
	(cons 100 "AcDbEntity")
	(cons 10 '(0.0 0.0 0.0)) 
	(cons 67 0)
	(cons 40 1) 
	)
	)
	(entmake 
	(list
	'(0 . "HATCH") 
	;(330 . <Entity name: 1cdb71ae9f0>) 
	;(5 . "2FD") 
	'(100 . "AcDbEntity") 
	'(67 . 0) 
	'(410 . "Model") 
	'(8 . "0") 
	'(100 . "AcDbHatch") 
	'(10 0.0 0.0 0.0) 
	'(210 0.0 0.0 1.0) 
	'(2 . "SOLID") 
	'(70 . 1) 
	'(71 . 0) 
	'(91 . 1) 
	'(92 . 7) 
	'(72 . 1) 
	'(73 . 1) 
	'(93 . 2) 
	'(10 1.0 0.0 0.0) 
	'(42 . 1.0) 
	'(10 -1.0 0.0 0.0) 
	'(42 . 1.0) 
	'(97 . 0) 
	'(75 . 1) 
	'(76 . 1) 
	'(47 . 0.0564485) 
	'(98 . 1) 
	'(10 0.0 0.0 0.0) 
	'(450 . 0) 
	'(451 . 0) 
	'(460 . 0.0) 
	'(461 . 0.0) 
	'(452 . 0) 
	'(462 . 1.0) 
	'(453 . 2) 
	'(463 . 0.0) 
	'(63 . 5) 
	'(421 . 255) 
	'(463 . 1.0) 
	'(63 . 2) 
	'(421 . 16776960) 
	'(470 . "LINEAR")
	)		   
	)
	(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	)
)

 

 

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
Message 8 of 14

Without (vla ...) only (entmake you can try this, two soluce:

(if (not (tblsearch "BLOCK" "NKT"))
	(progn
		(entmake
			'(
				(0 . "BLOCK")
				(100 . "AcDbEntity")
				(67 . 0)
				(8 . "0")
				(100 . "AcDbBlockBegin")
				(70 . 0)
				(10 0.0 0.0 0.0)
				(2 . "NKT")
			)
		)
		(entmake
			'(
				(0 . "CIRCLE")
				(100 . "AcDbEntity")
				(67 . 0)
				(410 . "Model")
				(8 . "0")
				(62 . 0)
				(6 . "ByBlock")
				(370 . -2)
				(100 . "AcDbCircle")
				(10 0.0 0.0 0.0)
				(40 . 1.0)
				(210 0.0 0.0 1.0)
			)
		)
		(entmake
			'(
				(0 . "HATCH")
				(100 . "AcDbEntity")
				(67 . 0)
				(410 . "Model")
				(8 . "0")
				(62 . 0)
				(440 . 16777216)
				(100 . "AcDbHatch")
				(10 0.0 0.0 0.0)
				(210 0.0 0.0 1.0)
				(2 . "SOLID")
				(70 . 1)
				(71 . 0)
				(91 . 1)
				(92 . 1)
				(93 . 1)
				(72 . 2)
				(10 0.0 0.0 0.0)
				(40 . 1.0)
				(50 . 0.0)
				(51 . 6.28319)
				(73 . 1)
				(97 . 0)
				(75 . 1)
				(76 . 1)
				(98 . 1)
				(10 0.0 0.0 0.0)
				(450 . 0)
				(451 . 0)
				(460 . 0.0)
				(461 . 0.0)
				(452 . 0)
				(462 . 0.0)
				(453 . 2)
				(463 . 0.0)
				(63 . 5)
				(421 . 255)
				(463 . 1.0)
				(63 . 2)
				(421 . 16776960)
				(470 . "LINEAR")
			)
		)
		(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	)
)

Or with polyline

(if (not (tblsearch "BLOCK" "NKT"))
	(progn
		(entmake
			'(
				(0 . "BLOCK")
				(100 . "AcDbEntity")
				(67 . 0)
				(8 . "0")
				(100 . "AcDbBlockBegin")
				(70 . 0)
				(10 0.0 0.0 0.0)
				(2 . "NKT")
			)
		)
		(entmake
			'(
				(0 . "CIRCLE")
				(100 . "AcDbEntity")
				(67 . 0)
				(410 . "Model")
				(8 . "0")
				(62 . 0)
				(6 . "ByBlock")
				(370 . -2)
				(100 . "AcDbCircle")
				(10 0.0 0.0 0.0)
				(40 . 1.0)
				(210 0.0 0.0 1.0)
			)
		)
		(entmake
			'(
				(0 . "LWPOLYLINE")
				(100 . "AcDbEntity")
				(67 . 0)
				(410 . "Model")
				(8 . "0")
				(62 . 0)
				(6 . "Continuous")
				(370 . -2)
				(100 . "AcDbPolyline")
				(90 . 2)
				(70 . 1)
				(43 . 1.0)
				(38 . 0.0)
				(39 . 0.0)
				(10 0.5 0.0)
				(40 . 1.0)
				(41 . 1.0)
				(42 . 1.0)
				(91 . 0)
				(10 -0.5 0.0)
				(40 . 1.0)
				(41 . 1.0)
				(42 . 1.0)
				(91 . 0)
				(210 0.0 0.0 1.0)
			)
		)
		(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	)
)
Message 9 of 14
Kent1Cooper
in reply to: Mesut_Akcan

If the goal is to work with (entmake), then fine.  If it's just to make the Block, the (entmake) approach is obviously hugely complicated.  Is there any reason not to just do something like one of these?

(defun C:DotR1H ()
  (command
    "_.circle" "non" (getvar 'viewctr) 1
    "_.hatch" "Solid" "_last" ""
    "_.block" "NKT-H" "_non" (getvar 'viewctr) "_last" "_previous" ""
  )
  (prin1)
)

(defun C:DotR1D ()
  (command
    "_.donut" 0 2 "_non" (getvar 'viewctr) ""
    "_.block" "NKT-D" "_non" (getvar 'viewctr) "_last" ""
  )
  (prin1)
)

I used differentiated Block names to distinguish between them.  The first is as described [and could probably have the Circle deleted], the second is a little simpler and should be indistinguishable in use, and I expect uses a little less memory.

Kent Cooper, AIA
Message 10 of 14
Mesut_Akcan
in reply to: Mesut_Akcan

Performing operations with the "command" function may be a practical solution for beginners, but sometimes problems may occur when performing operations with the "command" function.
for example;
osnap problems,
Different autocad command parameters in different autocad versions. etc.

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
Message 11 of 14
Kent1Cooper
in reply to: Mesut_Akcan


@Mesut_Akcan wrote:

Performing operations with the "command" function may be a practical solution for beginners, but sometimes problems may occur when performing operations with the "command" function.
for example;
osnap problems,
Different autocad command parameters in different autocad versions. etc.


Yes, but as you discovered, complications may also arise when performing operations with the (entmake) function ["how many of the DXF code entries do I really need to include?" being one of the big ones].  Osnap problems are easily controlled in (command) functions [as is done in my suggestions].  Certain parameters may change, but usually they involve added options, and spelling out option names as I typically do avoids problems with those.  I have never yet had such changes affect routines that I have been using for decades.

 

But by all means go ahead with (entmake), if it's worth the need for several times as much code to do it that way.

Kent Cooper, AIA
Message 12 of 14

To avoid struggling with (entmake), I draw what I want to achieve then I use this little code which returns me the list which I just have to copy and paste into the code and make some adjustments if desired, for example example (cons code variable).
This way I can be sure not to forget any code or not provide good syntax.
For the block I use this syntax (entget (tblobjname 'BLOCK' 'NKT'))
Besides I don't get (100 . 'AcDbBlockReference') like you, but (100 . 'AcDbBlockBegin')

I would add that (entmake) also avoids worrying about the current UCS.

 

(defun c:list_for_entmake ( / dxf_cod lremov)
	(setq dxf_cod (entget (car (entsel))) lremov nil)
	(foreach n dxf_cod (if (member (car n) '(5 330 -1)) (setq lremov (cons (car n) lremov))))
	(foreach m lremov
		(setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
	)
	(foreach n dxf_cod
		(print n)
	)
	(prin1)
)
Message 13 of 14


@CADaSchtroumpf wrote:

.... I draw what I want to achieve then I use this little code which returns me the list which I just have to copy and paste into the code ....


The approach you describe ends up using sometimes many more entries than you need to make something.  For a LINE, for example, it's enough to include only the DXF 0, 10, and 11 entries  -- if you're willing to go with current conditions for the rest, you don't need to include anything for 330 and the couple of 100's [entity stuff], 8 [Layer], 67 & 410 [space], or 210 [extrusion direction].  I expect that some of the (entmake) ingredients in this topic could be dispensed with, without making any difference to the result, and some of the long code could be shortened.

 

And sometimes it's surprising what's needed.  A recent example for me:  I had a reason to use [in this case] (entmakex) to make a Polyline, which involved the "basic" ingredients as an initial list, to which was repeatedly (append)ed a changing set of 10 entries for vertices, and a changing number of them.  I thought I should dispense with the 90 entry for the number of vertices, since it couldn't be known in the basics list, when the (append)ing of the vertices hadn't happened yet.  I assumed it would establish that from the completed list in making the Polyline, just as it establishes things like the Layer if that's not specified.  But no -- an entry for that is required, even if it turns out to be different in the end result.  Since the most common situation was likely to be 3 vertices, I put in (90 . 3), and that allows the Polyline to be created, even when it is wrong with some other number of vertices (append)ed.  Somehow the (entmakex) list can be self-contradictory, but still work.

Kent Cooper, AIA
Message 14 of 14

@Kent1Cooper 

I somewhat agree with you.
But an experiment (which is a bit old) where I used an entmake to construct an entity. The reduced list was correct but the entity was not built. (I no longer remember the type of entity I was trying to create, but I remember it was a somewhat complex entity)
I tumbled on this problem, I didn't understand.
By groping I added the 100 codes to my list and the entity was built.
To avoid this setback which caused me to lose hair, I have since put in all the codes.
Although this makes the code long and somewhat undrinkable, I prefer this process which I think has very little influence on the speed of code execution.

So if you ever encounter this problem, think about code 100.🤔

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report