Author Topic: ObjectDBX and Attributes  (Read 27354 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
ObjectDBX and Attributes
« on: August 24, 2006, 03:49:28 PM »
I know in lisp, and VBA if the alignment of attributes is anything but left, then they do not update correctly.  Is this true for .Net also?  I hope not.  I haven't done any testing yet, as this is above my level right now, but if the alignment issue is a non-issue, then I will be looking into this for some routines that I have now.

Thanks.

Edit:  In my searchs of the net I haven't found an answer yet.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Cathy

  • Guest
Re: ObjectDBX and Attributes
« Reply #1 on: August 24, 2006, 05:06:44 PM »
I just feel certain that .net will not help this -- it's not the language that you use to change the attribute, it's the way Autocad handles the change. 

If you use the ATTSYNC command after you open the drawing, Autocad will rejustify the attributes correctly. 

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #2 on: August 24, 2006, 05:16:48 PM »
I just feel certain that .net will not help this -- it's not the language that you use to change the attribute, it's the way Autocad handles the change. 

If you use the ATTSYNC command after you open the drawing, Autocad will rejustify the attributes correctly. 
I thought so, but was hoping.  Oh well, I guess I won't update those routines then.  Thanks.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: ObjectDBX and Attributes
« Reply #3 on: August 25, 2006, 12:33:49 PM »
I just feel certain that .net will not help this -- it's not the language that you use to change the attribute, it's the way Autocad handles the change. 

If you use the ATTSYNC command after you open the drawing, Autocad will rejustify the attributes correctly. 

No need for that. The solution is quite simple in managed or unmanaged ObjectARX.

You temporarily set the WorkingDatabase property of the HostApplicationServices object to the database that contains the text/attribute, and then do the mods. Make sure that you save the curent value of WorkingDatabase before you change it, and then restore that after you're done (this part is absolutely critical, to prevent AutoCAD from crashing)

Here is a class that you can use to automate the switching:

Code: [Select]
using System;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;

namespace CaddZone.DatabaseServices
{
   class WorkingDatabase : IDisposable
   {
      public WorkingDatabase(Database db)
      {
         Database current = HostApplicationServices.WorkingDatabase;
         if (db != current)
         {
            m_Previous = current;
            HostApplicationServices.WorkingDatabase = db;
         }
         else
            GC.SuppressFinalize(this);
      }

      ~WorkingDatabase()
      {
         Dispose(false);
      }

      #region IDisposable Members

      public void Dispose()
      {
         Dispose(true);
      }

      #endregion

      private bool disposed = false;
      private void Dispose(bool p)
      {
         if (!disposed)
         {
            Database current = HostApplicationServices.WorkingDatabase;
            if ( m_Previous != null && current != m_Previous)
               HostApplicationServices.WorkingDatabase = m_Previous;
            disposed = true;
            GC.SuppressFinalize(this);
         }
      }

      private Database m_Previous = null;

   }

   // Example usage:

   public class Example
   {
      public Example()
      {
         Database db = new Database(true, true);

         using (WorkingDatabase wdb = new WorkingDatabase(db))
         {
            // Do stuff here that requires db to be the WorkingDatabase
         }
      }
   }
}

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #4 on: August 25, 2006, 01:01:20 PM »
Thanks for posting Tony!!

This seems a little over my head right now, but let me take a stab at what you are saying.

So I would open the drawing as and ODBX document (IAxDbDocument ?) and then use your function to grab the database, and make my changes? and this will take care of the problem with attributes?

What else would you need to do this with? (real quick off the top of you head, if you don't mind)

Thanks again!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: ObjectDBX and Attributes
« Reply #5 on: August 25, 2006, 01:50:03 PM »
Thanks for posting Tony!!

This seems a little over my head right now, but let me take a stab at what you are saying.

So I would open the drawing as and ODBX document (IAxDbDocument ?) and then use your function to grab the database, and make my changes? and this will take care of the problem with attributes?

What else would you need to do this with? (real quick off the top of you head, if you don't mind)

Thanks again!

Hi Tim.  If you're using ObjectDBX ActiveX, then you can get the
managed Database from the AcadDatabase using this:

Code: [Select]
   AxDbDocument dbxDoc = // get your database open

   using( WorkingDatabase wdb = new WorkingDatabase(
                       Database.FromAcadDatabase(dbxDoc.Database)))
   {
          // Here you can modify text/attributes in the database
   }

You don't need to do the mods via managed code, you can use the ActiveX methods, the only requirement is that while you do the mods, HostApplicationServices.WorkingDatabase must be set to the Database containing the text/attributes. The WorkingDatabase class I posted automates the temporary switching of that property's value for you.



T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #6 on: August 25, 2006, 01:57:16 PM »
Thanks for the clarification Tony!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #7 on: August 30, 2006, 02:54:02 PM »
Tony (or anyone who knows),

  I can't seem to get this to work.  I was using what you posted as my guide, but it errors saying
Quote
ODBX-Test.cs(38,12): error CS0246: The type or namespace name 'WorkingDatabase' could not be found (are you missing a using directive or an assembly reference?)

Here is the code.  I'm just (trying to) printing out the names of all the blocks in a drawing opened with ObjectDBX.
Code: [Select]
using System;
using System.Collections;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop.Common;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass (typeof (Test.odbxTest))]

namespace Test
{
/// <summary>
/// Description of Working.
/// </summary>
public class odbxTest
{
[CommandMethod ("dbxTest")]
public void TestODBX() {
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor DocEd = Doc.Editor;
Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud layer", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
Dia.ShowDialog();
string[] DwgList = Dia.GetFilenames();
AxDbDocument dbxDoc = new AxDbDocument();
foreach (string Str in DwgList) {
dbxDoc.Open (Str, null);
using (WorkingDatabase wdb = new WorkingDatabase (Database.FromAcadDatabase (dbxDoc.Database))) {
using (Transaction wdbTrans = wdb.TransactionManager.StartTransaction()) {
BlockTable bt = (BlockTable) wdbTrans.GetObject (wdb.BlockTableId, OpenMode.ForRead);
foreach (ObjectId id in bt) {
BlockTableRecord btr = (BlockTableRecord) wdb.Trans.GetObject (id, OpenMode.ForRead);
DocEd.WriteMessage ("\n Block name: {0}", btr.Name);
}
}
}
}
}
}
}
Thanks in advance.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #8 on: August 30, 2006, 03:38:09 PM »
What about adding one line in your's code:
Code: [Select]
using CaddZone.DatabaseServices;

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #9 on: August 30, 2006, 03:42:23 PM »
I think I would have to have Tony's dll file, but I tried it anyway since I'm so lost here, and this is the error I got.
Quote
ODBX-Test.cs(17,7): error CS0246: The type or namespace name 'CaddZone' could not be found (are you missing a using directive or an assembly reference?)

Build complete -- 1 errors, 0 warnings
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #10 on: August 30, 2006, 03:46:11 PM »
I think I would have to have Tony's dll file, but I tried it anyway since I'm so lost here, and this is the error I got.
Include Tony's code (not dll) in your's cs-file and try again.
Your's code must looking like this:
Code: [Select]
using System;
using System.Collections;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop.Common;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(Test.odbxTest))]

