Author Topic: Object do not display properly on inactive drawings  (Read 2541 times)

0 Members and 1 Guest are viewing this topic.

hperison

  • Guest
Object do not display properly on inactive drawings
« on: April 10, 2012, 06:34:11 PM »
I have created a NET routine which, when executed, creates a schematic drawing representation of the parent (active drawing).  All of the procedures execute as they should, however one is a mystery.    HATCH

On the schematic (inactive document) the hatch appears with the Autocad default settings for the pattern used.
The properties that I am looking at are:   The pattern scale and the hatch angle.

The new hatch pattern is displayed with a pattern scale of 1.0  and a hatch angle of 0.0    when they should be
displayed with a pattern scale of 0.5 and a hatch angle of 45

Upon reviewing the hatch properties, by double clicking on the offending hatch pattern, I find that the values are
are correct and as expected  (0.5 and 45).     By closing the hatch property dialog, the hatch pattern updates itself.


Why doesn't this occur automatically, even linetypes do not appear correctly until a regen is manually involked? 
Is it because the hatch pattern or other elements are not being drawn on the active document?
Is this just Autocad?

I have attempted to do the same test via COM  and the results are the same.

I can't believe that no one programically creates supporting documents from a parent drawing.

Below is some code:

Code: [Select]
            '
            ' Create the hatch object and append it to the block table record
            Dim acHatch As Hatch = New Hatch()
            '
            ' Set the properties of the hatch object
            acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
            acHatch.PatternScale = 0.5
            acHatch.PatternAngle = Math.PI * 0.25
            '
            ' Add the hatch object to the new database.  If these 3 lines of code are before the pattern settings
            ' an "eAmbiguousObject" error will occur when the hatch object is evaluated.
            acHatch.SetDatabaseDefaults(acNewDb)
            acBlkTblRec.AppendEntity(acHatch)
            acTrans.AddNewlyCreatedDBObject(acHatch, True)
            '
            ' Define the host working database.  If this is not added here the hatch does not appear until the
            ' document is saved and reopened
            HostApplicationServices.WorkingDatabase = acHatch.Database
 
            acHatch.Associative = True
            acHatch.AppendLoop(HatchLoopTypes.[Default], acObjIdColl)
            acHatch.EvaluateHatch(True)
            '
            ' Save the new object to the database
            acTrans.Commit()


« Last Edit: April 10, 2012, 06:37:45 PM by hperison »

TheMaster

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #1 on: April 11, 2012, 12:12:45 AM »
I have created a NET routine which, when executed, creates a schematic drawing representation of the parent (active drawing).  All of the procedures execute as they should, however one is a mystery.    HATCH

On the schematic (inactive document) the hatch appears with the Autocad default settings for the pattern used.
The properties that I am looking at are:   The pattern scale and the hatch angle.

The new hatch pattern is displayed with a pattern scale of 1.0  and a hatch angle of 0.0    when they should be
displayed with a pattern scale of 0.5 and a hatch angle of 45

Upon reviewing the hatch properties, by double clicking on the offending hatch pattern, I find that the values are
are correct and as expected  (0.5 and 45).     By closing the hatch property dialog, the hatch pattern updates itself.


Why doesn't this occur automatically, even linetypes do not appear correctly until a regen is manually involked? 
Is it because the hatch pattern or other elements are not being drawn on the active document?
Is this just Autocad?

I have attempted to do the same test via COM  and the results are the same.

I can't believe that no one programically creates supporting documents from a parent drawing.

Below is some code:

Code: [Select]
            '
            ' Create the hatch object and append it to the block table record
            Dim acHatch As Hatch = New Hatch()
            '
            ' Set the properties of the hatch object
            acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
            acHatch.PatternScale = 0.5
            acHatch.PatternAngle = Math.PI * 0.25
            '
            ' Add the hatch object to the new database.  If these 3 lines of code are before the pattern settings
            ' an "eAmbiguousObject" error will occur when the hatch object is evaluated.
            acHatch.SetDatabaseDefaults(acNewDb)
            acBlkTblRec.AppendEntity(acHatch)
            acTrans.AddNewlyCreatedDBObject(acHatch, True)
            '
            ' Define the host working database.  If this is not added here the hatch does not appear until the
            ' document is saved and reopened
            HostApplicationServices.WorkingDatabase = acHatch.Database
 
            acHatch.Associative = True
            acHatch.AppendLoop(HatchLoopTypes.[Default], acObjIdColl)
            acHatch.EvaluateHatch(True)
            '
            ' Save the new object to the database
            acTrans.Commit()

To have changes displayed in a non-active document that's open in the editor,
the non-active document must be made the 'current' document when the changes
occur. The API that does that is not exposed to managed code, and it cant' be
P/Invoked either.  The API is AcApDocManager::setCurDocument().

I wouldn't try opening a document and modifying it when it is not active.

It's no more difficult to just create a new Database() in memory, add your
content to it, save it, and if you need to, open it in the editor.

hperison

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #2 on: April 11, 2012, 11:27:58 AM »
Quote
To have changes displayed in a non-active document that's open in the editor,
the non-active document must be made the 'current' document when the changes
occur. The API that does that is not exposed to managed code, and it cant' be
P/Invoked either.  The API is AcApDocManager::setCurDocument().

Thanks for the input.  I had my suspicions that this was the case.

It appears that I have to write a new Hatch function that produces what I am looking for.

hperison

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #3 on: April 11, 2012, 06:38:05 PM »
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:

Code: [Select]
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.    :laugh:
« Last Edit: April 11, 2012, 07:05:05 PM by hperison »

TheMaster

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #4 on: April 11, 2012, 09:19:12 PM »
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:

Code: [Select]
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.    :laugh:

There should be no need for the calls to UpgradeOpen()/DowngradeOpen(),
because the Hatch object is a newly-created object that was just appended
to the database.

UpgradeOpen() is used on database-resident objects that are  currently open
for read. Newly-created objects are write-enabled by default, and do not require
a call to UpgradeOpen().

Calling DowngradeOpen() on an object that is Transaction-resident as is
the case in your code, is pointless as it does nothing.
« Last Edit: April 11, 2012, 09:24:51 PM by TheMaster »

kaefer

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #5 on: April 12, 2012, 04:01:43 AM »
It's no more difficult to just create a new Database() in memory, add your
content to it, save it, and if you need to, open it in the editor.

You wouldn't believe that in this instance (side database), the hatch pattern properties aren't updated just as they aren't updated in a non-current, editor-opened drawing. While it's all fine and dandy what you're telling us about the current document, this suggests a particular problem with the Hatch class.

kaefer

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #6 on: April 12, 2012, 07:21:40 AM »
this suggests a particular problem with the Hatch class.

It does. Thanks to Alfred Neswadba over at Autodesk's .NET forum, the order of setting the hatch pattern and the other properties is important, and it is version-dependent.

Code - F#: [Select]
  1.     let ha = new Hatch()
  2.  
  3.     if  acadApp.Version.Major < 18 ||
  4.         (acadApp.Version.Major = 18 && acadApp.Version.Minor < 1) then
  5.    
  6.         ha.PatternScale <- 0.5
  7.         ha.PatternAngle <- System.Math.PI * 0.25
  8.    
  9.     ha.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
  10.  
  11.     if  acadApp.Version.Major > 18 ||
  12.         (acadApp.Version.Major = 18 && acadApp.Version.Minor >= 1) then
  13.  
  14.         ha.PatternScale <- 0.5
  15.         ha.PatternAngle <- System.Math.PI * 0.25


hperison

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #7 on: April 12, 2012, 10:49:03 AM »
There should be no need for the calls to UpgradeOpen()/DowngradeOpen(),
because the Hatch object is a newly-created object that was just appended
to the database.

Master:  I was so excited that I got the function working after major hours were spent on attempting
 to resolve my issue and didn't realize my error.   You are correct and I have removed the
UpgradeOpen/DowngradeOpen and everything still worked as desired.  Thank you again.


kaefer:  Interesting news!!!    I am using Autocad 2010-64 bit

Thank you

TheMaster

  • Guest
Re: Object do not display properly on inactive drawings
« Reply #8 on: April 12, 2012, 03:20:33 PM »
It's no more difficult to just create a new Database() in memory, add your
content to it, save it, and if you need to, open it in the editor.

You wouldn't believe that in this instance (side database), the hatch pattern properties aren't updated just as they aren't updated in a non-current, editor-opened drawing. While it's all fine and dandy what you're telling us about the current document, this suggests a particular problem with the Hatch class.

In the case of a non-active/current document open in the editor, the problem of graphics not updating has nothing to do with hatch behavior. That's a totally separate  issue that affects all graphics, not only hatches. Of course, something may have changed in the last two releases (I did raise the issue with Albert, and he acknowledged that it was problem, but I don't know if anything was ever done about it).