Active Contributor
28 Posts
1 Kudo
Registered: ‎12-08-2009
Post 11 of 15

Re: Object do not display correctly on inactive drawing

04-11-2012 03:38 PM in reply to: chiefbraincloud

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
acTrans.AddNewlyCreatedDBObject(acHatch, True)
' Change from read to write mode
'set the Hatch properties
acHatch.Associative = True
acHatch.PatternScale = 0.5
acHatch.PatternAngle = Math.PI * 0.25
acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
' Change from write to read mode
'Attach to boundary loop
acHatch.AppendLoop(HatchLoopTypes.[Default], acObjIdColl)
' Save the new hatch object to the database


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

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 12 of 15

Re: Object do not display correctly on inactive drawing

04-11-2012 04:34 PM in reply to: hperison

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.

Dave O.                                                                  Sig-Logos32.png
*Expert Elite*
9,785 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 13 of 15

Re: Object do not display correctly on inactive drawing

04-12-2012 12:19 AM in reply to: chiefbraincloud



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

Hatch.SetHatchPattern(DatabaseServices.HatchPatternType.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
Active Contributor
28 Posts
1 Kudo
Registered: ‎12-08-2009
Post 14 of 15

Re: Object do not display correctly on inactive drawing

04-12-2012 07:49 AM in reply to: Alfred.NESWADBA

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:smileyhappy:

415 Posts
0 Kudos
Registered: ‎09-23-2004
Post 15 of 15

Re: Object do not display correctly on inactive drawing

07-05-2013 09:21 AM in reply to: chiefbraincloud

Hi Chief,

I have the same problem with the hatch scale.  I've tried re-arranging the hatch properties, but I just can't seem to get it to visually show the correct hatch scale.  When I pick the hatch and view its properties, it shows the right hatch scale, but visually it's wrong.  Can you take a look and see where I might be going wrong?

    Public Sub AddIndexArea(ByVal leftX As Double, ByVal rightX As Double, ByVal bottomY As Double, ByVal topY As Double, dwg_scale As Double)
        ' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        ' Start a transaction
        Using a1IndexAreaTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            ' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = a1IndexAreaTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

            ' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = a1IndexAreaTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            ' Create a rectangle object for the boundary of the hatch
            Dim a1IndexArea As New Autodesk.AutoCAD.Geometry.Point3dCollection
            a1IndexArea.Add(New Geometry.Point3d(leftX, bottomY, 0))
            a1IndexArea.Add(New Geometry.Point3d(rightX, bottomY, 0))
            a1IndexArea.Add(New Geometry.Point3d(rightX, topY, 0))
            a1IndexArea.Add(New Geometry.Point3d(leftX, topY, 0))
            Dim a1IndexAreaPLine As New DatabaseServices.Polyline2d(DatabaseServices.Poly2dType.SimplePoly, a1IndexArea, 0, True, 0, 0, Nothing)
            a1IndexAreaTrans.AddNewlyCreatedDBObject(a1IndexAreaPLine, True)

            ' Adds the rectangle to an object id collection
            Dim a1IndexAreaIdColl As ObjectIdCollection = New ObjectIdCollection()


            ' Create the hatch object and append it to the block table record
            Dim acHatch As Hatch = New Hatch()
            a1IndexAreaTrans.AddNewlyCreatedDBObject(acHatch, True)

            ' Set the properties of the hatch object
            ' Associative must be set after the hatch object is appended to the block table record
            acHatch.Associative = True
            acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
            acHatch.PatternScale = dwg_scale

            acHatch.AppendLoop(HatchLoopTypes.Outermost, a1IndexAreaIdColl)

            ' Save the new object to the database
        End Using
    End Sub



Post to the Community

Have questions about Autodesk products? Ask the community.

New Post