Jump to content

Entmake of a Hatch


Quest for Peace

Recommended Posts

My first post, I've been a lurker on websites like this for years. I'm trying to entmake (or entmakex) a hatch. I can do it for a solid hatch. I found a thread here from some time back about how other defined hatches are more difficult and I saw them discussing how it's done but no code attached or specific examples. I don't get it, please help. In that thread it said the simplest way was to take the straight DXF code from an existing hatch and entmakex it. But when I do that, it says "error: extra cdrs in dotted pair on input" so I went in and deleted the entity names, but then it won't make it.

Edited by Quest for Peace
Link to comment
Share on other sites

Thanks for both pieces of information,

 

I read it, didn't understand it. But comprehension is not a prerequisite for use. So I used it and created a rectangular hatch. I was very excited. Then I used it to give me the list that could be entmake'd into a hatch. Worked again, very excited. Then I tried to add my twist. The dxf code I posted has one boundary that is circular (dxf code 72 set to 2), and is a removed boundary. So my hatch is rectagular with a circular void in the middle. Doesn't work, I still don't get it. I'm suspecting it has to do with dxf 92, the boundary path flag. Help.

Edited by Quest for Peace
Link to comment
Share on other sites

Thanks to Lee Mac for correcting my poor etiquette, I'll go back and fix it so I stop getting corrected.

Now I'd really appreciate some help writing an excluded region in my entmake hatch.

My failed code:


(defun c:test1 ()


(entmakex


 '((0 . "HATCH")


   (100 . "AcDbEntity")


   (67 . 0)


   (8 . "0")


   (62 . 0)


   (100 . "AcDbHatch")


   (10 0.0 0.0 0.0)


   (210 0.0 0.0 1.0)


   (2 . "AR-SAND")


   (70 . 0)


   (71 . 1)


   (91 . 2)


   (92 . 16)


   (93 . 1)


   (72 . 2)


   (10 24.0 12.0 0.0)


   (40 . 3.61639)


   (50 . 0.0)


   (51 . 6.28319)


   (73 . 1)


   (97 . 1)


   (92 . 1)


   (93 . 4)


   (72 . 1)


   (10 1.24648 1.24648 0.0)


   (11 46.7535 1.24648 0.0)


   (72 . 1)


   (10 46.7535 1.24648 0.0)


   (11 46.7535 22.7535 0.0)


   (72 . 1)


   (10 46.7535 22.7535 0.0)


   (11 1.24648 22.7535 0.0)


   (72 . 1)


   (10 1.24648 22.7535 0.0)


   (11 1.24648 1.24648 0.0)


   (97 . 1)


   (75 . 0)


   (76 . 1)


   (52 . 0.0)


   (41 . 3.0)


   (77 . 0)


   (78 . 4)


   (53 . 0.65449)


   (43 . 0.0)


   (44 . 0.0)


   (45 . -0.1889)


   (46 . 5.78047)


   (79 . 6)


   (49 . 0.0)


   (49 . -4.56)


   (49 . 0.0)


   (49 . -5.1)


   (49 . 0.0)


   (49 . -4.875)


   (53 . 0.1309)


   (43 . 0.0)


   (44 . 0.0)


   (45 . 5.30933)


   (46 . 8.46644)


   (79 . 6)


   (49 . 0.0)


   (49 . -2.46)


   (49 . 0.0)


   (49 . -4.11)


   (49 . 0.0)


   (49 . -1.575)


   (53 . 5.71595)


   (43 . -3.69)


   (44 . 0.0)


   (45 . 9.34243)


   (46 . 0.0169772)


   (79 . 6)


   (49 . 0.0)


   (49 . -1.5)


   (49 . 0.0)


   (49 . -5.4)


   (49 . 0.0)


   (49 . -7.05)


   (53 . 5.54142)


   (43 . -3.69)


   (44 . 0.0)


   (45 . 9.0183)


   (46 . 2.63303)


   (79 . 6)


   (49 . 0.0)


   (49 . -0.75)


   (49 . 0.0)


   (49 . -3.54)


   (49 . 0.0)


   (49 . -4.05)


   (98 . 1)


   (10 0.0 0.0 0.0)))


 )

 