namespace CaddZone.DatabaseServices
{
  class WorkingDatabase : IDisposable
  {
    public WorkingDatabase(Database db)
    {
      Database current = HostApplicationServices.WorkingDatabase;
      if (db != current)
      {
        m_Previous = current;
        HostApplicationServices.WorkingDatabase = db;
      }
      else
        GC.SuppressFinalize(this);
    }
    public Database Database()
    {
      return HostApplicationServices.WorkingDatabase;
    }
    ~WorkingDatabase()
    {
      Dispose(false);
    }

      #region IDisposable Members

    public void Dispose()
    {
      Dispose(true);
    }

      #endregion

    private bool disposed = false;
    private void Dispose(bool p)
    {
      if (!disposed)
      {
        Database current = HostApplicationServices.WorkingDatabase;
        if ( m_Previous != null && current != m_Previous)
          HostApplicationServices.WorkingDatabase = m_Previous;
        disposed = true;
        GC.SuppressFinalize(this);
      }
    }

    private Database m_Previous = null;

  }
}

namespace Test
{
  /// <summary>
  /// Description of Working.
  /// </summary>
  public class odbxTest
  {
    [CommandMethod ("dbxTest")]
    public void TestODBX()
    {
      Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
      Editor DocEd = Doc.Editor;
      Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud layer", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
      Dia.ShowDialog();
      string[] DwgList = Dia.GetFilenames();
      AxDbDocument dbxDoc = new AxDbDocument();
      foreach (string Str in DwgList)
      {
        dbxDoc.Open (Str, null);
        Database db = Database.FromAcadDatabase (dbxDoc.Database);
        using (CaddZone.DatabaseServices.WorkingDatabase wdb = new CaddZone.DatabaseServices.WorkingDatabase (db))
        {
          using (Transaction wdbTrans = db.TransactionManager.StartTransaction())
          {
            BlockTable bt = (BlockTable) wdbTrans.GetObject (db.BlockTableId, OpenMode.ForRead);
            foreach (ObjectId id in bt)
            {
              BlockTableRecord btr = (BlockTableRecord) wdbTrans.GetObject (id, OpenMode.ForRead);
              DocEd.WriteMessage ("\n Block name: {0}", btr.Name);
            }
          }
        }
      }
    }
  }
}
I've do not tested it but it was compiled without errors.
« Last Edit: August 30, 2006, 04:06:34 PM by Alexander Rivilis »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #11 on: August 30, 2006, 04:16:09 PM »
Thank you very much Alexander!!  I tried it, and was about to post saying it didn't work, but I say you posted more, and after testing it works great!

Thank you so much for posting your code also Tony!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #12 on: August 30, 2006, 05:54:52 PM »
I can't see to get this to work.

Question: When using the code provided, can I pass the database (db) to sub-functions? or do I have to try something else?

It looks like it might work, but I get an error when trying the command in Acad.  Here is the main part of the rouine.  If needs be I can post the whole code.

Thanks in advance for any help/tips on how to do this better.
Code: [Select]
public void UpdateRevStuff() {
      Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
      Editor DocEd = Doc.Editor;
      Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud layer", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
      Dia.ShowDialog();
      string[] DwgList = Dia.GetFilenames();
      AxDbDocument dbxDoc = new AxDbDocument();
foreach (string Str in DwgList) {
      dbxDoc.Open (Str, null);
      Database db = Database.FromAcadDatabase (dbxDoc.Database);
      using (CaddZone.DatabaseServices.WorkingDatabase wdb = new CaddZone.DatabaseServices.WorkingDatabase (db)) {
      if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
dbxDoc.Save();
}
      }
      }
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #13 on: August 30, 2006, 06:13:42 PM »
Question: When using the code provided, can I pass the database (db) to sub-functions? or do I have to try something else?
Yes. You can pass Database any function (really reference will be passed).
Quote
It looks like it might work, but I get an error when trying the command in Acad.  Here is the main part of the rouine.  If needs be I can post the whole code.
What error message? Are you trying to debug this code? Debugging maybe very usefull.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: ObjectDBX and Attributes
« Reply #14 on: August 30, 2006, 06:15:04 PM »
Just a quick guess, perhaps a Doclock may be required.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #15 on: August 30, 2006, 06:26:46 PM »
Question: When using the code provided, can I pass the database (db) to sub-functions? or do I have to try something else?
Yes. You can pass Database any function (really reference will be passed).
Quote
It looks like it might work, but I get an error when trying the command in Acad.  Here is the main part of the rouine.  If needs be I can post the whole code.
What error message? Are you trying to debug this code? Debugging maybe very usefull.
Attached are the error messages.  I tried to debug it, but it said I didn't have the right JIT version (I think), and then it just hung it up till I used task manager to end it.

Just a quick guess, perhaps a Doclock may be required.
I can try that Mick.  Thanks.  Will let you know...... It didn't work.  Got the same error, but I used it on the current drawing, is that correct?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #16 on: August 30, 2006, 06:34:59 PM »
How can I add an error function (for lack of better wording) like in Lisp so that I know where, or what is causing it to crash, so that I can debug it better?  I can select the drawings, but after that it crashes.  Thanks again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #17 on: August 30, 2006, 06:35:39 PM »
Got the same error, but I used it on the current drawing, is that correct?
IMHO yours code can not work with current drawing (or any other drawing opened in AutoCAD).
If you can not use debugger (I do not know why it is not installed), use any kind of dialog messages in order to localize place of error.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #18 on: August 30, 2006, 06:41:32 PM »
Got the same error, but I used it on the current drawing, is that correct?
IMHO yours code can not work with current drawing (or any other drawing opened in AutoCAD).
If you can not use debugger (I do not know why it is not installed), use any kind of dialog messages in order to localize place of error.
The code runs in the current drawing, I was talking about using the 'DocumentLock' that MickD was talking about.

I can throw in some stuff to see where it errors I guess.  I will post when I know something new.

Thanks again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #19 on: August 30, 2006, 06:54:44 PM »
It has to do with the save.  I will see if I can find anything out on the net.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: ObjectDBX and Attributes
« Reply #20 on: August 30, 2006, 07:00:34 PM »
If you're using Database.Save() then it doesn't seem to work.
You will have to use Database.Saveas()...found that out a while ago.

Hope this helps.

Cheers,
Glenn.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #21 on: August 30, 2006, 07:09:34 PM »
If you're using Database.Save() then it doesn't seem to work.
You will have to use Database.Saveas()...found that out a while ago.

Hope this helps.

Cheers,
Glenn.
I was trying to use dbxDoc.Save() and that doesn't seem to work, then I tried dbxDoc.SaveAs (dbxDoc.Name) but I need one more parm, but I'm not sure what to put.  In the ide it says that
Quote
public virtual void SaveAs(
 string FileName,
 object vSecurityParams
)
I then look at the 'SecurityParams' and didn't quite see something I would use.

Needless to say I'm a little lost here.

Thanks again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: ObjectDBX and Attributes
« Reply #22 on: August 30, 2006, 07:18:31 PM »
In times like these it helps to have a look at the arx api for a bit of guidence.
Quote
To specify security parameters, set pSecurity to point to a SecurityParams struct that conveys your preferences. If pSecurity is non-NULL, its settings override any previous database security settings. If pSecurity is NULL, any currently enforced security settings remain in effect. If no previous security-related settings were specified, and pSecurity is NULL, no security-related operation is attempted. If the SecurityParams struct passed as the pSecurity argument is not properly initialized, the method fails. See SecurityParams for more information on initializing this struct.

So, with that I'd try a 'null' or SystemType.Missing (or what ever it is :) )
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #23 on: August 30, 2006, 07:32:28 PM »
In times like these it helps to have a look at the arx api for a bit of guidence.
Quote
To specify security parameters, set pSecurity to point to a SecurityParams struct that conveys your preferences. If pSecurity is non-NULL, its settings override any previous database security settings. If pSecurity is NULL, any currently enforced security settings remain in effect. If no previous security-related settings were specified, and pSecurity is NULL, no security-related operation is attempted. If the SecurityParams struct passed as the pSecurity argument is not properly initialized, the method fails. See SecurityParams for more information on initializing this struct.

So, with that I'd try a 'null' or SystemType.Missing (or what ever it is :) )
null didn't work, and neither did SystemType.Missing.  I also tried something I found on the adesk ng, but that didn't work either (it was)
Code: [Select]
dbxDoc.SaveAs (dbxDoc.Name, new Autodesk.AutoCAD.DatabaseServices.SecurityParameters());
Then I tried this, because I'm using ObjectDBX
Code: [Select]
dbxDoc.SaveAs (dbxDoc.Name, new Autodesk.AutoCAD.Interop.Common.SecurityParams());
With no luck either.  I added a message box right before the save, and it displays, so I'm sure it's the save.

Thanks for all the effort guys.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: ObjectDBX and Attributes
« Reply #24 on: August 30, 2006, 07:50:36 PM »
If you tried SystemType.Missing then that won't work.
It should be System.Type.Missing.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #25 on: August 31, 2006, 11:10:29 AM »
If you tried SystemType.Missing then that won't work.
It should be System.Type.Missing.
Thanks Glenn, but it didn't work either.  It compiled with that, but didn't work.  Still looking.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: ObjectDBX and Attributes
« Reply #26 on: August 31, 2006, 03:12:30 PM »
FileType is the second argument.  SecurityParam is optional. 

File Types are:

ac2000_dwg
 AutoCAD 2000 DWG (*.dwg)
 
ac2000_dxf
 AutoCAD 2000 DXF (*.dxf)
 
ac2000_Template
 AutoCAD 2000 Drawing Template File (*.dwt)
 
ac2004_dwg
 AutoCAD 2004 DWG (*.dwg)
 
ac2004_dxf
 AutoCAD 2004 DXF (*.dxf)
 
ac2004_Template
 AutoCAD 2004 Drawing Template File (*.dwt)
 
acNative
 A synonym for the latest drawing release. In this release, this value equals ac2004_dwg.
 
James Buzbee
Windows 8

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #27 on: August 31, 2006, 03:29:04 PM »
How would you use it?  I tried
dbxDoc.SaveAs (dbxDoc.Name, ac2004_dwg);
and it wouldn't complie, so then I tried it as a string, and got the same error.

Man this is frustrating, so close, but can't cross the finish line.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: ObjectDBX and Attributes
« Reply #28 on: August 31, 2006, 03:40:37 PM »

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: ObjectDBX and Attributes
« Reply #29 on: August 31, 2006, 03:45:41 PM »
Sorry for the confusion: ac2004_dwg is the activex constant.  I havn't tried this in .net but as long as your referencing the AxDb1#.dll I would think it should work?  

My only other thought would be the first argument is the name only: "MyDrawing" and the second argument as a string ".dwg" ??? Just purely guessing here . . ..
James Buzbee
Windows 8

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #30 on: August 31, 2006, 03:55:55 PM »
The problem is that those talk about closing/saving the current drawing, which is different that closing a drawing opened with ObjectDBX in .Net.  The attached images show the different methods and what is need per the two.  Thanks for trying.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #31 on: August 31, 2006, 03:58:36 PM »
Sorry for the confusion: ac2004_dwg is the activex constant.  I havn't tried this in .net but as long as your referencing the AxDb1#.dll I would think it should work? 

My only other thought would be the first argument is the name only: "MyDrawing" and the second argument as a string ".dwg" ??? Just purely guessing here . . ..
I'm willing to try anything almost, but this didn't work either.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #32 on: August 31, 2006, 04:11:02 PM »
[I'm willing to try anything almost, but this didn't work either.  :-)
I think problem not in second parameter of dbxDoc.SaveAs() function. Problem is that this drawing is now  current (e.g. WorkingDatabase).
Try to dbxDoc.SaveAs()  after using (WorkingDatabase ...) block.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #33 on: August 31, 2006, 04:57:07 PM »
[I'm willing to try anything almost, but this didn't work either.  :-)
I think problem not in second parameter of dbxDoc.SaveAs() function. Problem is that this drawing is now  current (e.g. WorkingDatabase).
Try to dbxDoc.SaveAs()  after using (WorkingDatabase ...) block.

AND THE WINNER IS ALEXANDER RIVILIS!!!!
Doing this, and using what Tony told me on the adesk ng site worked.  Thank you so much!
Code: [Select]
public void UpdateRevStuff() {
      Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
      Editor DocEd = Doc.Editor;
      //using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()) {
      Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud layer", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
      Dia.ShowDialog();
      string[] DwgList = Dia.GetFilenames();
      AxDbDocument dbxDoc = new AxDbDocument();
      foreach (string Str in DwgList) {
        dbxDoc.Open (Str, null);
        Database db = Database.FromAcadDatabase (dbxDoc.Database);
        using (CaddZone.DatabaseServices.WorkingDatabase wdb = new CaddZone.DatabaseServices.WorkingDatabase (db)) {
      if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
MessageBox.Show ("Right before save.");
//dbxDoc.SaveAs (dbxDoc.Name);
//Marshal.ReleaseComObject (dbxDoc);

}
      }
      }
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
Marshal.ReleaseComObject (dbxDoc);
}
 //}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #34 on: August 31, 2006, 05:01:42 PM »
Side note:  The attribute updated correclty also, so you can use ObjectDBX with .Net and attributes.  Good news!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ObjectDBX and Attributes
« Reply #35 on: August 31, 2006, 05:05:20 PM »
aside from the technical issues Tim, that looks like an interesting project.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #36 on: August 31, 2006, 05:10:44 PM »
aside from the technical issues Tim, that looks like an interesting project.
If you think it is of intrest I can post the whole code.

I posted the finished code to soon.  I release the dbxDoc to soon in the first code I posted.  Here is the correct on, which also writes to the current documents command line saying which ones got updated and which ones didn't

Code: [Select]
public void UpdateRevStuff() {
      Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
      Editor DocEd = Doc.Editor;
      Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud layer", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
      Dia.ShowDialog();
      string[] DwgList = Dia.GetFilenames();
      AxDbDocument dbxDoc = new AxDbDocument();
    foreach (string Str in DwgList) {
  bool ShouldSave = false;
        dbxDoc.Open (Str, null);
      Database db = Database.FromAcadDatabase (dbxDoc.Database);
      using (CaddZone.DatabaseServices.WorkingDatabase wdb = new CaddZone.DatabaseServices.WorkingDatabase (db)) {
      if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
ShouldSave = true;
//MessageBox.Show ("Right before save.");

}
      }
      }
      if (ShouldSave == true) {
      DocEd.WriteMessage ("\n Saving file {0}", dbxDoc.Name);
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
      }
else {
DocEd.WriteMessage ("\n ++ Not saving file {0}", dbxDoc.Name);
}
}
Marshal.ReleaseComObject (dbxDoc);
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #37 on: August 31, 2006, 05:59:50 PM »
Even better.  Now you can save the origianl thumbnail preview of the drawing.  Here is the code portion I changed to do so.
Code: [Select]
if (ShouldSave == true) {
db.RetainOriginalThumbnailBitmap = true;  // Added line.
DocEd.WriteMessage ("\n Saving file {0}", dbxDoc.Name);
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
}

THANKS AGAIN TO ALL WHO HELPED ME COMPLETE THIS!!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ObjectDBX and Attributes
« Reply #38 on: August 31, 2006, 06:19:51 PM »
Even better.  Now you can save the original thumbnail preview of the drawing.  Here is the code portion I changed to do so.
Code: [Select]
///

That alone is worth the price of admission
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: ObjectDBX and Attributes
« Reply #39 on: September 01, 2006, 02:59:50 AM »
AND THE WINNER IS ALEXANDER RIVILIS!!!!
:) And what about not using AxDbDocument? AFAIK You can do the same with Database.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ObjectDBX and Attributes
« Reply #40 on: September 01, 2006, 11:02:51 AM »
AND THE WINNER IS ALEXANDER RIVILIS!!!!
:) And what about not using AxDbDocument? AFAIK You can do the same with Database.
I thought I had to when using ObjectDBX.  If not then I can change it if it works.  Is there a draw back to using one over the other?

Thanks again Alexander.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.