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:
write description for all polyline
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: write description for all polyline (Read 1393 times)
0 Members and 1 Guest are viewing this topic.
A-SABER
Mosquito
Posts: 11
write description for all polyline
«
on:
February 05, 2021, 07:36:51 PM »
the folwing code to write polyline name in each polyline the result is the same pic it's ok
I need to write a description for all parcels using code
same like this
PH 101
NORTH ---
SOUTH PH 105
EAST PH 103
WEST ---
anther example
PH 106
NORTH PH 103
SOUT PH 109
EAST PH 106
WEST PH 105
check each parcel if has parcel in north ok write it, not has parcel, not written.
and the same check-in (SOUTH - EAST - WEST )
Code - C#:
[Select]
public
static
void
polylinenumber
(
)
{
double
txth
=
1
;
int
snumber
=
101
;
Document doc
=
Autodesk
.
AutoCAD
.
ApplicationServices
.
Application
.
DocumentManager
.
MdiActiveDocument
;
Database db
=
doc
.
Database
;
Editor ed
=
doc
.
Editor
;
using
(
Transaction trans
=
db
.
TransactionManager
.
StartTransaction
(
)
)
{
try
{
BlockTable bt
=
trans
.
GetObject
(
db
.
BlockTableId
, OpenMode
.
ForRead
)
as
BlockTable
;
BlockTableRecord btr
=
trans
.
GetObject
(
bt
[
BlockTableRecord
.
ModelSpace
]
, OpenMode
.
ForWrite
)
as
BlockTableRecord
;
TypedValue
[
]
tv
=
new
TypedValue
[
1
]
;
tv
.
SetValue
(
new
TypedValue
(
(
int
)
DxfCode
.
Start
,
"LWPOLYLINE"
)
,
0
)
;
SelectionFilter filter
=
new
SelectionFilter
(
tv
)
;
PromptSelectionResult ssPrompt
;
ssPrompt
=
ed
.
GetSelection
(
filter
)
;
if
(
ssPrompt
.
Status
==
PromptStatus
.
OK
)
{
SelectionSet ss
=
ssPrompt
.
Value
;
List
<
Polyline
>
lspl
=
new
List
<
Polyline
>
(
)
;
foreach
(
SelectedObject sObj
in
ss
)
{
Polyline poly
=
trans
.
GetObject
(
sObj
.
ObjectId
, OpenMode
.
ForWrite
)
as
Polyline
;
lspl
.
Add
(
poly
)
;
}
var
sortedpolyList
=
lspl
.
OrderByDescending
(
p
=>
p
.
StartPoint
.
Y
)
.
ThenBy
(
p
=>
p
.
StartPoint
.
X
)
;
//var sortedpolyList = lspl.OrderByDescending(p => p.StartPoint.Y).ThenBy(p => p.StartPoint.X);
foreach
(
Polyline item
in
sortedpolyList
)
{
DBText txtpl
=
new
DBText
(
)
;
txtpl
.
SetDatabaseDefaults
(
)
;
txtpl
.
TextString
=
"PH "
+
snumber
.
ToString
(
)
;
//Point3d p2 = PolylineExtensions.Centroid(item);
txtpl
.
Position
=
PolylineExtensions
.
Centroid
(
item
)
;
txtpl
.
Rotation
=
0
;
txtpl
.
Height
=
txth
;
btr
.
AppendEntity
(
txtpl
)
;
trans
.
AddNewlyCreatedDBObject
(
txtpl,
true
)
;
snumber
++;
}
trans
.
Commit
(
)
;
}
}
catch
(
System
.
Exception
ex
)
{
ed
.
WriteMessage
(
"Error pls chek "
+
ex
.
Message
)
;
trans
.
Abort
(
)
;
}
}
}
«
Last Edit: February 13, 2021, 12:40:37 AM by A-SABER
»
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
write description for all polyline