Now, with Lee Mac's link to code by ElpanovEvgeniy. I can make a rectagular hatch:

 


(DEFUN C:TEST2 ()


(ENTMAKE
 '((0 . "HATCH") (100 . "AcDbEntity") (410 . "Model") (100 
. "AcDbHatch") (10 0.0 
0.0 0.0) (210 0.0 0.0 1.0) (2 . "AR-SAND") (70 . 0) 
(71 . 0) (91 . 1) (92 . 7) 
(72 . 0) (73 . 1) (93 .  (10 1.24648 1.24648) 
(10 46.7535 1.24648) (10 
46.7535 1.24648) (10 46.7535 22.7535) (10 46.7535 
22.7535) (10 1.24648 22.7535) 
(10 1.24648 22.7535) (10 1.24648 1.24648) (97 
. 0) (75 . 0) (76 . 1) (52 . 
1.5708) (41 . 3.0) (77 . 0) (78 . 1) (53 . 
1.5708) (43 . 0.0) (44 . 0.0) (45 . 
1.0) (46 . 1.0) (79 . 0) (47 . 1.0) (98 
. 2) (10 0.0 0.0 0.0) (10 0.0 0.0 0.0) 
(451 . 0) (460 . 0.0) (461 . 0.0) 
(452 . 1) (462 . 1.0) (453 . 2) (463 . 0.0) 
(463 . 1.0) (470 . 
"LINEAR")))


 )

 

But now I still can't get to the goal because the first code has an excluded circle in the middle. I still, after reading my dxf codes last night, suspect it has to do with dxf 92. But one of the other boundary codes must also not be set correctly. I just get a return when I try to add that region.

Link to comment
Share on other sites

Since you have a void entmake'ing the Hatch becomes difficult, I would recommend you use the Visual LISP AddHatch method to create your hatch, an example:

(defun c:test ( / acdoc acspc hobj obj1 obj2 )

   ;; Example by Lee Mac 2011  -  www.lee-mac.com

   (setq acdoc (vla-get-activedocument  (vlax-get-acad-object))
         acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace))
   )

   ;; Create some test shapes to demonstrate the idea:

   (setq obj1
       (vla-addlightweightpolyline acspc
           (vlax-make-variant
               (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 7))
                   '(0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0)
               )
           )
       )
   )
   (vla-put-closed obj1 :vlax-true)

   (setq obj2 (vla-addcircle acspc (vlax-3D-point '(0.5 0.5 0.0)) 0.25))

   ;; Add the Hatch Object:

   (setq hobj (vla-addhatch acspc achatchpatterntypepredefined "ANSI31" :vlax-true achatchobject))

   ;; The Hatch Object is currently volatile, the next step is important:

   (vla-appendouterloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj1)
           )
       )
   )

   ;; Create the Circular void:

   (vla-appendinnerloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj2)
           )
       )
   )

   (vla-put-patternscale hobj 0.05)

   ;; Finished manipulation of the Hatch boundary, time to evaluate:

   (vla-evaluate hobj)
   (princ)
)
 
Edited by Lee Mac
Link to comment
Share on other sites

Yes, I clearly see Lee's post pointing you the way to Code Posting Guidelines. I also clearly saw where you chose to ignore them. :rtfm: Surely in all your lurking you have seen code posted in the code tags. You can delete your rude posts all you want, I can still see them.

 

You are not on much of a Quest for Peace with that attitude.

Link to comment
Share on other sites

Perfect. Worked first try. Once again, beyond my ability, but I can see it and see it will move me forward with that program. I wonder why the entmake is so difficult. I don't normally back down from trying to understand something, I find it comes up again and again if I don't master it. But if you're confirming it creates a difficult situation, I'll let it go. Thank you so much for that help, it gets me past something I've been struggling on/off for a month.

 

Sorry for poor manners. I have some stuff I use out of the express tools that I wonder how they work. My understanding is that I should avoid using them if I can. So maybe one day I'll be back to understand the acet-setvar. (But I need to search the threads first, make sure it's not already covered. I find there's a wealth of knowledge already there.) Thanks again.

