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:
Determine if Dynamic Block has an Alignment Paramter
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Determine if Dynamic Block has an Alignment Paramter (Read 344 times)
0 Members and 1 Guest are viewing this topic.
cmwade77
Swamp Rat
Posts: 1443
Determine if Dynamic Block has an Alignment Paramter
«
on:
February 26, 2024, 06:29:57 PM »
I would like to know if there is a way to determine if a dynamic block contains an Alignment parameter? I tried searching for a parameter with the name Alignment, but unfortunately Alignment parameters can't be named and don't get the hardcoded name Alignment listed. This is what I tried:
Code - C#:
[Select]
private
static
bool
HasAlignmentParameter
(
BlockReference blockRef
)
{
if
(
blockRef
.
IsDynamicBlock
)
{
foreach
(
DynamicBlockReferenceProperty prop
in
blockRef
.
DynamicBlockReferencePropertyCollection
)
{
if
(
prop
.
PropertyName
.
Equals
(
"Alignment"
, StringComparison
.
OrdinalIgnoreCase
)
)
{
return
true
;
}
}
}
return
false
;
}
Logged
gile
Gator
Posts: 2507
Marseille, France
WWW
Re: Determine if Dynamic Block has an Alignment Paramter
«
Reply #1 on:
February 27, 2024, 04:10:14 AM »
Hi,
As far as I know, the .NET API does not expose this.
You can get it by inspecting the BlockTableRecord DXF data (see the attached (work in progress) extension methods).
Here's a testing command:
Code - C#:
[Select]
[
CommandMethod
(
"TEST"
)
]
public
static
void
Test
(
)
{
var
doc
=
Application
.
DocumentManager
.
MdiActiveDocument
;
var
db
=
doc
.
Database
;
var
ed
=
doc
.
Editor
;
var
promptEntityOptions
=
new
PromptEntityOptions
(
"
\n
Select Block: "
)
;
promptEntityOptions
.
SetRejectMessage
(
"
\n
Selected object is not a block reference."
)
;
promptEntityOptions
.
AddAllowedClass
(
typeof
(
BlockReference
)
,
true
)
;
var
promptEntityResult
=
ed
.
GetEntity
(
promptEntityOptions
)
;
if
(
promptEntityResult
.
Status
!=
PromptStatus
.
OK
)
return
;
using
(
var
tr
=
db
.
TransactionManager
.
StartOpenCloseTransaction
(
)
)
{
var
br
=
(
BlockReference
)
tr
.
GetObject
(
promptEntityResult
.
ObjectId
, OpenMode
.
ForRead
)
;
var
btr
=
(
BlockTableRecord
)
tr
.
GetObject
(
br
.
DynamicBlockTableRecord
, OpenMode
.
ForRead
)
;
try
{
if
(
btr
.
GetDynamicPropertiesData
(
tr
)
.
Any
(
tvs
=>
tvs
.
Any
(
tv
=>
tv
==
new
TypedValue
(
0
,
"BLOCKALIGNMENTPARAMETER"
)
)
)
)
ed
.
WriteMessage
(
"
\n
Select block reference has an alignment parameter"
)
;
else
ed
.
WriteMessage
(
"
\n
Select block reference has none alignment parameter"
)
;
}
catch
(
System
.
Exception
ex
)
{
ed
.
WriteMessage
(
$
"
\n
{ex.Message}"
)
;
}
tr
.
Commit
(
)
;
}
}
«
Last Edit: February 27, 2024, 05:35:23 AM by gile
»
Logged
Speaking English as a French Frog
cmwade77
Swamp Rat
Posts: 1443
Re: Determine if Dynamic Block has an Alignment Paramter
«
Reply #2 on:
February 28, 2024, 12:32:39 PM »
Wow, thank you, no wonder why I couldn't find it in a google search. This seems like such a basic thing, you would expect it to be there.
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
Determine if Dynamic Block has an Alignment Paramter