The code example contained within the AutoCAD NET Developers Guide does not provide
for arbitrary pattern values. It is simply a rudimentary code sample that reflects the means
of adding a Hatch pattern to a drawing. That is fine if that is what is needed. For setting the
Hatch pattern to a variable set of values the hatch pattern code can be as follows:
Dim acHatch As Hatch = New Hatch() ' 'Add the hatch to the block table record and the transaction acBlkTblRec.AppendEntity(acHatch) acTrans.AddNewlyCreatedDBObject(acHatch, True) acHatch.SetDatabaseDefaults(acSpoolDb) ' ' Change from read to write mode acHatch.UpgradeOpen() ' 'set the Hatch properties acHatch.Associative = True acHatch.PatternScale = 0.5 acHatch.PatternAngle = Math.PI * 0.25 acHatch.SetHatchPattern(HatchPatternType.PreDefine
d, "ANSI31") ' ' Change from write to read mode acHatch.DowngradeOpen() ' 'Attach to boundary loop acHatch.AppendLoop(HatchLoopTypes.[Default], acObjIdColl) ' ' Save the new hatch object to the database acTrans.Commit()
For me the CommandFlag.Session flag was set in order for the hatch to display.
If one has a better way of adding hatching that accepts differing parameters and displays correctly, then by all means share.
You sure about that?
I'm getting confused now. I was playing around with the example in the developers guide, and was just getting ready to post a comment here when you posted your last one.
I was getting the hatch showing up with the right pattern angle, but the wrong scale, regardless of calling evaluate hatch or not.
And even with the code you just posted, I am still getting an eInvalidInput Exception unless I move the PatternAngle setting to after calling SetHatchPattern.
Now it is getting even wierder, because I have gone back to the original Developer guide code, added two lines to set the PatternAngle and PatternScale, and now it is working fine. I have three separate functions each slightly different, and all three are working fine.
If I take any of the three and move the PatternAngle setting to before the SetHatchPattern call, they all fail, eInvalidInput.
>> unless I move the PatternAngle setting to after calling SetHatchPattern
Did you ever verify on what AutoCAD releases you are working? Because the order for PatternAngle before or after SetHatchPattern is depending on AutoCAD-release!
I use this code working now from 2007 to 2012, not yet tested with 2013
If ISHAcConn.AcadApp_VersionDouble < 18.1 Then Hatch.PatternAngle = (RotationDegree / 180 * Math.PI) End If
nType.PreDefined, tPatternName) If ISHAcConn.AcadApp_VersionDouble >= 18.1 Then Hatch.PatternAngle = (RotationDegree / 180 * Math.PI) End If
BTW: I'm really surprised that the hatch-creation is working without the .EvaluateHatch
- alfred -
Ingenieur Studio HOLLAUS ... www.hollaus.at
Due to my excitement in getting this to finally work I made an error in my latest code.
UpgradeOpen and DowngradeOpen lines are not required and do nothing. I have subsequently
removed those lines and the code still works as desired.
During my attempts to remedy the problem, I had a suspicion that sequence order was important
and was moving the order around without much success in getting the correct sequence. Upon review
of my original post, I see where I have gone astray.
I am using a AutoCAD 2010 - 64bit platform with VS2010 Pro
Thank you Alfred, as I am glad to know that I am going to need to implement a caveat for later versions of Autocad.
I think this can be put to rest now