Link to comment
Share on other sites

Perfect. Worked first try. Once again, beyond my ability, but I can see it and see it will move me forward with that program. I wonder why the entmake is so difficult. I don't normally back down from trying to understand something, I find it comes up again and again if I don't master it. But if you're confirming it creates a difficult situation, I'll let it go. Thank you so much for that help, it gets me past something I've been struggling on/off for a month.

 

You're welcome. If you have any questions about the code I posted just ask and I shall try my best to provide a comprehensible explanation. I also usually use entmake for entity creation for the raw speed and the fact that a multitude of properties can be set in one pass, rather than modifying each property individually using Visual LISP; however, the Hatch is one of the few entities (as well as MLine) that I avoid the use of entmake, purely because the Visual LISP alternative is SO much simpler and more robust to achieve the same result.

 

Cheers,

 

Lee

Link to comment
Share on other sites

  • 1 month later...

Lee (or Anyone),

 

The sample code creates 3 objects, the lwpolyline box, the circle, and the hatch. How do you take that information and create a block from it, quickly with speed? I have a block that looks like what you've created with one additional box offset outward from the box you show. All of it's companion blocks I'm now entmake'ing the entire block. I'd like to stay consistent, but this hatch problem is still causing me trouble.

 

Thanks,

Link to comment
Share on other sites

Quest for Peace said:
The sample code creates 3 objects, the lwpolyline box, the circle, and the hatch. How do you take that information and create a block from it, quickly with speed?,

 

Study this example of the modified code above:

