.NET

.NET

Reply
Active Contributor
hperison
Posts: 28
Registered: ‎12-08-2009
Message 11 of 15 (311 Views)

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
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.PreDefined, "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.  :smileyhappy:

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 12 of 15 (300 Views)

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*
Alfred.NESWADBA
Posts: 9,607
Registered: ‎06-29-2007
Message 13 of 15 (288 Views)

Re: Object do not display correctly on inactive drawing

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

Hi,

 

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

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
hperison
Posts: 28
Registered: ‎12-08-2009
Message 14 of 15 (272 Views)

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:

Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 15 of 15 (147 Views)

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)
            acBlkTblRec.AppendEntity(a1IndexAreaPLine)
            a1IndexAreaTrans.AddNewlyCreatedDBObject(a1IndexAreaPLine, True)

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

            acCurDb.TransactionManager.QueueForGraphicsFlush()

            ' Create the hatch object and append it to the block table record
            Dim acHatch As Hatch = New Hatch()
            acBlkTblRec.AppendEntity(acHatch)
            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.SetDatabaseDefaults()
            acHatch.Associative = True
            acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
            acHatch.PatternScale = dwg_scale

            acBlkTblRec.SetObjectIdsInFlux()
            acHatch.AppendLoop(HatchLoopTypes.Outermost, a1IndexAreaIdColl)
            acHatch.EvaluateHatch(True)

            ' Save the new object to the database
            a1IndexAreaTrans.Commit()
        End Using
    End Sub

 Thanks,

Mark

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.