Jump to content

Recommended Posts

Posted

Hello, is there any way to create  or add hatch during block creation with entmake, I've tried some ides but none work so any help is appreciated 

Posted

Hi @Tomislav
The answer to your question seems so obvious that it raises questions: you should elaborate a little more on the explanation.

Posted

here is the beginning of block creation, and I want to create hatch inside that circle to be part of block, but block simply refuses to be made when trying to create hatch inside...

everything works fine without hatch

 

 (entmake
      (list
	(cons 0 "BLOCK")
	(cons 2 "9102_DETALJNA_TOCKA")
	(cons 70 2)
	(cons 10 '(0.0 0.0 0.0))
      ) ;_ _list
    ) ;_ _entmake
    (entmake
      (list
	(cons 0 "POINT")
	(cons 8 "0")
	(cons 10 '(0.0 0.0 0.0))
      ) ;_ _list
      ) ;_ _entmake
    (entmake
      (list
	(cons 0 "CIRCLE")
	(cons 8 "0")
	(cons 10 '(0.0 0.0 0.0))
	(cons 40 r)
      ) ;_ _list
    )




;;;  ;; Step 3: Create the hatch inside the block definition
;;; (entmake '((0 . "HATCH")
;;;	    (100 . "AcDbEntity")
;;;	    (100 . "AcDbHatch")
;;;	    (10 0.0 0.0 0.0)		; Hatch origin
;;;	    (70 . 1)			; Associative
;;;	    (71 . 0)			; Hatch style (Normal)
;;;	    (91 . 1)			; Number of loops
;;;	    (92 . 2)			; Boundary path type (Polyline)
;;;	    (93 . 4)			; Number of polyline vertices
;;;	    (72 . 1)
;;;	    (73 . 1)
;;;	    (10 1.0 0.0)
;;;	    (72 . 1)
;;;	    (73 . 1)
;;;	    (10 0.0 1.0)
;;;	    (72 . 1)
;;;	    (73 . 1)
;;;	    (10 -1.0 0.0)
;;;	    (72 . 1)
;;;	    (73 . 1)
;;;	    (10 0.0 -1.0)
;;;	    (97 . 0)			; No additional boundary objects
;;;	    (75 . 0)			; Predefined hatch
;;;	    (76 . 1)			; Solid hatch
;;;	    (52 . 0.0)			; Hatch angle
;;;	    (41 . 1.0)			; Hatch scale
;;;	    (77 . 0)			; No double hatch
;;;	    (78 . 1)
;;;	    (2 . "SOLID")
;;;	   )
;;; )					; Pattern type & name

 

 

Posted

If you get the reference of a block that contains a 'hatch' with '(tblsearch "block"...)' and apply 'entget' to it, you will see that what is shown to you is not the reference of the block but of the 'hatch' and, associated within it, with code 330, the reference of the block.

Posted

I don't understand what are u trying to tell me...

Posted (edited)

A couple of ways to do this:

Create the block without the hatch, bedit it and in the block editor add the hatch. Use entmakex to create the block so that you have the block entity name to go into. This is slow though, opens up the block editor on the screen so also gives screen changes. This uses pure entmake.

 

A more efficient way is to use vla-addhatch - it is all online with the key to this method being you need to add (vla-evaluate MyHatch) at the end of the hatch definition (where MyHatch is your hatch definition). It doesn't use entmake as such but things like the outlines, hole, hatch patterns etc. can all be done with entmake. This method doesn't open the block editor and is a lot quicker.

 

 

 

-EDIT-

Link wasn't a goo example

 

 

Edited by Steven P
  • Like 1
Posted
  On 3/26/2025 at 12:29 PM, Tomislav said:

I don't understand what are u trying to tell me...

Expand  

 

'Hatch' isn't defined in the block definition, but the hatch references the block it is contained in (I think) - the opposite to what you'd expect.

  • Agree 1
Posted

This might be a better link from Tharwat as an exampl to work through

 

 

Posted

thank you, I've heard of something with bedit but didn't want that way with opening editor on screen, so will investigate vla_addhatch, although that seems above my programming capabilities 

  On 3/26/2025 at 12:39 PM, Steven P said:

 

'Hatch' isn't defined in the block definition, but the hatch references the block it is contained in (I think) - the opposite to what you'd expect.

Expand  

that is really weird 

Posted

Try this, a mash up from the 2 links above.

 

 

;;https://www.cadtutor.net/forum/topic/54640-lisp-to-add-a-circle-and-solid-hatch-to-a-block/
(defun c:Test (/ o _add_circle_+_solid)
;;Tharwat 19.11.2014;;
;;SUB ROUTINES
  (defun _AddPolyline ( spc / )
  ;;edited from:
  ;;https://help.autodesk.com/view/OARX/2022/ENU/?guid=GUID-ED02917C-D1D6-46B8-95C6-736163C31362
  ;; Define the 2D polyline points
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 14)))
    (vlax-safearray-fill points '(1 1 0  ;; Point List for polyline - straight vertices only here
                                  1 2 0
                                  2 2 0
                                  2 1 0
                                  1 1 0 ;; Closed polyline
                                 )
    )

    ;; Create a lightweight Polyline object in block
    (setq plineObj (vla-AddPolyline spc points))
    (setq h (vla-addhatch spc acHatchPatternTypePredefined "SOLID" :vlax-true )) ;; hatch style
    (vlax-invoke h 'AppendOuterLoop (list plineObj))
    (vlax-invoke h 'Evaluate)
  ) ; end defun add polyline

  (defun _add_circle_+_solid (spc pnt rad / c h) ;; spc = Block definition, pnt = Circle insertion point,rad = Radius of Circle
    (if (and (setq c (vla-addcircle spc (vlax-3d-point pnt) rad))
             (setq h (vla-addhatch spc acHatchPatternTypePredefined "SOLID" :vlax-true ))
        ) ; end and
      (progn
        (vlax-invoke h 'AppendOuterLoop (list c))
        (vlax-invoke h 'Evaluate)
      ) ; end progn
    )  ; end if
  ) ; end defun subfunction
;; END SUBROUTINES

  (vl-load-com)
  (princ "\n Pick a singLe Block to add Hatch :")
  (if (setq o (ssget "_+.:S:E:L" '((0 . "INSERT"))))
    (progn
      (_add_circle_+_solid
        (vla-item (vla-get-blocks (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ) (cdr (assoc 2 (entget (ssname o 0)))) ) ;; spc
        '(0. 0. 0.) ;; pnt
        1.0 ;; rad
      )
(_addPolyLine (vla-item (vla-get-blocks (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ) (cdr (assoc 2 (entget (ssname o 0)))) ) )
      (vla-regen doc acallviewports) ;; not sure if needed here or at end
    ) ; END PROGN
  ) ; END IF
  (princ)
)

 

Posted

i did this when defining block and it adds circle and hatch , but the when inserting block circle and hatch are not created at supplied point 'pt' but somewhere else

 

(entmake
      (list
	(cons 0 "BLOCK")
	(cons 2 "9102_DETALJNA_TOCKA")
	(cons 70 2)
	(cons 10 '(0.0 0.0 0.0))
      ) ;_ _list
    ) ;_ _entmake
    (entmake
      (list
	(cons 0 "POINT")
	(cons 8 "0")
	(cons 10 '(0.0 0.0 0.0))
      ) ;_ _list
      ) ;_ _entmake
    (entmakex (list
		(cons 0 "ATTDEF")
		(cons 100 "AcDbEntity")
		(cons 8 "DT_broj_tocke")
		(cons 100 "AcDbText")
		(cons 10 '(0.0 0.0 0.0))	;pozicija
		(cons 40 t_ht)
		(cons 1 "Default")
		(cons 100 "AcDbAttributeDefinition")
		(cons 3 "")
		(cons 2 "BROJ_TOCKE")
		(cons 70 0)		; 1 invisible (0-visible)
;;;		(cons 72 0)		; horizontal justification
;;;		(cons 74 2)		; vertical justification
	      ) ;_ _list
    ) ;_ _entmakex
    (entmakex (list
		(cons 0 "ATTDEF")
		(cons 100 "AcDbEntity")
		(cons 8 "DT_visina_terena")
		(cons 100 "AcDbText")
		(cons 10 pt_attdef_1)
		(cons 40 t_ht)
		(cons 1 "Default")
		(cons 100 "AcDbAttributeDefinition")
		(cons 3 "")
		(cons 2 "HTERENA")
		(cons 70 0)
;;;		(cons 72 0)
;;;		(cons 74 2)
	      ) ;_ _list
    ) ;_ _entmakex
    (entmakex (list
		(cons 0 "ATTDEF")
		(cons 100 "AcDbEntity")
		(cons 8 "DT_visina_voda")
		(cons 100 "AcDbText")
		(cons 10 pt_attdef_2)
		(cons 40 t_ht)
		(cons 1 "Default")
		(cons 100 "AcDbAttributeDefinition")
		(cons 3 "")
		(cons 2 "HVODA")
		(cons 70 0)
;;;		(cons 72 0)
;;;		(cons 74 2)
	      ) ;_ _list
(entmake
      (list
	(cons 0 "ENDBLK")
	(cons 8 "0")
      ) ;_ _list
    ) ;_ _entmake
  ) ;_ _progn
) ;_ _if

  (setq	blok (vla-item
	       (vla-get-blocks
		 (setq doc (vla-get-ActiveDocument
			     (vlax-get-acad-object))))
		       "9102_DETALJNA_TOCKA"
	     ) ;_  vla-item
  ) ;_  setq


  (if (and (setq c (vla-addcircle blok (vlax-3d-point pt) r))
	   (setq h (vla-addhatch
		     blok
		     acHatchPatternTypePredefined
		     "SOLID"
		     :vlax-true
		   ) ;_  vla-addhatch
	   ) ;_  setq
      ) ;_  and
    (progn
      (vlax-invoke h 'AppendOuterLoop (list c))
      (vlax-invoke h 'Evaluate)
    ) ;_  progn
  ) ;_  if

  (vla-regen doc acallviewports)

 

Posted

It doesn't look like you are specifying pt  or r in the (vla-addcircle line in the snip above, so it will be either 0,0 or a previous point named pt.

 

Might also look at your entmakex attdef doesn't have a closing bracket ?

Posted

solved it, instead of pt I put '(0.0 0.0 0.0) and it works.(pt and r are acquired at start of lisp)

THANX again for ur help and guidance, and @Tharwat for his lisp that gave me idea 

  • Like 2
Posted

@Tomislav Have you considered using a donut rather than hatch? Much simpler IMO.

Posted

the form and components of that block are predefined, so must be like that...

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