(defun c:test ( / acdoc acblk acspc block hobj obj1 obj2 ) (vl-load-com)

   ;; Example by Lee Mac 2011  -  www.lee-mac.com

   (setq block "My Block") ;; Name of block to be created.

   ;; Note: No error checking on whether this block already exists,
   ;; I leave that to you.

   (setq acdoc (vla-get-activedocument  (vlax-get-acad-object))
         acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace))
         acblk (vla-add (vla-get-blocks acdoc) (vlax-3D-point '(0. 0. 0.)) block)
   )

   ;; Create some test shapes to demonstrate the idea:

   (setq obj1
       (vla-addlightweightpolyline acblk
           (vlax-make-variant
               (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 7))
                   '(0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0)
               )
           )
       )
   )
   (vla-put-closed obj1 :vlax-true)

   (setq obj2 (vla-addcircle acblk (vlax-3D-point '(0.5 0.5 0.0)) 0.25))

   ;; Add the Hatch Object:

   (setq hobj (vla-addhatch acblk achatchpatterntypepredefined "ANSI31" :vlax-true achatchobject))

   ;; The Hatch Object is currently volatile, the next step is important:

   (vla-appendouterloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj1)
           )
       )
   )

   ;; Create the Circular void:

   (vla-appendinnerloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj2)
           )
       )
   )

   (vla-put-patternscale hobj 0.05)

   ;; Finished manipulation of the Hatch boundary, time to evaluate:

   (vla-evaluate hobj)

   ;; Block is created, now to insert it:

   (vla-insertblock acspc (vlax-3D-point '(0. 0. 0.)) block 1.0 1.0 1.0 0.0)    
   (princ)
)
 
Edited by Lee Mac
Link to comment
Share on other sites

Thanks again. Now my problem is that I didn't think ahead and ask all my questions at once. And since you're using a method I know nothing about, the smallest adjustment appears impossible. By the way, is there a website or book reference that covers this starting from novice?

 

New problems:

I need to force the hatch to color "Red".

I need the lines to be color "ByBlock" and linetype to be "ByBlock".

Oh, and to force all of them to layer 0, no matter what the current layer is.

 

That should do it, thanks again. Oh, and thanks for the Sunday reply. I didn't expect that.

Link to comment
Share on other sites

Quest for Peace said:
By the way, is there a website or book reference that covers this starting from novice?

 

I haven't come across a tutorial or book that will cover everything there is to know about Visual LISP, but personally, I have learnt the majority of what I know from the Visual LISP IDE Help Documentation provided with AutoCAD. Sadly, the ActiveX reference has been removed from versions 2011 onwards when VBA was no longer supported.

 

Otherwise, take a look at the Visual LISP tutorials on AfraLISP, and my post here may also help.

 

Quest for Peace said:
New problems:

I need to force the hatch to color "Red".

I need the lines to be color "ByBlock" and linetype to be "ByBlock".

Oh, and to force all of them to layer 0, no matter what the current layer is.

 

Here is the example modified again to demonstrate how to change object properties:

(defun c:test ( / acdoc acblk acspc block hobj obj1 obj2 ) (vl-load-com)

   ;; Example by Lee Mac 2011  -  www.lee-mac.com

   (setq block "My Block") ;; Name of block to be created.

   ;; Note: No error checking on whether this block already exists,
   ;; I leave that to you.

   (setq acdoc (vla-get-activedocument  (vlax-get-acad-object))
         acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace))
         acblk (vla-add (vla-get-blocks acdoc) (vlax-3D-point '(0. 0. 0.)) block)
   )

   ;; Create some test shapes to demonstrate the idea:

   (setq obj1
       (vla-addlightweightpolyline acblk
           (vlax-make-variant
               (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 7))
                   '(0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0)
               )
           )
       )
   )
   (vla-put-closed obj1 :vlax-true)

   (vla-put-linetype obj1 "BYBLOCK")
   (vla-put-color obj1 acbyblock)
   (vla-put-layer obj1 "0")

   (setq obj2 (vla-addcircle acblk (vlax-3D-point '(0.5 0.5 0.0)) 0.25))

   (vla-put-linetype obj2 "BYBLOCK")
   (vla-put-color obj2 acbyblock)
   (vla-put-layer obj2 "0")

   ;; Add the Hatch Object:

   (setq hobj (vla-addhatch acblk achatchpatterntypepredefined "ANSI31" :vlax-true achatchobject))

   ;; The Hatch Object is currently volatile, the next step is important:

   (vla-appendouterloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj1)
           )
       )
   )

   ;; Create the Circular void:

   (vla-appendinnerloop hobj
       (vlax-make-variant
           (vlax-safearray-fill
               (vlax-make-safearray vlax-vbobject '(0 . 0))
               (list obj2)
           )
       )
   )

   (vla-put-patternscale hobj 0.05)

   ;; Finished manipulation of the Hatch boundary, time to evaluate:

   (vla-evaluate hobj)
   (vla-put-color hobj acred)
   (vla-put-layer hobj "0")

   ;; Block is created, now to insert it:

   (vla-insertblock acspc (vlax-3D-point '(0. 0. 0.)) block 1.0 1.0 1.0 0.0)    
   (princ)
)
 
Edited by Lee Mac
Link to comment
Share on other sites

Thanks so much, again. I got it. Funny, the first time I ran it through, my computer paused for a long time. I don't know why it did that. I started a new drawing, reloaded, then it was immediate.

 

Yes, 2011 and the web based help. I haven't found it to be useful yet.

 

Thanks.

Link to comment
Share on other sites

Thanks so much, again. I got it. Funny, the first time I ran it through, my computer paused for a long time. I don't know why it did that. I started a new drawing, reloaded, then it was immediate.

 

Perhaps loading the Modeller DLLs, that sometimes takes a little while.

 

Yes, 2011 and the web based help. I haven't found it to be useful yet.

 

Worst decision ADesk ever made IMO.

Link to comment
Share on other sites

  • 8 years later...
;; Note: No error checking on whether this block already exists,
;; I leave that to you.

I can't find how to handle this. I'm using this method to create blocks, everything is fine. Now I have a need to redefine a block that already exists in the drawing. But this method adds the block data to the block in the drawing instead of redefining the block. I want all the current locations to remain in the drawing, and be able to redefine the block with this visual method. Entmake seems to be working for redefining blocks, but I can't entmake the hatches with complex shapes. I don't know, does that make sense?

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