TheSwamp

Code Red => .NET => Topic started by: Jeff H on November 26, 2014, 03:20:06 AM

Title: Screw it I give up
Post by: Jeff H on November 26, 2014, 03:20:06 AM
PLEASE READ
Please let me know if interested, and if not I will not waste my time because this a very tiny portion and there is much more but just started with this because I had to start somewhere. If people are interested I will continue to add more and more each day except for this week because it is Thanksgiving.
All I ask is if you notice something please point it out, and if you have a better approach or insight please share, which I'm sure many of you do.

The code and links to download project template are in attached files and are created using Markdownpad 2 (http://markdownpad.com/) which can be viewed with any internet browser. Please let me know if it makes it easier to read and understand or suggest a better method.
Again this is just a initial test to see if anyone is interested so I know if it is worth spending the time to explain and post, and also figuring out a good way to provide and explain it so its easy to use and understand.
With that said or actually typed.


I am tired of fighting a unwinnable battle, and I will not go into it, but

I will be posting a bunch a stuff that I use daily and has worked for a years consistently.
For example
Here are 2 tools built recently using code that each took less than 30 mins to create and have work great.

This is like MEP add device window where basically you point this to a folder with Block Library files and use it to insert blocks
(http://i1221.photobucket.com/albums/dd473/Jeffrey_H/ibwindow_zps167069a8.png)

This one is so you can edit all attributes at one time for a certain block, and also copy to clipboard to paste in excel, wblock out, zoom to each one, and does not lock drawing UI so can still edit drawing it becomes disabled if drawing is not active or closes if drawing closes. That is easily handled by PerDocData class that is mentioned in attached files.
(http://i1221.photobucket.com/albums/dd473/Jeffrey_H/attaboy_zps3fcb0496.png)


Attached are three html files to get this started

1 - Default Project.html - contains a quick overview of project setup and a link to download a solution set-up with references and structure, etc....
2 - Getting SymbolTablesRecords.html - This is just getting set up for iterating SymbolTables and getting SymbolTablesRecords and some other points like  if  Dependent Records are not needed how dependency can be determined without opening the object and just using the Objectid properties.
3 - AcCoreMgdExtensions intial.html - Contains intial setup for easier writng to commandline and creating CommandClasses and data associated.


Before it gets too deep I think I have an idea how to handle Transactions better, so they can be used easily and not worry if from Document, Database, a Side Database, Transaction or OpenCloseTransaction, etc....
Title: Re: Screw it I give up
Post by: Keith Brown on November 26, 2014, 07:02:57 AM
Thanks for sharing Jeff!


I like the use of the .html files for viewing and explaining what you are doing.  It also makes it easier to copy/paste code.


Keep them coming!
Title: Re: Screw it I give up
Post by: Kerry on November 26, 2014, 07:53:31 AM
Jeff,
Have you tried this.
Works in VS 2013

https://visualstudiogallery.msdn.microsoft.com/98fef791-eb65-4cdf-bf84-077b98c234cf


ADDED:
That may not be the correct one.
There are a couple of add-ons that do a HTML Markup direct from selected code in the VS IDE.


This is the result ...

Title: Re: Screw it I give up
Post by: Jeff_M on November 26, 2014, 10:19:19 AM
Thanks, Jeff! Sure wish I had something like this when I first decided to start using c#. And even after all this time, I am still learning from your posts!
Title: Re: Screw it I give up
Post by: JohnK on November 26, 2014, 10:31:05 AM
...
There are a couple of add-ons that do a HTML Markup direct from selected code in the VS IDE.
...

Why not use DoxyGen?
http://www.doxygen.org

Good link: http://stackoverflow.com/questions/2028264/visual-studio-with-doxygen-for-documentation-or-should-we-use-something-else
Title: Re: Screw it I give up
Post by: BlackBox on November 26, 2014, 10:54:29 AM
Thank you, Jeff.

The amount of time and effort you put into tasks like this, that help others, is greatly appreciated.

I've only had a chance to skim some of this (seriously, WTF is it with deadlines before Thanksgiving!? Reviewers are already gone on vacation, and nobody will look at the plans for a week. :roll: ), but it looks to be very useful as I continue to learn .NET generally, and C# specifically. :redbull: (too early for beer here; drink'em if you got'em)

Cheers
Title: Re: Screw it I give up
Post by: CADbloke on November 30, 2014, 11:23:10 PM
Thanks Jeff, there's a mountain of experience and toil in there, your efforts and generosity are much-appreciated. Count me in as interested. Would you consider posting the code to a Git/Hg repo so we can send you pull-requests for updates?

I've really got to tidy up my library stuff and post it here too, some day soon. I should also post some of my unit-testing stuff too (I'm typing this here as a note-to-self and as a commitment to actually do it).

For Visual Studio docs I use Atomineer (http://www.atomineerutils.com/).

cheers
Ewen
Title: Re: Screw it I give up
Post by: Jeff H on December 01, 2014, 04:22:52 AM
Markdown (http://en.wikipedia.org/wiki/Markdown) is not only for html but can be converted to pdf and many other formats.
Quote
Markdown is a plain text formatting syntax designed so that it can be converted to HTML (http://en.wikipedia.org/wiki/HTML) and many other formats using a tool by the same name. Markdown is often used to format readme files (http://en.wikipedia.org/wiki/README), for writing messages in online discussion forums, and to create rich text (http://en.wikipedia.org/wiki/Formatted_text) using a plain text (http://en.wikipedia.org/wiki/Plain_text) editor (http://en.wikipedia.org/wiki/Text_editor).
MarkdownPad 2 is just an editor that makes the processes easier to use.
For example in MarkDown
#Heading1#(Optional to add to the end)
##Heading2##
###Heading3###
**Bold
I looked at forums for SMF and looks like they have no plans to adopt the ability to include MarkDown. If they did you could format your post like attached files.

Reading your post now makes me think I being a little stoopid and should use something that could be integrated with code for documentation. Right now its completely separated making it a pain to manage. For example the very USEFUL geometry extensions by gile(thanks again gile) but can't remember what he used but he mentions it in an post here that I will look for.
So we got
http://www.doxygen.org (http://www.doxygen.org)
Atomineer (http://www.atomineerutils.com/)
https://visualstudiogallery.msdn.microsoft.com/98fef791-eb65-4cdf-bf84-077b98c234cf (https://visualstudiogallery.msdn.microsoft.com/98fef791-eb65-4cdf-bf84-077b98c234cf)
http://sandcastle.codeplex.com/ (http://sandcastle.codeplex.com/)

 
As far as GitHub, the actually library and AddinLoader that loads it, etc.. are in a repository on GitHub, my plans were to get some feedback on project setup along with a couple other things and refactor some things out to make it more "community friendly". Once that straighten out then make it public or maybe keep it private and PM me email address associated with github account and add anyone who wants to join and some others for the different roles. The second way would be to keep a more of a "Swamp" project.
 
Unless Autodesk builds a tool for it and is maintained I can not honestly ever see Unit-testing for AutoCAD becoming reality other than someone spending a huge amount of time just to find out it will take a huge amount to maintain and spend a huge amount of time to update each year.
The examples I have seen have been so narrowed in just to show a example of how it can be achieved, have made think holy sh*t that would be so much work to create a platform that would be useful.
Title: Re: Screw it I give up
Post by: JohnK on December 01, 2014, 08:26:36 AM
Would a "new project wizard" be of any use to this effort? ...My folder structure is a bit abnormal so I built myself a nice little wizard to create all the new project stuff (directories, README files, CMake files, classes, implementation files, etc.) I could build a similar wizard for the effort.
Title: Re: Screw it I give up
Post by: Jeff H on December 01, 2014, 12:17:29 PM
Would a "new project wizard" be of any use to this effort? ...My folder structure is a bit abnormal so I built myself a nice little wizard to create all the new project stuff (directories, README files, CMake files, classes, implementation files, etc.) I could build a similar wizard for the effort.
That would be awesome and here's a wizard with many options that freely available.
http://spiderinnet1.typepad.com/

Title: Re: Screw it I give up
Post by: Jeff H on December 01, 2014, 12:23:37 PM
Adding this to get closer to start seeing some actual examples might use in real world situations, but still needs more.

But the attached file is for
Setting Environment Variables
Setting System Variables
Temporarily Setting System Variables and reverting back to initial value.
Adding, removing, inserting SupportPaths, ToolPalettes, etc as if they were a collection and not a string with paths separated with ";"

Title: Re: Screw it I give up
Post by: Kerry on December 01, 2014, 12:29:12 PM
...
There are a couple of add-ons that do a HTML Markup direct from selected code in the VS IDE.
...

Why not use DoxyGen?
http://www.doxygen.org

Good link: http://stackoverflow.com/questions/2028264/visual-studio-with-doxygen-for-documentation-or-should-we-use-something-else


I had the idea that the html of the code could be used in your html to display coloured formatting.

//-------------------------------------------

Would a "new project wizard" be of any use to this effort? ...My folder structure is a bit abnormal so I built myself a nice little wizard to create all the new project stuff (directories, README files, CMake files, classes, implementation files, etc.) I could build a similar wizard for the effort.
That would be awesome and here's a wizard with many options that freely available.
http://spiderinnet1.typepad.com/

spiderinnet may need some encouragement to update the wizard for current AutoCAD builds.
Title: Re: Screw it I give up
Post by: JohnK on December 01, 2014, 01:42:00 PM
...

Would a "new project wizard" be of any use to this effort? ...My folder structure is a bit abnormal so I built myself a nice little wizard to create all the new project stuff (directories, README files, CMake files, classes, implementation files, etc.) I could build a similar wizard for the effort.
That would be awesome and here's a wizard with many options that freely available.
http://spiderinnet1.typepad.com/

spiderinnet may need some encouragement to update the wizard for current AutoCAD builds.
humm... Good point Kerry. I'll need to build a wizard that can read a "recipe"--of sorts-; that way only the recipe (and the few associated files) can/needs to be updated. Not to mention, many recipes can be built for several different conditions (which is a plus). I have a few big areas of concern right now so I will put my thinking cap on.

...I think I have may have just grabbed a tiger by the tail. :)
Title: Re: Screw it I give up
Post by: JohnK on December 01, 2014, 01:59:37 PM
That spiderinnet wizard looks like it's a VS addon. I was thinking of a standalone exe file. Is that a deal breaker?
Title: Re: Screw it I give up
Post by: Keith Brown on December 01, 2014, 03:56:54 PM
It wouldn't be a deal breaker for me.  If you could start visual studio and load the project in a stand alone would the be much difference?
Title: Re: Screw it I give up
Post by: JohnK on December 02, 2014, 12:36:38 PM
I created a C++ project for me to start coding some of my ideas. Right now, it is a command line utility (run by double clicking .bat files) but I do plan on creating a GUI for it once I get past some of the road blocks I foresee.

So far most of what I have done is "project setup" (build files, tests, documentation, etc.). However I do have some code already though; I took some code from some other projects. As it stands now, what builds is an EXE, two DLLs and three test cases. All three tests technically fail at this point but I will let you all know when I get them working and a useful distribution.

The project is being hosted on Visual Studio Online (I plan to support building with Clang, MinGW and Visual Studio compilers) so that means the Visual Studio Project Solution will be a supplementary file (used for building with VS only) and I will be coding this the Unix way (Text editor and CMakeList files). Invites to join the project in a bit (I will need a lot of help later). I also plan on getting online builds running for this project (I really want to test this feature out).

The name of this project is: "JaSP" and it stands for (I thought this was funny): "Just a Simple Project". I choose the name because this project, for me, is getting BIG fast and it will/should be able to create a project from simple to complicated based on the `recipe' used.

:)
Title: Re: Screw it I give up
Post by: Jeff H on December 04, 2014, 01:14:04 PM
Sorry default project in  link of html file in first post was all screwed up and no idea what happened but updated so it already downloaded just re-download.
Title: Re: Screw it I give up
Post by: Jeff H on December 04, 2014, 02:37:04 PM
Here is default project to download directly
Title: Re: Screw it I give up
Post by: CADbloke on December 07, 2014, 04:32:01 PM
Briefly because OFF-TOPIC! html-formatted code copy is part of the Productivity Power Tools (https://visualstudiogallery.msdn.microsoft.com/dbcb8670-889e-4a54-a226-a48a15e4cace) Visual Studio plugin. That plugin has lots of cool things BTW.
Title: Re: Screw it I give up
Post by: Jeff H on August 01, 2015, 12:19:40 AM
Database

Code - C#: [Select]
  1. using Autodesk.AutoCAD.Runtime;
  2. using System;
  3. namespace Autodesk.AutoCAD.DatabaseServices
  4. {
  5.     public static class DatabaseExtensions
  6.     {
  7.         private static string standard = "Standard";
  8.  
  9.         public static BlockTable BlockTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  10.         {
  11.             if (trx == null)
  12.             {
  13.                 throw new NoActiveTransactionException("No active Transaction");
  14.             }
  15.              return (BlockTable)trx.GetObject(db.BlockTableId, mode, false, false);
  16.         }
  17.  
  18.  
  19.         public static BlockTable BlockTable(this Database db, OpenMode mode = OpenMode.ForRead)
  20.         {
  21.             return db.BlockTable(db.TransactionManager.TopTransaction, mode);
  22.         }
  23.  
  24.  
  25.         public static DimStyleTable DimStyleTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  26.         {
  27.             if (trx == null)
  28.             {
  29.                 throw new NoActiveTransactionException("No active Transaction");
  30.             }
  31.             return (DimStyleTable)trx.GetObject(db.DimStyleTableId, mode, false, false);
  32.         }
  33.  
  34.  
  35.         public static DimStyleTable DimStyleTable(this Database db, OpenMode mode = OpenMode.ForRead)
  36.         {
  37.             return db.DimStyleTable(db.TransactionManager.TopTransaction, mode);
  38.         }
  39.  
  40.  
  41.  
  42.         public static LayerTable LayerTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  43.         {
  44.             if (trx == null)
  45.             {
  46.                 throw new NoActiveTransactionException("No active Transaction");
  47.             }
  48.             return (LayerTable)trx.GetObject(db.LayerTableId, mode, false, false);
  49.         }
  50.  
  51.  
  52.         public static LayerTable LayerTable(this Database db, OpenMode mode = OpenMode.ForRead)
  53.         {
  54.             return db.LayerTable(db.TransactionManager.TopTransaction, mode);
  55.         }
  56.  
  57.         public static LinetypeTable LinetypeTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  58.         {
  59.             if (trx == null)
  60.             {
  61.                 throw new NoActiveTransactionException("No active Transaction");
  62.             }
  63.             return (LinetypeTable)trx.GetObject(db.LinetypeTableId, mode, false, false);
  64.         }
  65.  
  66.  
  67.         public static LinetypeTable LinetypeTable(this Database db, OpenMode mode = OpenMode.ForRead)
  68.         {
  69.             return db.LinetypeTable(db.TransactionManager.TopTransaction, mode);
  70.         }
  71.  
  72.  
  73.  
  74.         public static RegAppTable RegAppTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  75.         {
  76.             if (trx == null)
  77.             {
  78.                 throw new NoActiveTransactionException("No active Transaction");
  79.             }
  80.             return (RegAppTable)trx.GetObject(db.RegAppTableId, mode, false, false);
  81.         }
  82.  
  83.  
  84.         public static RegAppTable RegAppTable(this Database db, OpenMode mode = OpenMode.ForRead)
  85.         {
  86.             return db.RegAppTable(db.TransactionManager.TopTransaction, mode);
  87.         }
  88.  
  89.  
  90.  
  91.         public static TextStyleTable TextStyleTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  92.         {
  93.             if (trx == null)
  94.             {
  95.                 throw new NoActiveTransactionException("No active Transaction");
  96.             }
  97.             return (TextStyleTable)trx.GetObject(db.TextStyleTableId, mode, false, false);
  98.         }
  99.  
  100.  
  101.         public static TextStyleTable TextStyleTable(this Database db, OpenMode mode = OpenMode.ForRead)
  102.         {
  103.             return db.TextStyleTable(db.TransactionManager.TopTransaction, mode);
  104.         }
  105.  
  106.         public static ObjectId StandardTextStyle(this Database db)
  107.         {
  108.           return  SymbolUtilityServices.GetTextStyleStandardId(db);
  109.         }
  110.  
  111.  
  112.         public static ObjectId ContinuousLinetypeId(this Database db)
  113.         {
  114.             return SymbolUtilityServices.GetLinetypeContinuousId(db);
  115.         }
  116.  
  117.         public static ObjectId StandardDimStyle(this Database db, Transaction trx)
  118.         {
  119.             var dimtbl = db.DimStyleTable(trx);
  120.             return dimtbl.Has(standard) ? dimtbl[standard] : db.Dimstyle;
  121.         }
  122.  
  123.         public static ObjectId StandardDimStyle(this Database db)
  124.         {
  125.             return db.StandardDimStyle(db.TransactionManager.TopTransaction);
  126.         }
  127.  
  128.  
  129.  
  130.         public static UcsTable UcsTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  131.         {
  132.             if (trx == null)
  133.             {
  134.                 throw new NoActiveTransactionException("No active Transaction");
  135.             }
  136.             return (UcsTable)trx.GetObject(db.UcsTableId, mode, false, false);
  137.         }
  138.  
  139.  
  140.         public static UcsTable UcsTable(this Database db, OpenMode mode = OpenMode.ForRead)
  141.         {
  142.             return db.UcsTable(db.TransactionManager.TopTransaction, mode);
  143.         }
  144.  
  145.  
  146.  
  147.         public static ViewportTable ViewportTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  148.         {
  149.             if (trx == null)
  150.             {
  151.                 throw new NoActiveTransactionException("No active Transaction");
  152.             }
  153.             return (ViewportTable)trx.GetObject(db.ViewportTableId, mode, false, false);
  154.         }
  155.  
  156.  
  157.         public static ViewportTable ViewportTable(this Database db, OpenMode mode = OpenMode.ForRead)
  158.         {
  159.             return db.ViewportTable(db.TransactionManager.TopTransaction, mode);
  160.         }
  161.  
  162.  
  163.  
  164.         public static ViewTable ViewTable(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  165.         {
  166.             if (trx == null)
  167.             {
  168.                 throw new NoActiveTransactionException("No active Transaction");
  169.             }
  170.             return (ViewTable)trx.GetObject(db.ViewTableId, mode, false, false);
  171.         }
  172.  
  173.  
  174.         public static ViewTable ViewTable(this Database db, OpenMode mode = OpenMode.ForRead)
  175.         {
  176.             return db.ViewTable(db.TransactionManager.TopTransaction, mode);
  177.         }
  178.  
  179.         /// <summary>
  180.         /// Author: Tony Tanzillo
  181.         /// Source: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  182.         /// </summary>
  183.         /// <param name="db"></param>
  184.         /// <param name="trx"></param>
  185.         /// <param name="mode"></param>
  186.         /// <returns></returns>
  187.        public static BlockTableRecord ModelSpace(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  188.         {
  189.             if (trx == null)
  190.             {
  191.                 throw new NoActiveTransactionException("No active Transaction");
  192.             }
  193.             return (BlockTableRecord)trx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),mode, false, false);
  194.         }
  195.  
  196.  
  197.         public static BlockTableRecord ModelSpace(this Database db, OpenMode mode = OpenMode.ForRead)
  198.         {
  199.             return db.ModelSpace(db.TransactionManager.TopTransaction, mode);
  200.         }
  201.  
  202.  
  203.        
  204.  
  205.         /// <summary>
  206.         /// Author: Tony Tanzillo
  207.         /// Source: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  208.         /// </summary>
  209.         /// <param name="db"></param>
  210.         /// <param name="trx"></param>
  211.         /// <param name="mode"></param>
  212.         /// <returns></returns>
  213.         public static BlockTableRecord CurrentSpace(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  214.         {
  215.             if (trx == null)
  216.             {
  217.                 throw new NoActiveTransactionException("No active Transaction");
  218.             }
  219.             return (BlockTableRecord)trx.GetObject(db.CurrentSpaceId, mode, false, false);
  220.         }
  221.  
  222.  
  223.         public static BlockTableRecord CurrentSpace(this Database db, OpenMode mode = OpenMode.ForRead)
  224.         {
  225.             return db.CurrentSpace(db.TransactionManager.TopTransaction, mode);
  226.         }        
  227.  
  228.  
  229.         public static DBDictionary NamedObjectDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  230.         {
  231.             if (trx == null)
  232.             {
  233.                 throw new NoActiveTransactionException("No active Transaction");
  234.             }
  235.             return (DBDictionary)trx.GetObject(db.NamedObjectsDictionaryId, mode, false, false);
  236.         }
  237.  
  238.  
  239.         public static DBDictionary NamedObjectDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  240.         {
  241.             return db.NamedObjectDBDictionary(db.TransactionManager.TopTransaction, mode);
  242.         }
  243.  
  244.  
  245.         public static DBDictionary GroupDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  246.         {
  247.             if (trx == null)
  248.             {
  249.                 throw new NoActiveTransactionException("No active Transaction");
  250.             }
  251.             return (DBDictionary)trx.GetObject(db.GroupDictionaryId, mode, false, false);
  252.         }
  253.  
  254.  
  255.         public static DBDictionary GroupDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  256.         {
  257.             return db.GroupDBDictionary(db.TransactionManager.TopTransaction, mode);
  258.         }
  259.  
  260.  
  261.         public static DBDictionary MLStyleDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  262.         {
  263.             if (trx == null)
  264.             {
  265.                 throw new NoActiveTransactionException("No active Transaction");
  266.             }
  267.             return (DBDictionary)trx.GetObject(db.MLStyleDictionaryId, mode, false, false);
  268.         }
  269.  
  270.  
  271.         public static DBDictionary MLStyleDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  272.         {
  273.             return db.MLStyleDBDictionary(db.TransactionManager.TopTransaction, mode);
  274.         }
  275.  
  276.         public static ObjectId StandardMLStyle(this Database db)
  277.         {
  278.  
  279.             return db.StandardMLStyle(db.TransactionManager.TopTransaction);
  280.         }
  281.  
  282.         public static ObjectId StandardMLStyle(this Database db, Transaction trx)
  283.         {
  284.             var mlDic = db.MLStyleDBDictionary(trx);
  285.             return mlDic.Contains(standard) ? mlDic.GetAt(standard) : db.CmlstyleID;
  286.         }
  287.  
  288.  
  289.         public static DBDictionary LayoutDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  290.         {
  291.             if (trx == null)
  292.             {
  293.                 throw new NoActiveTransactionException("No active Transaction");
  294.             }
  295.             return (DBDictionary)trx.GetObject(db.LayoutDictionaryId, mode, false, false);
  296.         }
  297.  
  298.  
  299.         public static DBDictionary LayoutDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  300.         {
  301.             return db.LayoutDBDictionary(db.TransactionManager.TopTransaction, mode);
  302.         }
  303.  
  304.  
  305.         public static DBDictionary PlotSettingsDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  306.         {
  307.             if (trx == null)
  308.             {
  309.                 throw new NoActiveTransactionException("No active Transaction");
  310.             }
  311.             return (DBDictionary)trx.GetObject(db.PlotSettingsDictionaryId, mode, false, false);
  312.         }
  313.  
  314.  
  315.         public static DBDictionary PlotSettingsDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  316.         {
  317.             return db.PlotSettingsDBDictionary(db.TransactionManager.TopTransaction, mode);
  318.         }
  319.  
  320.         public static DBDictionary TableStyleDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  321.         {
  322.             if (trx == null)
  323.             {
  324.                 throw new NoActiveTransactionException("No active Transaction");
  325.             }
  326.             return (DBDictionary)trx.GetObject(db.TableStyleDictionaryId, mode, false, false);
  327.         }
  328.  
  329.  
  330.         public static DBDictionary TableStyleDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  331.         {
  332.             return db.TableStyleDBDictionary(db.TransactionManager.TopTransaction, mode);
  333.         }
  334.  
  335.  
  336.         public static DBDictionary MLeaderStyleDBDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead)
  337.         {
  338.             if (trx == null)
  339.             {
  340.                 throw new NoActiveTransactionException("No active Transaction");
  341.             }
  342.             return (DBDictionary)trx.GetObject(db.MLeaderStyleDictionaryId, mode, false, false);
  343.         }
  344.  
  345.  
  346.         public static DBDictionary MLeaderStyleDBDictionary(this Database db, OpenMode mode = OpenMode.ForRead)
  347.         {
  348.             return db.MLeaderStyleDBDictionary(db.TransactionManager.TopTransaction, mode);
  349.         }
  350.  
  351.         public static ObjectId StandardMLeaderStyle(this Database db)
  352.         {
  353.  
  354.             return db.StandardMLeaderStyle(db.TransactionManager.TopTransaction);
  355.         }
  356.  
  357.         public static ObjectId StandardMLeaderStyle(this Database db, Transaction trx)
  358.         {
  359.             var mlDic = db.MLeaderStyleDBDictionary(trx);
  360.             return mlDic.Contains(standard) ? mlDic.GetAt(standard) : db.MLeaderstyle;
  361.         }
  362.  
  363.         public static GroupDictionary GroupDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  364.         {
  365.             if (trx == null)
  366.             {
  367.                 throw new NoActiveTransactionException("No active Transaction");
  368.             }
  369.             DBDictionary dic = (DBDictionary)trx.GetObject(db.GroupDictionaryId, mode, false, false);
  370.             return includingErased
  371.                 ? new GroupDictionary(trx, dic, includingErased)
  372.                 : new GroupDictionary(trx, dic.IncludingErased, includingErased);            
  373.         }
  374.  
  375.         public static GroupDictionary GroupDictionary(this Database db, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  376.         {
  377.             return db.GroupDictionary(db.TransactionManager.TopTransaction, mode, includingErased);
  378.         }
  379.  
  380.         public static MLStyleDictionary MLStyleDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  381.         {
  382.             if (trx == null)
  383.             {
  384.                 throw new NoActiveTransactionException("No active Transaction");
  385.             }
  386.             DBDictionary dic = (DBDictionary)trx.GetObject(db.MLStyleDictionaryId, mode, false, false);
  387.             return includingErased
  388.                 ? new MLStyleDictionary(trx, dic, includingErased)
  389.                 : new MLStyleDictionary(trx, dic.IncludingErased, includingErased);
  390.         }
  391.  
  392.         public static MLStyleDictionary MLStyleDictionary(this Database db, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  393.         {
  394.             return db.MLStyleDictionary(db.TransactionManager.TopTransaction, mode, includingErased);
  395.         }
  396.  
  397.         public static LayoutDictionary LayoutDictionary(this Database db, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  398.         {
  399.             if (trx == null)
  400.             {
  401.                 throw new NoActiveTransactionException("No active Transaction");
  402.             }
  403.             DBDictionary dic = (DBDictionary)trx.GetObject(db.LayoutDictionaryId, mode, false, false);
  404.             return includingErased
  405.                 ? new LayoutDictionary(trx, dic, includingErased)
  406.                 : new LayoutDictionary(trx, dic.IncludingErased, includingErased);
  407.         }
  408.  
  409.         public static LayoutDictionary LayoutDictionary(this Database db, OpenMode mode = OpenMode.ForRead, bool includingErased = false)
  410.         {
  411.             return db.LayoutDictionary(db.TransactionManager.TopTransaction, mode, includingErased);
  412.         }
  413.  
  414.         public static int RevisionNumber(this Database db)
  415.         {
  416.             DatabaseSummaryInfo info = db.SummaryInfo;
  417.             string revisionNumberString = info.RevisionNumber;
  418.             int revisionNumber;
  419.             if (!revisionNumberString.IsNullOrEmpty())
  420.             {                
  421.                 if (Int32.TryParse(revisionNumberString, out revisionNumber))
  422.                 {
  423.                     return revisionNumber;
  424.                 }
  425.             }
  426.             revisionNumber = 0;
  427.             DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(info);
  428.             infoBuilder.RevisionNumber = revisionNumber.ToString();
  429.             db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
  430.             return revisionNumber;
  431.         }
  432.  
  433.         public static int IncrementRevisionNumber(this Database db)
  434.         {
  435.             return db.AddToRevisionNumber(1);
  436.  
  437.         }
  438.  
  439.         public static int AddToRevisionNumber(this Database db, int number)
  440.         {
  441.             DatabaseSummaryInfo info = db.SummaryInfo;
  442.             string revisionNumberString = info.RevisionNumber;
  443.             int revisionNumber;
  444.             if (revisionNumberString.IsNullOrEmpty() || !Int32.TryParse(revisionNumberString, out revisionNumber))
  445.             {
  446.                 revisionNumber = 0;
  447.             }
  448.  
  449.             int newRevisionNum = revisionNumber + number;
  450.             if (newRevisionNum < 0)
  451.             {
  452.                 newRevisionNum = 0;
  453.             }
  454.             DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
  455.             infoBuilder.RevisionNumber = newRevisionNum.ToString();
  456.             db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
  457.             return newRevisionNum;
  458.  
  459.         }
  460.     }
  461. }
  462.  



Title: Re: Screw it I give up
Post by: Jeff H on August 01, 2015, 12:21:08 AM
Blockreferences
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.Runtime;
  6.  
  7. namespace Autodesk.AutoCAD.DatabaseServices
  8. {
  9.     public static class BlockReferenceExtensions
  10.     {
  11.         public static BlockTableRecord GetEffectiveBlockTableRecord(this BlockReference blockref, Transaction trx)
  12.         {
  13.             if (blockref.IsDynamicBlock)
  14.             {
  15.                 return blockref.DynamicBlockTableRecord.GetDBObject<BlockTableRecord>(trx, OpenMode.ForRead, false);
  16.             }
  17.             return blockref.BlockTableRecord.GetDBObject<BlockTableRecord>(trx, OpenMode.ForRead, false);
  18.         }
  19.  
  20.         public static BlockTableRecord GetEffectiveBlockTableRecord(this BlockReference blockref)
  21.         {
  22.             return blockref.GetEffectiveBlockTableRecord(blockref.Database.TransactionManager.TopTransaction);
  23.         }
  24.  
  25.         public static string GetEffectiveName(this BlockReference blockref, Transaction trx)
  26.         {
  27.             if (blockref.IsDynamicBlock)
  28.             {
  29.                 return blockref.DynamicBlockTableRecord.GetDBObject<BlockTableRecord>(trx, OpenMode.ForRead, false).Name;
  30.             }
  31.             return blockref.Name;
  32.         }
  33.  
  34.         public static string GetEffectiveName(this BlockReference blockref)
  35.         {
  36.             return blockref.GetEffectiveName(blockref.Database.TransactionManager.TopTransaction);
  37.            
  38.         }
  39.  
  40.         public static IEnumerable<AttributeReference> GetAttributeReferences(this BlockReference bref, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  41.         {
  42.             if (trx == null)
  43.             {
  44.                 throw new NoActiveTransactionException("No active Transaction");
  45.             }
  46.             if (includingErased)
  47.             {
  48.                 foreach (ObjectId id in bref.AttributeCollection)
  49.                 {
  50.  
  51.                     yield return (AttributeReference)trx.GetObject(id, mode, true, openObjectsOnLockedLayers);
  52.  
  53.                 }
  54.             }
  55.             else
  56.             {
  57.                 foreach (ObjectId id in bref.AttributeCollection)
  58.                 {
  59.                     if (!id.IsErased)
  60.                     {
  61.                         yield return (AttributeReference)trx.GetObject(id, mode, false, openObjectsOnLockedLayers);
  62.                     }
  63.                    
  64.  
  65.                 }
  66.             }
  67.  
  68.  
  69.         }
  70.  
  71.         public static IEnumerable<AttributeReference> GetAttributeReferences(this BlockReference bref, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  72.         {
  73.             return bref.GetAttributeReferences(bref.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  74.  
  75.         }
  76.  
  77.         public static Dictionary<string, AttributeReference> GetAttributeReferenceDictionary(this BlockReference bref, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  78.         {
  79.             if (trx == null)
  80.             {
  81.                 throw new NoActiveTransactionException("No active Transaction");
  82.             }
  83.  
  84.             return bref.GetAttributeReferences(trx, mode, includingErased, openObjectsOnLockedLayers).ToDictionary(a => a.Tag);
  85.  
  86.         }
  87.  
  88.         public static Dictionary<string, AttributeReference> GetAttributeReferenceDictionary(this BlockReference bref, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  89.         {
  90.             return bref.GetAttributeReferenceDictionary(bref.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  91.  
  92.         }
  93.     }
  94. }
  95.  
  96.  

Blocktable
Code - C#: [Select]
  1. using System.Collections.Generic;
  2.  
  3. namespace Autodesk.AutoCAD.DatabaseServices
  4. {
  5.     public static class BlockTableExtensions
  6.     {
  7.         public static IEnumerable<BlockTableRecord> GetBlockTableRecords(this BlockTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  8.         {
  9.             if (filter.IsSet(SymbolTableRecordFilter.IncludeDependent))
  10.             {
  11.                 return symbolTbl.GetSymbolTableRecords<BlockTableRecord>(trx, mode, filter, true);
  12.             }
  13.             return symbolTbl.GetSymbolTableRecords<BlockTableRecord>(trx, mode, filter, true).NonDependent();
  14.         }
  15.  
  16.         public static IEnumerable<BlockTableRecord> GetBlockTableRecords(this BlockTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  17.         {
  18.             return symbolTbl.GetBlockTableRecords(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter);
  19.         }
  20.  
  21.  
  22.         public static IEnumerable<BlockTableRecord> GetUserDefinedBlockTableRecords(this BlockTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead)
  23.         {
  24.  
  25.             return symbolTbl.GetSymbolTableRecords<BlockTableRecord>(trx, mode, SymbolTableRecordFilter.None, true).UserDefinedBlocks();
  26.         }
  27.  
  28.         public static IEnumerable<BlockTableRecord> GetUserDefinedBlockTableRecords(this BlockTable symbolTbl, OpenMode mode = OpenMode.ForRead)
  29.         {
  30.             return symbolTbl.GetUserDefinedBlockTableRecords(symbolTbl.Database.TransactionManager.TopTransaction, mode);
  31.         }
  32.  
  33.  
  34.         public static IEnumerable<BlockTableRecord> GetUserCreatedBlockTableRecords(this BlockTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead)
  35.         {
  36.  
  37.             return symbolTbl.GetSymbolTableRecords<BlockTableRecord>(trx, mode, SymbolTableRecordFilter.None, true).UserCreatedBlocks();
  38.         }
  39.  
  40.         public static IEnumerable<BlockTableRecord> GetUserCreatedBlockTableRecords(this BlockTable symbolTbl, OpenMode mode = OpenMode.ForRead)
  41.         {
  42.             return symbolTbl.GetUserCreatedBlockTableRecords(symbolTbl.Database.TransactionManager.TopTransaction, mode);
  43.         }
  44.  
  45.  
  46.  
  47.         internal static ObjectId GetDatabaseBlockTableId(this BlockTable symbolTbl, Database db)
  48.         {
  49.             return db.BlockTableId;
  50.         }
  51.     }
  52.  
  53. }
  54.  
BlockTableRecord
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.Runtime;
  6. using Autodesk.AutoCAD.DatabaseServices.Contracts;
  7. using System.Diagnostics.Contracts;
  8. //using Autodesk.AutoCAD.ApplicationServices.Core;
  9. //using Autodesk.AutoCAD.EditorInput;
  10. namespace Autodesk.AutoCAD.DatabaseServices
  11. {
  12.  public static class BlockTableRecordExtensions
  13.     {
  14.  
  15.         /// <summary>
  16.         /// Author: Tony Tanzillo
  17.         /// Source: http://www.theswamp.org/index.php?topic=41311.msg464529#msg464529
  18.         /// </summary>
  19.         /// <param name="source"></param>
  20.         /// <returns></returns>
  21.      public static IEnumerable<BlockTableRecord> UserDefinedBlocks(this IEnumerable<BlockTableRecord> source)
  22.      {
  23.          return source.Where(btr =>
  24.              !(
  25.              btr.IsAnonymous ||
  26.              btr.IsFromExternalReference ||
  27.              btr.IsFromOverlayReference ||
  28.              btr.IsLayout ||
  29.              btr.IsAProxy
  30.              )
  31.              );
  32.      }
  33.  
  34.      public static IEnumerable<BlockTableRecord> UserCreatedBlocks(this IEnumerable<BlockTableRecord> source)
  35.      {
  36.          return source.Where(btr =>
  37.              !(
  38.              btr.IsFromExternalReference ||
  39.              btr.IsFromOverlayReference ||
  40.              btr.IsLayout ||
  41.              btr.IsAProxy
  42.              )
  43.              );
  44.      }
  45.         /// <summary>
  46.         /// Author: Tony Tanzillo
  47.         /// Source: http://www.theswamp.org/index.php?topic=41311.msg464529#msg464529
  48.         /// Use instead of UserDefinedBlocks when anonymous blocks are needed
  49.         /// </summary>
  50.         /// <param name="source"></param>
  51.         /// <returns></returns>
  52.      public static IEnumerable<BlockTableRecord> NonDependent(this IEnumerable<BlockTableRecord> source)
  53.      {
  54.          return source.Where(btr =>
  55.              !(
  56.              btr.IsFromExternalReference ||
  57.              btr.IsFromOverlayReference
  58.              )
  59.              );
  60.      }
  61.  
  62.  
  63.      public static IEnumerable<ObjectId> GetObjectIds<T>(this BlockTableRecord btr) where T : Entity
  64.      {
  65.          IntPtr impobj = RXClass.GetClass(typeof(T)).UnmanagedObject;
  66.          foreach (ObjectId id in btr)
  67.          {
  68.              if (id.ObjectClass.UnmanagedObject == impobj)
  69.              {
  70.                  yield return id;
  71.              }
  72.          }
  73.      }
  74.  
  75.      public static IEnumerable<ObjectId> GetObjectIds(this BlockTableRecord btr)
  76.      {
  77.          foreach (ObjectId id in btr)
  78.          {
  79.              yield return id;
  80.          }
  81.      }
  82.  
  83.         /// <summary>
  84.         /// Author: Tony Tanzillo
  85.         /// A combination of code written by Tony Tanzillo from 2 sources below
  86.         /// Source1: http://www.theswamp.org/index.php?topic=42197.msg474011#msg474011
  87.         /// Source2: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  88.         /// </summary>
  89.         /// <param name="btr"></param>
  90.         /// <param name="mode"></param>
  91.         /// <param name="openErased"></param>
  92.         /// <param name="openObjectsOnLockedLayers"></param>
  93.         /// <returns></returns>
  94.      public static IEnumerable<Entity> GetEntities(this BlockTableRecord btr, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  95.         {
  96.             if (trx == null)
  97.             {
  98.                 throw new NoActiveTransactionException("No active Transaction");
  99.             }
  100.  
  101.             foreach (ObjectId id in includingErased ? btr.IncludingErased : btr)
  102.             {
  103.                 yield return (Entity)trx.GetObject(id, mode, includingErased, openObjectsOnLockedLayers);
  104.             }
  105.  
  106.         }
  107.  
  108.         public static IEnumerable<Entity> GetEntities(this BlockTableRecord btr, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  109.         {
  110.             return btr.GetEntities(btr.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  111.  
  112.         }
  113.  
  114.         /// <summary>
  115.         /// Author: Tony Tanzillo
  116.         /// A combination of code written by Tony Tanzillo from 2 sources below
  117.         /// Source1: http://www.theswamp.org/index.php?topic=42197.msg474011#msg474011
  118.         /// Source2: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  119.         /// </summary>
  120.         /// <typeparam name="T"></typeparam>
  121.         /// <param name="btr"></param>
  122.         /// <param name="mode"></param>
  123.         /// <param name="openErased"></param>
  124.         /// <param name="openObjectsOnLockedLayers"></param>
  125.         /// <returns></returns>
  126.         public static IEnumerable<T> GetEntities<T>(this BlockTableRecord btr, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false) where T : Entity
  127.         {
  128.             if (trx == null)
  129.             {
  130.                 throw new NoActiveTransactionException("No active Transaction");
  131.             }
  132.  
  133.             IntPtr impObject = RXClass.GetClass(typeof(T)).UnmanagedObject;
  134.  
  135.  
  136.             foreach (ObjectId id in includingErased ? btr.IncludingErased : btr)
  137.             {
  138.                 if(id.ObjectClass.UnmanagedObject == impObject)
  139.                 {
  140.                     yield return (T)trx.GetObject(id, mode, includingErased, openObjectsOnLockedLayers);
  141.                 }
  142.  
  143.             }
  144.         }
  145.  
  146.         public static IEnumerable<T> GetEntities<T>(this BlockTableRecord btr, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false) where T : Entity
  147.         {
  148.             return btr.GetEntities<T>(btr.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  149.         }
  150.  
  151.         /// <summary>
  152.         /// Author: Tony Tanzillo
  153.         /// A combination of code written by Tony Tanzillo from 2 sources below
  154.         /// Source1: http://www.theswamp.org/index.php?topic=42197.msg474011#msg474011
  155.         /// Source2: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  156.         /// </summary>
  157.         /// <typeparam name="T"></typeparam>
  158.         /// <param name="btr"></param>
  159.         /// <param name="mode"></param>
  160.         /// <param name="openErased"></param>
  161.         /// <param name="openObjectsOnLockedLayers"></param>
  162.         /// <returns></returns>
  163.         public static IEnumerable<T> GetEntitiesAssignableFrom<T>(this BlockTableRecord btr, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false) where T : Entity
  164.         {
  165.             if (trx == null)
  166.             {
  167.                 throw new NoActiveTransactionException("No active Transaction");
  168.             }
  169.  
  170.             RXClass rxclass = RXClass.GetClass(typeof(T));
  171.  
  172.  
  173.             foreach (ObjectId id in includingErased ? btr.IncludingErased : btr)
  174.             {
  175.                 if (id.ObjectClass.IsDerivedFrom(rxclass))
  176.                 {
  177.                     yield return (T)trx.GetObject(id, mode, includingErased, openObjectsOnLockedLayers);
  178.                 }
  179.  
  180.             }
  181.  
  182.         }
  183.  
  184.         public static IEnumerable<T> GetEntitiesAssignableFrom<T>(this BlockTableRecord btr, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false) where T : Entity
  185.         {
  186.             return btr.GetEntitiesAssignableFrom<T>(btr.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  187.  
  188.         }
  189.      /// <summary>
  190.      /// Method for getting all blockreference Ids
  191.      /// </summary>
  192.      /// <param name="btr"></param>
  193.      /// <param name="directOnly"></param>
  194.      /// <param name="forceValidity"></param>
  195.      /// <param name="trx"></param>
  196.      /// <returns></returns>
  197.         public static ObjectIdCollection GetAllBlockReferenceIds(this BlockTableRecord btr, Transaction trx, bool directOnly, bool forceValidity)
  198.         {
  199.             if (trx == null)
  200.             {
  201.                 throw new NoActiveTransactionException("No active Transaction");
  202.             }
  203.  
  204.             ObjectIdCollection blockReferenceIds = btr.GetBlockReferenceIds(directOnly, forceValidity);
  205.  
  206.          if (!btr.IsDynamicBlock) return blockReferenceIds;
  207.          foreach (ObjectId id in btr.GetAnonymousBlockIds())
  208.          {
  209.              BlockTableRecord record = trx.GetObject(id, OpenMode.ForRead) as BlockTableRecord;
  210.              blockReferenceIds.Add(record.GetBlockReferenceIds(directOnly, forceValidity));
  211.  
  212.          }
  213.          return blockReferenceIds;
  214.         }
  215.  
  216.         public static ObjectIdCollection GetAllBlockReferenceIds(this BlockTableRecord btr, bool directOnly, bool forceValidity)
  217.         {
  218.             return btr.GetAllBlockReferenceIds(btr.Database.TransactionManager.TopTransaction, directOnly, forceValidity);
  219.         }
  220.  
  221.         public static IEnumerable<BlockReference> GetAllBlockReferences(this BlockTableRecord btr, Transaction trx, bool directOnly, bool forceValidity)
  222.         {
  223.             TransactionManager tm = btr.Database.TransactionManager;
  224.             foreach (ObjectId id in GetAllBlockReferenceIds(btr, trx, directOnly, forceValidity))
  225.             {
  226.  
  227.                 yield return (BlockReference)trx.GetObject(id, OpenMode.ForRead, false, false);
  228.             }
  229.            
  230.         }
  231.  
  232.         public static IEnumerable<BlockReference> GetAllBlockReferences(this BlockTableRecord btr, bool directOnly, bool forceValidity)
  233.         {
  234.             return btr.GetAllBlockReferences(btr.Database.TransactionManager.TopTransaction, directOnly, forceValidity);
  235.         }
  236.  
  237.  
  238.  
  239.      public static IEnumerable<AttributeDefinition> GetAttributeDefinitions(this BlockTableRecord btr, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  240.      {
  241.  
  242.          return btr.GetEntities<AttributeDefinition>(trx, mode, includingErased, openObjectsOnLockedLayers);
  243.      }
  244.  
  245.      public static IEnumerable<AttributeDefinition> GetAttributeDefinitions(this BlockTableRecord btr, OpenMode mode = OpenMode.ForRead, bool includingErased = false, bool openObjectsOnLockedLayers = false)
  246.      {
  247.          return btr.GetAttributeDefinitions(btr.Database.TransactionManager.TopTransaction, mode, includingErased, openObjectsOnLockedLayers);
  248.      }
  249.     }
  250. }
  251.  
  252.  
  253.  

Title: Re: Screw it I give up
Post by: Jeff H on August 01, 2015, 12:34:44 AM
Objectid
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.DatabaseServices.Contracts;
  6. using System.Diagnostics.Contracts;
  7. using Autodesk.AutoCAD.Runtime;
  8.  
  9. namespace Autodesk.AutoCAD.DatabaseServices
  10. {
  11.     public static class ObjectIdExtensions
  12.     {
  13.  
  14.         public static T GetDBObject<T>(this ObjectId id, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false) where T : DBObject
  15.         {
  16.             if (id.IsNull)
  17.             {
  18.                 throw new ArgumentNullException("id is null");
  19.             }
  20.             if (trx == null)
  21.             {
  22.                 throw new NoActiveTransactionException("No active Transaction");
  23.             }
  24.             return (T)trx.GetObject(id, mode, openErased, false);
  25.         }
  26.  
  27.         public static T GetDBObject<T>(this ObjectId id, OpenMode mode = OpenMode.ForRead, bool openErased = false) where T : DBObject
  28.         {
  29.             return id.GetDBObject<T>(id.Database.TransactionManager.TopTransaction, mode, openErased);
  30.         }
  31.  
  32.         public static DBObject GetDBObject(this ObjectId id, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false)
  33.         {
  34.             return id.GetDBObject<DBObject>(trx, mode, openErased);
  35.         }
  36.  
  37.         public static DBObject GetDBObject(this ObjectId id, OpenMode mode = OpenMode.ForRead, bool openErased = false)
  38.         {
  39.             return id.GetDBObject<DBObject>(id.Database.TransactionManager.TopTransaction, mode, openErased);
  40.         }
  41.  
  42.  
  43.  
  44.  
  45.         public static T GetEntity<T>(this ObjectId id, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false) where T : Entity
  46.         {
  47.             if (id.IsNull)
  48.             {
  49.                 throw new ArgumentNullException("id is null");
  50.             }
  51.             if (trx == null)
  52.             {
  53.                 throw new NoActiveTransactionException("No active Transaction");
  54.             }
  55.             return (T)trx.GetObject(id, mode, openErased, forceOpenOnLockedLayer);
  56.         }
  57.        
  58.  
  59.         public static T GetEntity<T>(this ObjectId id, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false) where T : Entity
  60.         {
  61.             return id.GetEntity<T>(id.Database.TransactionManager.TopTransaction, mode, openErased, forceOpenOnLockedLayer);
  62.         }
  63.  
  64.  
  65.         public static Entity GetEntity(this ObjectId id, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false)
  66.         {
  67.             return id.GetEntity<Entity>(trx, mode, openErased, forceOpenOnLockedLayer);
  68.         }
  69.  
  70.         public static Entity GetEntity(this ObjectId id, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false)
  71.         {
  72.             return id.GetEntity<Entity>(id.Database.TransactionManager.TopTransaction, mode, openErased, forceOpenOnLockedLayer);
  73.         }
  74.  
  75.         public static IEnumerable<T> GetEntities<T>(this IEnumerable<ObjectId> ids, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false) where T : Entity
  76.         {
  77.             if (ids == null)
  78.             {
  79.                 throw new ArgumentNullException("ids is null");
  80.             }
  81.             if (trx == null)
  82.             {
  83.                 throw new NoActiveTransactionException("No active Transaction");
  84.             }
  85.             foreach (ObjectId id in ids)
  86.             {
  87.                yield return (T)trx.GetObject(id, mode, openErased, forceOpenOnLockedLayer);
  88.             }
  89.            
  90.         }
  91.  
  92.         public static IEnumerable<T> GetEntities<T>(this IEnumerable<ObjectId> ids, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false) where T : Entity
  93.         {
  94.             ObjectId id = ids.First();
  95.             if (id == null)
  96.             {
  97.                 throw new ArgumentNullException("id is null");
  98.             }
  99.             return ids.GetEntities<T>(id.Database.TransactionManager.TopTransaction, mode, openErased, forceOpenOnLockedLayer);
  100.         }
  101.  
  102.         public static IEnumerable<Entity> GetEntities(this IEnumerable<ObjectId> ids, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false)
  103.         {
  104.              return ids.GetEntities<Entity>(trx, mode, openErased, forceOpenOnLockedLayer);
  105.  
  106.         }
  107.  
  108.         public static IEnumerable<Entity> GetEntities(this IEnumerable<ObjectId> ids, OpenMode mode = OpenMode.ForRead, bool openErased = false, bool forceOpenOnLockedLayer = false)
  109.         {
  110.             ObjectId id = ids.First();
  111.             if (id == null)
  112.             {
  113.                 throw new ArgumentNullException("id is null");
  114.             }
  115.             return ids.GetEntities<Entity>(id.Database.TransactionManager.TopTransaction, mode, openErased, forceOpenOnLockedLayer);
  116.         }
  117.  
  118.         public static IEnumerable<T> GetDBObjects<T>(this IEnumerable<ObjectId> ids, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false) where T : DBObject
  119.         {
  120.             if (ids == null)
  121.             {
  122.                 throw new ArgumentNullException("ids is null");
  123.             }
  124.             if (trx == null)
  125.             {
  126.                 throw new NoActiveTransactionException("No active Transaction");
  127.             }
  128.             foreach (ObjectId id in ids)
  129.             {
  130.                 yield return (T)trx.GetObject(id, mode, openErased, false);
  131.             }
  132.  
  133.         }
  134.  
  135.         public static IEnumerable<T> GetDBObjects<T>(this IEnumerable<ObjectId> ids, OpenMode mode = OpenMode.ForRead, bool openErased = false) where T : DBObject
  136.         {
  137.             ObjectId id = ids.First();
  138.             if (id == null)
  139.             {
  140.                 throw new ArgumentNullException("id is null");
  141.             }
  142.             return ids.GetDBObjects<T>(id.Database.TransactionManager.TopTransaction, mode, openErased);
  143.         }
  144.  
  145.         public static IEnumerable<DBObject> GetDBObjects(this IEnumerable<ObjectId> ids, Transaction trx, OpenMode mode = OpenMode.ForRead, bool openErased = false)
  146.         {
  147.             return ids.GetDBObjects<DBObject>(trx, mode, openErased);
  148.  
  149.         }
  150.  
  151.         public static IEnumerable<DBObject> GetDBObjects(this IEnumerable<ObjectId> ids, OpenMode mode = OpenMode.ForRead, bool openErased = false)
  152.         {
  153.             ObjectId id = ids.First();
  154.             if (id == null)
  155.             {
  156.                 throw new ArgumentNullException("id is null");
  157.             }
  158.             return ids.GetDBObjects<DBObject>(id.Database.TransactionManager.TopTransaction, mode, openErased);
  159.         }
  160.     }
  161. }
  162.  
  163.  

SymbolTable
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.DatabaseServices.Contracts;
  6. using Autodesk.AutoCAD.Runtime;
  7.  
  8. namespace Autodesk.AutoCAD.DatabaseServices
  9. {
  10.     public static class SymbolTableExtensions
  11.     {
  12.         public static IEnumerable<ObjectId> GetObjectIds(this SymbolTable st)
  13.         {
  14.             foreach (ObjectId id in st)
  15.             {
  16.                 yield return id;
  17.             }
  18.         }
  19.  
  20.         internal static IEnumerable<T> GetSymbolTableRecords<T>(this SymbolTable symbolTbl, Transaction trx,
  21.             OpenMode mode, SymbolTableRecordFilter filter, bool filterDependecyById) where T : SymbolTableRecord
  22.         {
  23.             if (trx == null)
  24.             {
  25.                 throw new NoActiveTransactionException("No active Transaction");
  26.             }
  27.  
  28.             bool includingErased = filter.IsSet(SymbolTableRecordFilter.IncludedErased);
  29.  
  30.             if (filter.IsSet(SymbolTableRecordFilter.IncludeDependent))
  31.             {
  32.                 foreach (ObjectId id in includingErased ? symbolTbl.IncludingErased : symbolTbl)
  33.                 {
  34.                     yield return (T)trx.GetObject(id, mode, includingErased, false);
  35.                 }
  36.             }
  37.  
  38.             else
  39.             {
  40.                 if (filterDependecyById)
  41.                 {
  42.                     IntPtr dbIntPtr = symbolTbl.Database.UnmanagedObject;
  43.                     foreach (ObjectId id in includingErased ? symbolTbl.IncludingErased : symbolTbl)
  44.                     {
  45.                         if (id.OriginalDatabase.UnmanagedObject == dbIntPtr)
  46.                         {
  47.                             yield return (T)trx.GetObject(id, mode, includingErased, false);
  48.                         }
  49.                     }
  50.                 }
  51.                 else
  52.                 {
  53.                     foreach (ObjectId id in includingErased ? symbolTbl.IncludingErased : symbolTbl)
  54.                     {
  55.                         T current = (T)trx.GetObject(id, mode, includingErased, false);
  56.                         if (!current.IsDependent)
  57.                         {
  58.                             yield return current;
  59.                         }
  60.                     }
  61.                 }
  62.  
  63.             }
  64.  
  65.  
  66.         }
  67.  
  68.  
  69.         /// <summary>
  70.         /// Author: Gile
  71.         /// Source: http://www.theswamp.org/index.php?topic=42539.msg477455#msg477455
  72.         /// </summary>
  73.         /// <param name="source"></param>
  74.         /// <returns></returns>
  75.         public static ObjectId ImportSymbolTableRecord<T>(this Database targetDb, string sourceFile,
  76.             DuplicateRecordCloning cloningStyle, string recordName)
  77.             where T : SymbolTable
  78.         {
  79.  
  80.             using (var sourceDb = new Database(false, true))
  81.             {
  82.                 sourceDb.ReadDwgFile(sourceFile, System.IO.FileShare.ReadWrite, false, "");
  83.                 ObjectId sourceTableId, targetTableId;
  84.                 switch (typeof (T).Name)
  85.                 {
  86.                     case "BlockTable":
  87.                         sourceTableId = sourceDb.BlockTableId;
  88.                         targetTableId = targetDb.BlockTableId;
  89.                         break;
  90.                     case "DimStyleTable":
  91.                         sourceTableId = sourceDb.DimStyleTableId;
  92.                         targetTableId = targetDb.DimStyleTableId;
  93.                         break;
  94.                     case "LayerTable":
  95.                         sourceTableId = sourceDb.LayerTableId;
  96.                         targetTableId = targetDb.LayerTableId;
  97.                         break;
  98.                     case "LinetypeTable":
  99.                         sourceTableId = sourceDb.LinetypeTableId;
  100.                         targetTableId = targetDb.LinetypeTableId;
  101.                         break;
  102.                     case "RegAppTable":
  103.                         sourceTableId = sourceDb.RegAppTableId;
  104.                         targetTableId = targetDb.RegAppTableId;
  105.                         break;
  106.                     case "TextStyleTable":
  107.                         sourceTableId = sourceDb.TextStyleTableId;
  108.                         targetTableId = targetDb.TextStyleTableId;
  109.                         break;
  110.                     case "UcsTable":
  111.                         sourceTableId = sourceDb.UcsTableId;
  112.                         targetTableId = targetDb.UcsTableId;
  113.                         break;
  114.                     case "ViewTable":
  115.                         sourceTableId = sourceDb.ViewportTableId;
  116.                         targetTableId = targetDb.ViewportTableId;
  117.                         break;
  118.                     case "ViewportTable":
  119.                         sourceTableId = sourceDb.ViewportTableId;
  120.                         targetTableId = targetDb.ViewportTableId;
  121.                         break;
  122.                     default:
  123.                         throw new ArgumentException("Requires a concrete type derived from SymbolTable");
  124.                 }
  125.  
  126.                 using (Transaction tr = sourceDb.TransactionManager.StartTransaction())
  127.                 {
  128.  
  129.                     T sourceTable = (T) tr.GetObject(sourceTableId, OpenMode.ForRead);
  130.                     if (!sourceTable.Has(recordName))
  131.                     {
  132.                         return ObjectId.Null;
  133.                     }
  134.                     var idCol = new ObjectIdCollection();
  135.                     ObjectId sourceTableRecordId = sourceTable[recordName];
  136.                     idCol.Add(sourceTableRecordId);
  137.                     var idMap = new IdMapping();
  138.                     sourceDb.WblockCloneObjects(idCol, targetTableId, idMap, cloningStyle, false);
  139.                     tr.Commit();
  140.                     return idMap[sourceTableRecordId].Value;
  141.                 }
  142.             }
  143.         }
  144.  
  145.  
  146.         /// <summary>
  147.         /// Author: Gile
  148.         /// Source: http://www.theswamp.org/index.php?topic=42539.msg477455#msg477455
  149.         /// </summary>
  150.         /// <param name="source"></param>
  151.         /// <returns></returns>
  152.         public static bool ImportSymbolTableRecords<T>(this Database targetDb, string sourceFile,
  153.             DuplicateRecordCloning cloningStyle, params string[] recordNames)
  154.             where T : SymbolTable
  155.         {
  156.             using (var sourceDb = new Database(false, true))
  157.             {
  158.                 sourceDb.ReadDwgFile(sourceFile, System.IO.FileShare.Read, false, "");
  159.                 ObjectId sourceTableId, targetTableId;
  160.                 switch (typeof (T).Name)
  161.                 {
  162.                     case "BlockTable":
  163.                         sourceTableId = sourceDb.BlockTableId;
  164.                         targetTableId = targetDb.BlockTableId;
  165.                         break;
  166.                     case "DimStyleTable":
  167.                         sourceTableId = sourceDb.DimStyleTableId;
  168.                         targetTableId = targetDb.DimStyleTableId;
  169.                         break;
  170.                     case "LayerTable":
  171.                         sourceTableId = sourceDb.LayerTableId;
  172.                         targetTableId = targetDb.LayerTableId;
  173.                         break;
  174.                     case "LinetypeTable":
  175.                         sourceTableId = sourceDb.LinetypeTableId;
  176.                         targetTableId = targetDb.LinetypeTableId;
  177.                         break;
  178.                     case "RegAppTable":
  179.                         sourceTableId = sourceDb.RegAppTableId;
  180.                         targetTableId = targetDb.RegAppTableId;
  181.                         break;
  182.                     case "TextStyleTable":
  183.                         sourceTableId = sourceDb.TextStyleTableId;
  184.                         targetTableId = targetDb.TextStyleTableId;
  185.                         break;
  186.                     case "UcsTable":
  187.                         sourceTableId = sourceDb.UcsTableId;
  188.                         targetTableId = targetDb.UcsTableId;
  189.                         break;
  190.                     case "ViewTable":
  191.                         sourceTableId = sourceDb.ViewportTableId;
  192.                         targetTableId = targetDb.ViewportTableId;
  193.                         break;
  194.                     case "ViewportTable":
  195.                         sourceTableId = sourceDb.ViewportTableId;
  196.                         targetTableId = targetDb.ViewportTableId;
  197.                         break;
  198.                     default:
  199.                         throw new ArgumentException("Requires a concrete type derived from SymbolTable");
  200.                 }
  201.  
  202.                 using (var tr = sourceDb.TransactionManager.StartTransaction())
  203.                 {
  204.                     var allImported = true;
  205.                     var sourceTable = (T) tr.GetObject(sourceTableId, OpenMode.ForRead);
  206.                     var idCol = new ObjectIdCollection();
  207.                     foreach (var recordName in recordNames)
  208.                     {
  209.                         if (sourceTable.Has(recordName))
  210.                         {
  211.                             idCol.Add(sourceTable[recordName]);
  212.                         }
  213.                         else
  214.                         {
  215.                             allImported = false;
  216.                         }
  217.                     }
  218.  
  219.                     var idMap = new IdMapping();
  220.                     sourceDb.WblockCloneObjects(idCol, targetTableId, idMap, cloningStyle, false);
  221.                     tr.Commit();
  222.                     return allImported;
  223.                 }
  224.             }
  225.         }
  226.  
  227.     }
  228. }
  229.  

DBDictionary
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.Runtime;
  6. using System.Diagnostics.Contracts;
  7. using Autodesk.AutoCAD.DatabaseServices.Contracts;
  8.  
  9. namespace Autodesk.AutoCAD.DatabaseServices
  10. {
  11.     public static class DBDictionaryExtensions
  12.     {
  13.         public static IEnumerable<T> GetEntries<T>(this DBDictionary dic, Transaction trx, OpenMode mode = OpenMode.ForRead, bool includingErased = false) where T : DBObject
  14.         {
  15.             if (trx == null)
  16.             {
  17.                 throw new NoActiveTransactionException("No active Transaction");
  18.             }
  19.             foreach (var entry in includingErased ? dic.IncludingErased : dic)
  20.             {
  21.                 yield return (T)trx.GetObject(entry.Value, mode, includingErased, false);
  22.             }
  23.         }
  24.  
  25.         public static IEnumerable<T> GetEntries<T>(this DBDictionary dic, OpenMode mode = OpenMode.ForRead, bool includingErased = false) where T : DBObject
  26.         {
  27.             return dic.GetEntries<T>(dic.Database.TransactionManager.TopTransaction, mode, includingErased);
  28.         }
  29.     }
  30. }
  31.  
  32.  
DimstyleTable
Code - C#: [Select]
  1. using System.Collections.Generic;
  2.  
  3. namespace Autodesk.AutoCAD.DatabaseServices
  4. {
  5.     public static class DimStyleTableExtensions
  6.     {
  7.  
  8.         public static IEnumerable<DimStyleTableRecord> GetDimStyleTableRecords(this DimStyleTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  9.         {
  10.             return symbolTbl.GetSymbolTableRecords<DimStyleTableRecord>(trx, mode, filter, true);
  11.         }
  12.  
  13.         public static IEnumerable<DimStyleTableRecord> GetDimStyleTableRecords(this DimStyleTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  14.         {
  15.             return symbolTbl.GetSymbolTableRecords<DimStyleTableRecord>(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter, true);
  16.         }
  17.  
  18.     }
  19. }
  20.  
  21.  
LayerTable
Code - C#: [Select]
  1. using System.Collections.Generic;
  2.  
  3. namespace Autodesk.AutoCAD.DatabaseServices
  4. {
  5.     public static class LayerTableExtensions
  6.     {
  7.  
  8.         public static IEnumerable<LayerTableRecord> GetLayerTableRecords(this LayerTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  9.         {
  10.             return symbolTbl.GetSymbolTableRecords<LayerTableRecord>(trx, mode, filter, false);
  11.         }
  12.  
  13.         public static IEnumerable<LayerTableRecord> GetLayerTableRecords(this LayerTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  14.         {
  15.             return symbolTbl.GetSymbolTableRecords<LayerTableRecord>(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter, false);
  16.         }
  17.  
  18.     }
  19.  
  20.  
  21. }
  22.  
  23.  

Title: Re: Screw it I give up
Post by: Jeff H on August 01, 2015, 12:42:12 AM
LineTypeTable
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Autodesk.AutoCAD.DatabaseServices
  7. {
  8.  
  9.  
  10.     public static class LinetypeTableExtensions
  11.     {
  12.  
  13.         public static IEnumerable<LinetypeTableRecord> GetLinetypeTableRecords(this LinetypeTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  14.         {
  15.             return symbolTbl.GetSymbolTableRecords<LinetypeTableRecord>(trx, mode, filter, false);
  16.         }
  17.  
  18.         public static IEnumerable<LinetypeTableRecord> GetLinetypeTableRecords(this LinetypeTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  19.         {
  20.             return symbolTbl.GetSymbolTableRecords<LinetypeTableRecord>(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter, false);
  21.         }
  22.  
  23.     }
  24. }
  25.  
  26.  

ObjectIDCollection
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Autodesk.AutoCAD.DatabaseServices
  7. {
  8.     public static class ObjectIdCollectionExtensions
  9.     {
  10.        
  11.         public static void Add(this ObjectIdCollection thisIds, ObjectIdCollection ids)
  12.         {
  13.             foreach (ObjectId id in ids)
  14.             {
  15.                 thisIds.Add(id);
  16.             }
  17.         }
  18.  
  19.         public static void Add(this ObjectIdCollection thisIds, IEnumerable<ObjectId> ids)
  20.         {
  21.             foreach (ObjectId id in ids)
  22.             {
  23.                 thisIds.Add(id);
  24.             }
  25.         }
  26.  
  27.  
  28.  
  29.         public static ObjectId[] ToArray(this ObjectIdCollection ids)
  30.         {
  31.             ObjectId[] idsArray = new ObjectId[ids.Count];
  32.             ids.CopyTo(idsArray, 0);
  33.             return idsArray;
  34.         }
  35.  
  36.         //public static ObjectId[] ToArray(this IEnumerable<ObjectId> ids)
  37.         //{
  38.         //    return ids.ToArray();
  39.         //}
  40.  
  41.         public static IEnumerable<ObjectId> Where<T>(this ObjectIdCollection source, Transaction trx, Func<T, bool> predicate) where T : DBObject
  42.         {
  43.             if (source.IsNull())
  44.             {
  45.                 throw new ArgumentNullException("source");
  46.             }
  47.             if (predicate.IsNull())
  48.             {
  49.                 throw new ArgumentNullException("predicate");
  50.             }
  51.             return WhereImpl<T>(source, trx, predicate);
  52.         }
  53.  
  54.         public static IEnumerable<ObjectId> Where<T>(this ObjectIdCollection source, Func<T, bool> predicate) where T : DBObject
  55.         {
  56.  
  57.             return Where<T>(source, HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction,  predicate);
  58.         }
  59.  
  60.         private static IEnumerable<ObjectId> WhereImpl<T>(this ObjectIdCollection source, Transaction trx, Func<T, bool> predicate) where T : DBObject
  61.         {
  62.            
  63.             foreach (ObjectId item in source)
  64.             {
  65.                 T dbo = (T)trx.GetObject(item, OpenMode.ForRead, false, false);
  66.                 if (predicate(dbo))
  67.                 {
  68.                     yield return item;
  69.                 }
  70.  
  71.             }
  72.         }
  73.         public static ObjectIdCollection ToObjectIdCollection(this IEnumerable<ObjectId> source)
  74.         {
  75.  
  76.             return new ObjectIdCollection(source.ToArray());
  77.         }
  78.  
  79.         public static ObjectIdCollection ToObjectIdCollection(this IEnumerable<DBObject> source)
  80.         {
  81.             ObjectIdCollection ids = new ObjectIdCollection();
  82.             foreach (var dbObject in source)
  83.             {
  84.                 ids.Add(dbObject.ObjectId);
  85.             }
  86.             return ids;
  87.         }
  88.  
  89.  
  90.     }
  91. }
  92.  

TextStyleTableRecords
Code - C#: [Select]
  1. using System.Collections.Generic;
  2. using System.Linq;
  3.  
  4. namespace Autodesk.AutoCAD.DatabaseServices
  5. {
  6.     public static class TextStyleTableExtensions
  7.     {
  8.  
  9.  
  10.         public static IEnumerable<TextStyleTableRecord> GetAllTextStyleTableRecords(this TextStyleTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  11.         {
  12.             return symbolTbl.GetSymbolTableRecords<TextStyleTableRecord>(trx, mode, filter, true);
  13.         }
  14.  
  15.         public static IEnumerable<TextStyleTableRecord> GetAllTextStyleTableRecords(this TextStyleTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  16.         {
  17.             return symbolTbl.GetSymbolTableRecords<TextStyleTableRecord>(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter, true);
  18.         }
  19.  
  20.         public static IEnumerable<TextStyleTableRecord> GetTextStyleTableRecords(this TextStyleTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  21.         {
  22.             return symbolTbl.GetSymbolTableRecords<TextStyleTableRecord>(trx, mode, filter, true).Where(txt => !txt.IsShapeFile);
  23.         }
  24.  
  25.         public static IEnumerable<TextStyleTableRecord> GetTextStyleTableRecords(this TextStyleTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  26.         {
  27.             return symbolTbl.GetTextStyleTableRecords(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter);
  28.         }
  29.  
  30.         public static IEnumerable<TextStyleTableRecord> GetShapeFileTableRecords(this TextStyleTable symbolTbl, Transaction trx, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  31.         {
  32.             return symbolTbl.GetSymbolTableRecords<TextStyleTableRecord>(trx, mode, filter, true).Where(txt => txt.IsShapeFile);
  33.         }
  34.  
  35.         public static IEnumerable<TextStyleTableRecord> GetShapeFileTableRecords(this TextStyleTable symbolTbl, OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
  36.         {
  37.             return symbolTbl.GetShapeFileTableRecords(symbolTbl.Database.TransactionManager.TopTransaction, mode, filter);
  38.         }
  39.  
  40.     }
  41. }
  42.  
Title: Re: Screw it I give up
Post by: Jeff H on August 01, 2015, 12:46:26 AM
Not sure how other than post whole project
Title: Re: Screw it I give up
Post by: Atook on August 01, 2015, 02:02:54 PM
Great stuff, I can't believe I didn't find this thread earlier!

Thanks Jeff, for posting, and to others (Gile + Tony) for their contributions.

Just getting a look at how you organize a project is a huge help for a newb like me.

And the code..  :smitten:

Thanks again.
Title: Re: Screw it I give up
Post by: sybold on August 04, 2015, 07:09:19 AM
would a git repository not be a better solution to share and exchange the code, others can submit code easily that way too
Title: Re: Screw it I give up
Post by: nobody on August 07, 2015, 12:10:02 AM
You guys must have an incredible library of pretty cool stuff :) Thanks for sharing.
Title: Re: Screw it I give up
Post by: Jeff H on August 14, 2015, 03:19:57 PM
Looking for a few more folks to join private repo on github to help clean up a little and document some before making public, anyone interested let me know.
Title: Re: Screw it I give up
Post by: sybold on August 15, 2015, 08:46:40 AM
sure, no problem
Title: Re: Screw it I give up
Post by: Jeff H on August 15, 2015, 09:58:17 AM
PM me or post your github username or email registered with github
Title: Re: Screw it I give up
Post by: CADbloke on August 16, 2015, 09:57:44 PM
Hi Jeff,

I'm CADbloke on Github (surprise!) - I'll help out where I can. Step 1, change all the formatting and spacing with Resharper because people love that ....
Title: Re: Screw it I give up
Post by: JohnK on August 17, 2015, 08:53:13 AM
You started to use Git (I didn't know you used Git)?!

Now that you have a git repo you can use it as a template for future projects.
http://stackoverflow.com/questions/9106387/git-merging-from-a-template-project-no-subdirectory
Title: Re: Screw it I give up
Post by: Jeff H on August 17, 2015, 09:54:22 PM
You started to use Git (I didn't know you used Git)?!

Now that you have a git repo you can use it as a template for future projects.
http://stackoverflow.com/questions/9106387/git-merging-from-a-template-project-no-subdirectory
:-)