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

Collecting objects on a Layout for erasing

4 REPLIES 4
Reply
Message 1 of 5
FrankLenoir
339 Views, 4 Replies

Collecting objects on a Layout for erasing

I am new to using .NET with AutoCAD.
I want to erase all objects present on a layout. I have tried several ways and none of them succeeded.
Does anyone know how to get to objects on a layout for erasing?

Thanks for the help!

Frank
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: FrankLenoir

A layout is a block. Once you have the layout object you have access to the
entity objects it contains.
--
Bobby C. Jones
http://bobbycjones.spaces.live.com

wrote in message news:6292555@discussion.autodesk.com...
I am new to using .NET with AutoCAD.
I want to erase all objects present on a layout. I have tried several ways
and none of them succeeded.
Does anyone know how to get to objects on a layout for erasing?

Thanks for the help!

Frank
Message 3 of 5
FrankLenoir
in reply to: FrankLenoir

I already tried to access the layout as a block.
I tried following

Dim acBlkTbl As BlockTable = CType(acTrans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acBlkTblRec As BlockTableRecord = CType(acTrans.GetObject(acBlkTbl(layoutId.ToString), OpenMode.ForRead), BlockTableRecord)

and

Dim acBlkTbl As BlockTable = CType(acTrans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acBlkTblRec As BlockTableRecord = CType(acTrans.GetObject(acBlkTbl(LayoutName), OpenMode.ForRead), BlockTableRecord)

layoutID is the ObjectId of the layout
Before a check is done if the layout does exist

Both ended with runtime exception 'eKeyNotFound'
Message 4 of 5
Anonymous
in reply to: FrankLenoir

What Bobby told you isn't precisely correct, which may be what
lead you off track.

A Layout is NOT a block.

A Layout is an object that represents a layout tab. Each layout
tab displays the contents of a block (whose names begin with
'Paper_Space' followed by a number, or 'Model_Space' for the
model tab). In other words, the entities that appear on a layout
tab are contained in a block that's associated with the layout.

If you have the ObjectId of the layout, open it and cast it to a
Layout Object and then get the ObjectId of the BlockTableRecord
that contains the entities appearing on the layout from the Layout's
BlockTableRecordId property. Then open that id, and cast it to a
BlockTableRecord object object and iterate over its contents using
For Each/Next to get the ObjectId of each entity in the block.


--
http://www.caddzone.com

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

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6294062@discussion.autodesk.com...
I already tried to access the layout as a block.
I tried following

Dim acBlkTbl As BlockTable =
CType(acTrans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acBlkTblRec As BlockTableRecord =
CType(acTrans.GetObject(acBlkTbl(layoutId.ToString), OpenMode.ForRead),
BlockTableRecord)

and

Dim acBlkTbl As BlockTable =
CType(acTrans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acBlkTblRec As BlockTableRecord =
CType(acTrans.GetObject(acBlkTbl(LayoutName), OpenMode.ForRead),
BlockTableRecord)

layoutID is the ObjectId of the layout
Before a check is done if the layout does exist

Both ended with runtime exception 'eKeyNotFound'
Message 5 of 5
FrankLenoir
in reply to: FrankLenoir

I found the solution.
Here it is:

Dim acLayout As Layout = CType(acTrans.GetObject(layoutId, OpenMode.ForRead), Layout)
Dim acBlkTblRec As BlockTableRecord = CType(acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord)
For Each acObjId As ObjectId In acBlkTblRec
Dim acObject As DBObject = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acObject.Erase(True)
Next

Thanks for your help.

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