HATCH vba

HATCH vba

zsolti_sdd
Enthusiast Enthusiast
1,672 Views
5 Replies
Message 1 of 6

HATCH vba

zsolti_sdd
Enthusiast
Enthusiast

hy

 

how can i hatch a rectangle? and creat a dimension ? and calculate the area of that hatch?

i try this code to hatch.  ThisDrawing.ModelSpace.AddHatch  predefined, solid, False, rect     ....but not working

 

 

'creat a rectangle in origin

 

coords(0) = 0
coords(1) = 0
coords(2) = Val(TextBox1.Text)
coords(3) = 0
coords(4) = Val(TextBox1.Text)
coords(5) = Val(TextBox2.Text)
coords(6) = 0
coords(7) = Val(TextBox2.Text)
Dim rect As AcadLWPolyline
Set rect = ThisDrawing.ModelSpace.AddLightWeightPolyline(coords)


rect.Closed = True
rect.Update

0 Likes
1,673 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> i try this code to hatch.  ThisDrawing.ModelSpace.AddHatch  predefined, solid, False, rect 

You code snippet shows how you created a polyline, it does not show how to hatch it.

But as you already know the function which is needed to create a hatch, why not just using the help, place the cursor above "AddHatch", click to be in text-edit-mode and press <F1> ... that  brings you to the help and on the same page to a sample how AddHatch is working like >>>here<<<.

 

Take that sample, reduce the lines that might not be needed for you (at the moment) until the sample does not work ... so that is the point of the minimum requirements to create the hatch. Next step is to change the sample values to your values, e.g. another patternname, ... and at least not the sample-circle is used, instead your polyline is used.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

zsolti_sdd
Enthusiast
Enthusiast

sorry

i dont understand !anythingSmiley FrustratedSmiley Frustrated

what defined?

 

the code?

 

0 Likes
Message 4 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> i dont understand !anything

With just a few words what I suggested:

  • use the sample in the help
  • I also have shown you a link to the sample as hyperlink on >>>click<<< in my previous post.

Hopefully that is easier to understand?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 6

zsolti_sdd
Enthusiast
Enthusiast

in this case : Runtime Error

0 Likes
Message 6 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

did the sample run before you made modifications? I guess yes, and to change the patternname to "SOLID", but try to use that as gradient does not work, so be consequent and if you make one change then look to all lines which have to be modified as well to fit to the change.

If you make a hatch to not be a gradient hatch, then don't use the "acGradientObject"-parameter within the "AddHatch" function and also don't assign "GradientColor1" and "GradientColor2".

 

And please let us know more than "in this case" ... without telling us what you did. I guess no one here likes to verify lines from your screenshot with the original sample.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes