Author Topic: Cell styles in TableStyle...  (Read 21463 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: Cell styles in TableStyle...
« Reply #15 on: July 25, 2010, 12:01:43 PM »
just tried (have been a long time, since I did something for a table object)... using a Kean existing sample in his site, I can modify the cells with an existing cell type.

http://through-the-interface.typepad.com/through_the_interface/2008/11/creating-a-cust.html
Code: [Select]
tb.Cells[i, j].Style = "Header";
Have not tried to add a new one, but guess that has to be based on an existing one and change it from there...

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Cell styles in TableStyle...
« Reply #16 on: July 25, 2010, 01:15:56 PM »
With this one can add a cellstyle, delete a cellstyle, set the textstyle for a cellstyle.
It requires you to add some textstyles and a tablestyle
1) Apparantly it is impossible (whatever you do don't actually try it)
2) It probably is no use to the OP , as it is in no way what he wanted.
3) Who wants to use interop anyway.

Code: [Select]
       [CommandMethod("tts")]
        public static void TableStyleTest()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            string tableStyleName = "YourTableStyle";

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TableStyle tableStyle;
                DBDictionary dic = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
                foreach (DictionaryEntry eDict in dic)
                {
                    tableStyle = tr.GetObject
                        ((ObjectId)eDict.Value, OpenMode.ForRead) as TableStyle;
                    if (tableStyle.Name == tableStyleName)
                    {
                        tableStyle.UpgradeOpen();

                        ArrayList ca = tableStyle.CellStyles;
                        interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
                        object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId);
                        interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;

                        TextStyleTable textstyletable=tr.GetObject
                            (db.TextStyleTableId,OpenMode.ForRead) as TextStyleTable;
                        object ob2 = Ap.ActiveDocument.ObjectIdToObject(textstyletable.ObjectId.OldId);
                        interop.Common.IAcadTextStyles tss = ob2 as interop.Common.IAcadTextStyles;
                      
                      
                        if(ca.Contains("U1")) ts.DeleteCellStyle("U1");
                        ts.CreateCellStyle("U1");
                        ts.SetCellClass("U1", 1);
                        if (ca.Contains("U2")) ts.DeleteCellStyle("U2");
                        ts.CreateCellStyle("U2");
                        ts.SetCellClass("U2", 2);
                        if (ca.Contains("U3")) ts.DeleteCellStyle("U3");
                        ts.CreateCellStyle("U3");
                        ts.SetCellClass("U3", 3);

                        ed.WriteMessage(tss.Item("User1").ObjectID.ToString());
                        if(textstyletable.Has("User1"))
                            ts.SetTextStyleId("U1", tss.Item("User1").ObjectID);

                        if (textstyletable.Has("User2"))
                            ts.SetTextStyleId("U2", tss.Item("User2").ObjectID);

                        if (textstyletable.Has("User3"))
                            ts.SetTextStyleId("U3", tss.Item("User3").ObjectID);
                    }

                }
                tr.Commit();
            }
            
        } // end TableStyleTest

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Cell styles in TableStyle...
« Reply #17 on: July 25, 2010, 01:57:30 PM »
With this one can add a cellstyle, delete a cellstyle, set the textstyle for a cellstyle.
It requires you to add some textstyles and a tablestyle
1) Apparantly it is impossible (whatever you do don't actually try it)
2) It probably is no use to the OP , as it is in no way what he wanted.
3) Who wants to use interop anyway.

Code: [Select]
       [CommandMethod("tts")]
        public static void TableStyleTest()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            string tableStyleName = "YourTableStyle";

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TableStyle tableStyle;
                DBDictionary dic = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
                foreach (DictionaryEntry eDict in dic)
                {
                    tableStyle = tr.GetObject
                        ((ObjectId)eDict.Value, OpenMode.ForRead) as TableStyle;
                    if (tableStyle.Name == tableStyleName)
                    {
                        tableStyle.UpgradeOpen();

                        ArrayList ca = tableStyle.CellStyles;
                        interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
                        object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId);
                        interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;

                        TextStyleTable textstyletable=tr.GetObject
                            (db.TextStyleTableId,OpenMode.ForRead) as TextStyleTable;
                        object ob2 = Ap.ActiveDocument.ObjectIdToObject(textstyletable.ObjectId.OldId);
                        interop.Common.IAcadTextStyles tss = ob2 as interop.Common.IAcadTextStyles;
                      
                      
                        if(ca.Contains("U1")) ts.DeleteCellStyle("U1");
                        ts.CreateCellStyle("U1");
                        ts.SetCellClass("U1", 1);
                        if (ca.Contains("U2")) ts.DeleteCellStyle("U2");
                        ts.CreateCellStyle("U2");
                        ts.SetCellClass("U2", 2);
                        if (ca.Contains("U3")) ts.DeleteCellStyle("U3");
                        ts.CreateCellStyle("U3");
                        ts.SetCellClass("U3", 3);

                        ed.WriteMessage(tss.Item("User1").ObjectID.ToString());
                        if(textstyletable.Has("User1"))
                            ts.SetTextStyleId("U1", tss.Item("User1").ObjectID);

                        if (textstyletable.Has("User2"))
                            ts.SetTextStyleId("U2", tss.Item("User2").ObjectID);

                        if (textstyletable.Has("User3"))
                            ts.SetTextStyleId("U3", tss.Item("User3").ObjectID);
                    }

                }
                tr.Commit();
            }
            
        } // end TableStyleTest

Bryco,
Look my previous message: "Reply #11 on: Today at 05:05:31 am".
I ask again:
Out whence in your code this methods: SetCellClass, CreateCellStyle, SetTextStyleId and DeleteCellStyle?
I even show screen (may be it was more understandable):



Is it your extension methods?
Why you use OldId property in your code?
« Last Edit: July 25, 2010, 02:04:34 PM by Hwd »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Cell styles in TableStyle...
« Reply #18 on: July 25, 2010, 02:12:15 PM »
just tried (have been a long time, since I did something for a table object)... using a Kean existing sample in his site, I can modify the cells with an existing cell type.

http://through-the-interface.typepad.com/through_the_interface/2008/11/creating-a-cust.html
Code: [Select]
tb.Cells[i, j].Style = "Header";
Have not tried to add a new one, but guess that has to be based on an existing one and change it from there...

I know about this topic, and I read it before my topic was created. You can read my message in Kean Walmsley comments (July 22, 2010 at 04:40 PM).

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Cell styles in TableStyle...
« Reply #19 on: July 25, 2010, 02:47:31 PM »
Hwd,
I tested Bryco's code here on Acad2010 and it works fine. So, what version are you trying to use this with?

Also, I'm not sure when this was added to the .NET API, but this code (which you had asked about)
Code: [Select]
                        object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId);
                        interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;

can now be condensed to:
Code: [Select]
                        interop.Common.IAcadTableStyle ts = tableStyle.AcadObject as interop.Common.IAcadTableStyle;
The reason he had used the OldId to get the COM object, is because .NET & COM use 2 different ObjectId's.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Cell styles in TableStyle...
« Reply #20 on: July 25, 2010, 02:49:28 PM »
Add the references you need. I have both Autodac and AxdbLib.
Your on your own now, I think Fox News is hiring though.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Cell styles in TableStyle...
« Reply #21 on: July 25, 2010, 02:52:47 PM »
Oh, that's good to know Jeff

LE3

  • Guest
Re: Cell styles in TableStyle...
« Reply #22 on: July 25, 2010, 03:13:28 PM »
Add the references you need. I have both Autodac and AxdbLib.
Your on your own now, I think Fox News is hiring though. ???? woot?
nice solution Bryco, thanks!.... tried here via normal .net and appears to no way.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Cell styles in TableStyle...
« Reply #23 on: July 25, 2010, 03:34:32 PM »
Thanks

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Cell styles in TableStyle...
« Reply #24 on: July 25, 2010, 04:41:47 PM »
So, what version are you trying to use this with?
I use AutoCAD 2009 x64 SP3 Enu.
Quote
The reason he had used the OldId to get the COM object, is because .NET & COM use 2 different ObjectId's.

Thank you. When I must use OldId?
Quote
Add the references you need. I have both Autodac and AxdbLib.
Thank you. My project has some references, and I can't add new reference on AxdbLib.

AxdbLib is AcAxDb17enures.dll?
Autodac (may be Autocad?) is acax17enu.tbl?
I show screen my problem:



Visual Studio 2010 not cry when I use other Autodesk.AutoCAD.Interop.Common.IAcadTextStyles interface methods.
But Visual Studio 2010 cry when I use methods, whish Bryco show me. Therefore I was think, what problem not in reference. I am mistaken?

Quote
Your on your own now, I think Fox News is hiring though.
I translate this suggestion, but I can't understand it.
I did not wish to offend anybody. If Bryco has taken offence - I ask excuse me.


Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Cell styles in TableStyle...
« Reply #25 on: July 25, 2010, 11:30:34 PM »
You do not need to reference the Autodesk.AutoCAD.Interop.Common.

You need to reference the axdb17enu.tlb (the last one shown in the Browse dialog). You should be able to see this in the COM listings as "AutoCAD/ObjectDBX Common 17.0 Type Library". With this, and the AutoCAD reference you already have, these are the only 2 required to access most, in not all, AutoCAD Interop objects, methods & properties.

The OldId is used when combining the use of .NET and COM objects, just as Bryco showed for getting a .NET object's COM counterpart. That's about the extent of my ability to explain this. Perhaps some one else can do a better or more thorough job.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Cell styles in TableStyle...
« Reply #26 on: July 26, 2010, 12:06:21 AM »
You'll probably need to add there using statements also.

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using interop = Autodesk.AutoCAD.Interop;


I think a lot of the problems associated with attempting to resolve .NET problems is not having sufficient information.
Perhaps if we posted a zipped 'Solution' of all files for others to test some of the problems could be resolved earlier.

Sometimes it takes longer to find out what is missing than it does to resolve an actual problem .... and not all of us can make time to spare to become involved.
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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Cell styles in TableStyle...
« Reply #27 on: July 26, 2010, 01:17:25 AM »
You do not need to reference the Autodesk.AutoCAD.Interop.Common.

You need to reference the axdb17enu.tlb (the last one shown in the Browse dialog). You should be able to see this in the COM listings as "AutoCAD/ObjectDBX Common 17.0 Type Library". With this, and the AutoCAD reference you already have, these are the only 2 required to access most, in not all, AutoCAD Interop objects, methods & properties.

The OldId is used when combining the use of .NET and COM objects, just as Bryco showed for getting a .NET object's COM counterpart. That's about the extent of my ability to explain this. Perhaps some one else can do a better or more thorough job.

Thank you!
When I use Windoxs XP x86 SP3 Professional, and AutoCAD 2009 x86 SP3 Enu - then I see "AutoCAD/ObjectDBX Common 17.0 Type Library" on COM tab.
But when I use Windoxs 7 x64 Ultimate, and AutoCAD 2009 x64 SP3 Enu - then I not see "AutoCAD/ObjectDBX Common 17.0 Type Library" on COM tab.
Screen:



"AutoCAD/ObjectDBX Common 17.0 Type Library" is absent for my x64.

Quote
Perhaps if we posted a zipped 'Solution' of all files for others to test some of the problems could be resolved earlier.

Sometimes it takes longer to find out what is missing than it does to resolve an actual problem .... and not all of us can make time to spare to become involved.

Thank you. Zipped 'Solution'.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Cell styles in TableStyle...
« Reply #28 on: July 26, 2010, 01:45:59 AM »
OK, my apologies. It looks like the "AutoCAD/ObjectDBX Common 17.0 Type Library" actually does point to "Autodesk.AutoCAD.Interop.Common.dll", so that should have been all you needed.

I don't have plain AutoCAD 2009, nor to I have VS2010 so I can't help with the posted file. I hope someone can get this sorted out for you.

Good Luck!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Cell styles in TableStyle...
« Reply #29 on: July 26, 2010, 02:40:19 AM »

The only option I have for testing on this box is MSVS2010 with AC2011.

Opened the solution,
Re-linked the references,
Set the ACAD.EXE version in Project Properties,
Built the debug dll

loaded into AutoCAD and ran without error

A piccy:
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.