.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessiing all local block definition in a file through managed code

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
479 Views, 14 Replies

Accessiing all local block definition in a file through managed code

I am using C# to customize AutoCAD 2008.
My requirement is to access all local block definitions in a file without iterating through all objects
using managed code. Below code will get me model space.
Autodesk.AutoCAD.DatabaseServices.Transaction trans1 = oDoc.TransactionManager.StartTransaction();
Autodesk.AutoCAD.DatabaseServices.BlockTableRecord bTRecord = (Autodesk.AutoCAD.DatabaseServices.BlockTableRecord) trans1.GetObject(bTable[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);

Now how do get all local block definitions in this space or file?
14 REPLIES 14
Message 2 of 15
NathTay
in reply to: Anonymous

It sounds like you mean block reference. Do you know the difference between a block definition and a block reference?
Message 3 of 15
Anonymous
in reply to: Anonymous

Customizing AutoCAD requires skills and experience in the subject, not
merely C# programming skills.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message
news:6161575@discussion.autodesk.com...
I am using C# to customize AutoCAD 2008. My requirement is to access all
local block definitions in a file without iterating through all objects
using managed code. Below code will get me model space.
Autodesk.AutoCAD.DatabaseServices.Transaction trans1 =
oDoc.TransactionManager.StartTransaction();
Autodesk.AutoCAD.DatabaseServices.BlockTableRecord bTRecord =
(Autodesk.AutoCAD.DatabaseServices.BlockTableRecord)
trans1.GetObject(bTable[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace],
Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead); Now how do get all
local block definitions in this space or file?
Message 4 of 15
Anonymous
in reply to: Anonymous

Thanks for the response.

In API terms Block definition is "BlockTableRecord" and Block reference is "BlockReference".

For AutoCAD users Block definition is named object and Block reference are instances of these block definitions.

As of now my program iterates through all the AutoCAD objects to collect all the block references by which I can get block definition to do certain actions. Right now I am thinking to fine tune the code to query all local block definitions’ and to get all its references.
I know from method BlockTableRecord.GetBlockReferenceIds(), I can get all its references.
Message 5 of 15
Anonymous
in reply to: Anonymous

Good Morning Tony Tanzillo,

Thanks for the feedback and you are right. I am in the process of building my skills in AutoCAD customization through managed code.

I do know how to get all block definitions in the dwg through AutoCAD interop.
I am always ending up with broken references to AxDBLib intertop due to another Autodesk product [Autodesk Inventor] in my system. We use Inventor API extensively and very rarely use AC and MCAD API’s.
Due to above issue I can not access Common name space.

Hence I was trying to query all local BlackTableRecord (Block definition) in the dwg through managed code.
Do you have any idea how to do this?


Have a nice day.

Vedamurthy T G
Message 6 of 15
NathTay
in reply to: Anonymous

In the material you are using for learning search for "SelectionSet".
Message 7 of 15
Anonymous
in reply to: Anonymous

You're on the right track, GetBlockReferenceIds() is what you would use to
get all insertions of a block, from its BlockTableRecord.

I don't know what to tell you about the Inventor/AXDBLib problem, sorry.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message
news:6162466@discussion.autodesk.com...
Good Morning Tony Tanzillo, Thanks for the feedback and you are right. I am
in the process of building my skills in AutoCAD customization through
managed code. I do know how to get all block definitions in the dwg through
AutoCAD interop. I am always ending up with broken references to AxDBLib
intertop due to another Autodesk product [Autodesk Inventor] in my system.
We use Inventor API extensively and very rarely use AC and MCAD API's. Due
to above issue I can not access Common name space. Hence I was trying to
query all local BlackTableRecord (Block definition) in the dwg through
managed code. Do you have any idea how to do this? Have a nice day.
Vedamurthy T G
Message 8 of 15
Anonymous
in reply to: Anonymous

Can you please tell me how to get all local BlockTableRecords in a drawing?

[I need to get only Block deifnitions not Block references]
Message 9 of 15
Anonymous
in reply to: Anonymous

You open the block table, and iterate over the ObjectIds of the block table
records using foreach()

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message
news:6163689@discussion.autodesk.com...
Can you please tell me how to get all local BlockTableRecords in a drawing?
[I need to get only Block deifnitions not Block references]
Message 10 of 15
Anonymous
in reply to: Anonymous

Fantastic, Thanks for the help. This will allow us to fine tune my existing program.
By this I can get rid of most of Interop codes. I implemented below code to get local block definitions.
Autodesk.AutoCAD.DatabaseServices.SymbolTableEnumerator blockLists = bTable.GetEnumerator();
while (blockLists.MoveNext())
{
Autodesk.AutoCAD.DatabaseServices.BlockTableRecord blockSym = (Autodesk.AutoCAD.DatabaseServices.BlockTableRecord)trans1.GetObject(blockLists.Current, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
if(!blockSym.IsAnonymous && !blockSym.IsLayout &&
!blockSym.IsFromExternalReference &&
!blockSym.IsFromOverlayReference &&
!blockSym.HasAttributeDefinitions)
acadEd.WriteMessage(blockSym.Name + "\n");
}

I need one more help. I am working towards only using managed codes in my program.
Right now I am using CAO Interop for my database connection utilities.
Is it possible to get data source, link and label templates and links only by using managed codes?
Message 11 of 15
NathTay
in reply to: Anonymous

Personally I would use foreach instead of declaring a SymbolTableEnumerator.

You may want to also check the IsErased property.

http://msdn.microsoft.com/en-us/data/aa937699.aspx
Message 12 of 15
Anonymous
in reply to: Anonymous

foreach statement cannot be used with enumerators.

ADO.Net will not help to access dbConnect information like getting link template or label template or links used in the drawing. Edited by: vedamurthy.t.g@tantrainfosolutions.com on Apr 17, 2009 10:00 PM
Message 13 of 15
Anonymous
in reply to: Anonymous


SymbolTable implements IEnumerable
--
Bobby
C. Jones


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
foreach
statement cannot be used with enumerators. ADO.Net will not help to access
dbConnect information like getting link template or label template or links
used in the drawing. Edited by: vedamurthy.t.g@tantrainfosolutions.com on Apr
17, 2009 10:00 PM
Message 14 of 15
NathTay
in reply to: Anonymous

> foreach statement cannot be used with enumerators.
My suggestion was to use forech instead of using enumerators

>ADO.Net will not help to access dbConnect information like getting link template or label template or links used in the drawing
Sorry, I realised after I posted I was thinking DAO not CAO Edited by: NathTay on Apr 20, 2009 8:29 AM
Message 15 of 15
Anonymous
in reply to: Anonymous

Thank you.

It worked.
I skipped GetEnumerator() method to use foreach.

Which menas that BlockTable is a collection of BlockTableRecord.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost