• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 20
    Registered: ‎12-08-2009

    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:

    Please use plain text.
    *Expert Elite*
    chiefbraincloud
    Posts: 736
    Registered: ‎02-13-2008

    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
    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎12-08-2009

    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:

    Please use plain text.