Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
.NET
»
Topic:
Get layout name while in its BlockTableRecord object
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Get layout name while in its BlockTableRecord object (Read 1446 times)
0 Members and 1 Guest are viewing this topic.
Coder
Swamp Rat
Posts: 827
Get layout name while in its BlockTableRecord object
«
on:
April 13, 2016, 03:34:20 AM »
Hello,
I am trying to print all object names in Model space and layouts (object name + layer + layout name) to command line but I am facing a problem with the layout name.
Can anyone tell me how to get the layout name while I am in its space ?.
Thanks in advance.
Code - C#:
[Select]
using
(
Transaction tr
=
db
.
TransactionManager
.
StartTransaction
(
)
)
{
BlockTable blks
=
(
BlockTable
)
tr
.
GetObject
(
db
.
BlockTableId
, OpenMode
.
ForRead
)
;
foreach
(
var
item
in
blks
)
{
BlockTableRecord rec
=
(
BlockTableRecord
)
tr
.
GetObject
(
item, OpenMode
.
ForRead
)
;
if
(
rec
.
IsLayout
)
{
Layout lay
=
(
Layout
)
tr
.
GetObject
(
rec
.
ObjectId
, OpenMode
.
ForRead
)
;
foreach
(
var
obj
in
rec
)
{
ent
=
(
Entity
)
tr
.
GetObject
(
obj, OpenMode
.
ForRead
)
;
ed
.
WriteMessage
(
"
\n
Name: ("
+
ent
.
GetType
(
)
.
Name
+
") Layer: ("
+
ent
.
Layer
+
") Space: ("
+
lay
.
LayoutName
+
")."
)
;
ed
.
WriteMessage
(
"
\n
"
)
;
}
}
}
}
Logged
gile
Gator
Posts: 2520
Marseille, France
WWW
Re: Get layout name while in its BlockTableRecord object
«
Reply #1 on:
April 13, 2016, 03:54:04 AM »
Hi,
Juste replace:
Code - C#:
[Select]
Layout lay
=
(
Layout
)
tr
.
GetObject
(
rec
.
ObjectId
, OpenMode
.
ForRead
)
;
with:
Code - C#:
[Select]
Layout lay
=
(
Layout
)
tr
.
GetObject
(
rec
.
LayoutId
, OpenMode
.
ForRead
)
;
Logged
Speaking English as a French Frog
Coder
Swamp Rat
Posts: 827
Re: Get layout name while in its BlockTableRecord object
«
Reply #2 on:
April 13, 2016, 04:13:10 AM »
Thank you gile , that works great.
After running the program successfully the program printed (viewport) two times and I am sure I have only one viewport in each layout, What is wrong with that?
Thanks
Logged
gile
Gator
Posts: 2520
Marseille, France
WWW
Re: Get layout name while in its BlockTableRecord object
«
Reply #3 on:
April 13, 2016, 05:38:56 AM »
Nothing wrong, each layout has its own viewport which Number property = 1 (CVPORT sysvar).
Logged
Speaking English as a French Frog
Coder
Swamp Rat
Posts: 827
Re: Get layout name while in its BlockTableRecord object
«
Reply #4 on:
April 13, 2016, 06:47:47 AM »
Many thanks gile for your help.
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
Get layout name while in its BlockTableRecord object