Hatch a Rectangle created using addLine

Hatch a Rectangle created using addLine

aachiney
Contributor Contributor
1,386 Views
3 Replies
Message 1 of 4

Hatch a Rectangle created using addLine

aachiney
Contributor
Contributor

 

I have 4 points and using the addLine() method, I am joining these 4 points to create a rectangle. I have

done this very well. 

 

What I want next is to fill this rectangle with certain color. I am not able to do this.

 

Any help please...?

 

 

0 Likes
Accepted solutions (1)
1,387 Views
3 Replies
Replies (3)
Message 2 of 4

seabrahenrique
Advocate
Advocate
Accepted solution

Hello,

 

This example comand to add hatch in AutoCAD may can help u... check here:

 

Sub Example_AddHatch()
    ' This example creates an associative gradient hatch in model space.
    
    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim PatternType As Long
    Dim bAssociativity As Boolean
    
    ' Define the hatch
    patternName = "CYLINDER"
    PatternType = acPreDefinedGradient '0
    bAssociativity = True
    
    ' Create the associative Hatch object in model space
    Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, acGradientObject)
    Dim col1 As AcadAcCmColor, col2 As AcadAcCmColor
    Set col1 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(AcadApplication.Version, 2))
    Set col2 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(AcadApplication.Version, 2))
    Call col1.SetRGB(255, 0, 0)
    Call col2.SetRGB(0, 255, 0)
    hatchObj.GradientColor1 = col1
    hatchObj.GradientColor2 = col2
    
    ' Create the outer boundary for the hatch (a circle)
    Dim outerLoop(0 To 0) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 3: center(1) = 3: center(2) = 0
    radius = 1
    Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
    
    ' Append the outerboundary to the hatch object, and display the hatch
    hatchObj.AppendOuterLoop outerLoop
    hatchObj.Evaluate
    ThisDrawing.Regen True
    
End Sub

 

Can u understand and adapt it to yout situation?

0 Likes
Message 3 of 4

aachiney
Contributor
Contributor

Hi,

 

Thanks for the reply... 

But I am unable to put the code to work. Below is the piece of my code which creates a rectangle.

    Set Bline = ThisDrawing.ModelSpace.AddLine(startPointMin, endPointMin)
    Set Cline = ThisDrawing.ModelSpace.AddLine(startPointPlu, endPointPlu)
    Set Pline = ThisDrawing.ModelSpace.AddLine(startPointMin, endPointMin2)
    Set Qline = ThisDrawing.ModelSpace.AddLine(startPointPlu, endPointPlu2)

    Set Rline = ThisDrawing.ModelSpace.AddLine(endPointMin, endPointPlu2)
    Set Sline = ThisDrawing.ModelSpace.AddLine(endPointPlu, endPointMin2)

  

Can you help me to adjust this code within yours... ?

 

Regards

0 Likes
Message 4 of 4

parikhnidi
Advocate
Advocate

I have not played much with the hatch pattern, but, wouldn't be easy to draw a polyline instead of four lines and hatch that polyline.

 

I will try to write some code on this to see if it works.

 

Just a thought.

Nimish

0 Likes