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:
Coordinates of a Picked point on the screen
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Coordinates of a Picked point on the screen (Read 1625 times)
0 Members and 1 Guest are viewing this topic.
emrahctrk
Mosquito
Posts: 3
Coordinates of a Picked point on the screen
«
on:
November 26, 2020, 09:38:10 AM »
hi, can you tell me how can I get coordinate of a point picked on the screen? I want to write X and Y coordinates on the screen where I will pick. Do you have any c# codes for it. I am new in C# so I am still learning.
Thank you all
Logged
gile
Gator
Posts: 2507
Marseille, France
WWW
Re: Coordinates of a Picked point on the screen
«
Reply #1 on:
November 26, 2020, 01:57:27 PM »
Hi,
Here's a simple and commented example:
Code - C#:
[Select]
[
CommandMethod
(
"PRINTCOORDS"
)
]
public
static
void
PrintCoordinates
(
)
{
Document doc
=
Application
.
DocumentManager
.
MdiActiveDocument
;
Database db
=
doc
.
Database
;
Editor ed
=
doc
.
Editor
;
// prompt the user to pick a point
PromptPointResult ppr
=
ed
.
GetPoint
(
"
\n
Pick a point: "
)
;
// return if the user cancelled
if
(
ppr
.
Status
!=
PromptStatus
.
OK
)
return
;
Point3d pickedPoint
=
ppr
.
Value
;
// start a transaction to add a text to the current space
using
(
Transaction tr
=
db
.
TransactionManager
.
StartTransaction
(
)
)
{
// open the current space BlockTableRecord for write
BlockTableRecord curSpace
=
(
BlockTableRecord
)
tr
.
GetObject
(
db
.
CurrentSpaceId
, OpenMode
.
ForWrite
)
;
// create a new DBText instance and set its properties
DBText text
=
new
DBText
(
)
{
Position
=
pickedPoint,
TextString
=
$
"{pickedPoint.X:0.00}, {pickedPoint.Y:0.00}"
}
;
// transform the text to UCS
text
.
TransformBy
(
ed
.
CurrentUserCoordinateSystem
)
;
// append the text to current space
curSpace
.
AppendEntity
(
text
)
;
// add the text to the transaction
tr
.
AddNewlyCreatedDBObject
(
text,
true
)
;
// commit the changes
tr
.
Commit
(
)
;
}
}
Logged
Speaking English as a French Frog
emrahctrk
Mosquito
Posts: 3
Re: Coordinates of a Picked point on the screen
«
Reply #2 on:
November 27, 2020, 06:21:53 AM »
thank you. It is useful
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
Coordinates of a Picked point on the screen