PDA

View Full Version : Ask for HatchPattern?


vndesperados
03-05-2005, 08:07 AM
Hello everybody!
My name is Long from VietNam
Anybody help me?
I wana change the PatternName of HatchPattern but that is a read-only properties.
EX:
The name of Hatch is SOLID, I wana change name is ANGLE.
How must I do?
Thanks.

Exxit
03-05-2005, 08:36 AM
Hi Long,

why did You post the question in the Advanced VBA forum?

I don't understand Your problem... :oops:

1. Which AC version are You running?
2. Do You want to change the hatch in a drawing?
or the name in the definition (in the *.pat.file) I won't do that

Maybe You can explain the problem better and maybe You can attach an example...?

regards, Lothar

Eddie
03-05-2005, 09:15 AM
8) OK that's better ...
Now First of all if you want to rename a read only file you MUST either remove the read only lock or make a copy of the file that is NOT read only.

Can you clarify your question as per Exxit's request ..

vndesperados
03-05-2005, 10:12 AM
Thank for reply!
My AutoCad is 2004
This is My Code
'--------------
Function ChangeHatchPattern(layerstr as string, hapattern as string) as boolean
Dim ha as AutoCad.Hatch
Dim objs as AutoCad.SelectionSet
Dim obj as AutoCad.AcadEntity
Set objs=ThisDrawing.SelectionSet.Add("SetObjets")
objs.Select acSelectionSetAll
For Each obj in objs
If obj.EntityType<>acHacth then
obj.Delete 'Creat a set of Hatch
End iF
Next
For each ha in objs
If ha.layer=layerstr then
ha.PatternName=hapattern
End if
Next
End Function
'End Code---------
Thanks
AnyFedBack is Helpful
Best Regards

Vo Kien Cuong

Eddie
03-05-2005, 08:08 PM
8) If I understand you correctly....You want replace the SOLID hatch pattern with the ANGEL pattern...Is this correct ??

If this is so then why are you deleting the hatch ?
If obj.EntityType<>acHacth then
obj.Delete 'Creat a set of Hatch
End iF

change your hatch pattern here...with something like this.

' Define the hatch
hapattern = "ANSI31"
Pattern = 0
Assoc = True

For each ha in objs
If ha.layer=layerstr then
ha.PatternName=hapattern
ha.Patterntype=Pattern
ha.bAssociativity=Assoc
End if
Next

vndesperados
04-05-2005, 01:50 AM
Hello
Thanks for reply
If I understand you correctly....You want replace the SOLID hatch pattern with the ANGEL pattern...Is this correct ??

That's right!

If this is so then why are you deleting the hatch ?
If obj.EntityType<>acHacth then
obj.Delete 'Creat a set of Hatch
End iF

This is a SelectionSet in Autocad and you can delete some object in this selection.

' Define the hatch
hapattern = "ANSI31"
Pattern = 0
Assoc = True

For each ha in objs
If ha.layer=layerstr then
ha.PatternName=hapattern
ha.Patterntype=Pattern
ha.bAssociativity=Assoc
End if
Next

Thank you code, hope is correct

Eddie
04-05-2005, 04:01 AM
8) Try something like this..

Sub ChangeHatchPattern()
Dim ha As AcadHatch
Dim ss As AcadSelectionSet
Dim obj As AcadEntity
Dim layerstr As String, hapattern As String

On Error Resume Next
ss.Delete
Set ss = ThisDrawing.SelectionSets("SS")
If Err Then Set ss = ThisDrawing.SelectionSets.Add("SS")

Mode = acSelectionSetAll
'Begin object AutoSelection for procedure
Dim Grpc(0) As Integer, GrpV(0) As Variant
Grpc(0) = 0: GrpV(0) = "hatch"
ss.Select Mode, , , Grpc, GrpV
If ss.Count = 0 Then End


' Define the hatch
hapattern = "ANSI31"
Pattern = acHatchPatternTypePreDefined
Assoc = True

' Cycle through the hatch objects on screen and change to new pattern
For Each ha In ss
ha.SetPattern Pattern, hapattern
ha.Evaluate
ha.Update
Next
ThisDrawing.Regen True
End Sub

Hope this helps.

vndesperados
04-05-2005, 04:27 AM
Hi Eddie
My name is Ngoc Long from VietNam
Ngoc Long is mean dragon diamond
Thank for your reply
I've just finish my course in College and this is the first project in my work
Can you tell me about you?
Please to meet you

Eddie
04-05-2005, 05:40 AM
8) Welcome Ngoc ...
Me..I'm in Australia, and have been using Autocad since R9/R10 and having been writing VBA for 1.5 years..

But rest assured the other more experienced VBA coders here, so any future queries WILL be answered.

vndesperados
05-05-2005, 01:35 PM
Hi Eddie
Thank for your code
That's very good for me.
Are you a software developer?
I've just finish my course in college about IT
I've been using AutoCAd since R12 for Dos and use AutoLisp 6 month ago.
Now I begin use VBA to Code in my project.
Hope you can help me
Best regards