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
»
AutoLISP (Vanilla / Visual)
»
XDRX-API
»
Topic:
[XDrX-PlugIn(19)] Select 2 points on POLYLINE and drag out a new segment
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: [XDrX-PlugIn(19)] Select 2 points on POLYLINE and drag out a new segment (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
xdcad
Swamp Rat
Posts: 527
WWW
[XDrX-PlugIn(19)] Select 2 points on POLYLINE and drag out a new segment
«
on:
November 28, 2023, 05:29:00 PM »
Mainly introduce point monitoring dynamic drag and AcGe geometry library
Several new functions are introduced:
Code - Auto/Visual Lisp:
[Select]
1
. xdrx
-
sysvar
-
push
System variables are pushed onto the stack to save the scene
and
set
new values.
(
xdrx
-
sysvar
-
push '
(
(
"osmode"
512
)
....
(
"cmdecho"
0
)
)
)
2
. xdrx
-
sysvar
-
pop
The saved system variables are popped out of the stack, one level up,
and
the
last
scene is restored.
(
xdrx
-
sysvar
-
pop
)
Restore the
last
call to xdrx
-
sysvar
-
push, one level
(
xdrx
-
sysvar
-
pop t
)
Revert to the original call xdrx
-
sysvar
-
push
When the above two functions are paired, they can be nested
(
xdrx
-
sysvar
-
push.....
)
(
xdrx
-
sysvar
-
push....
)
.....
(
xdrx
-
sysvar
-
pop
)
(
xdrx
-
sysvar
-
pop
)
Code - Auto/Visual Lisp:
[Select]
(
defun
c:tt
(
/
int1 int2 p1 p2 pts seg inx inx1 inx2 p1
-
xline p2
-
xline p1
-
vecx p2
-
vecy p1
-
vecy
)
;|
Drag the newly added segment and construct an XLINE parallel to P1P2 according to the mouse point dynpt
Find the intersection point with P1 vertical XLINE and P2 vertical XLINE, which is the new position of the two vertices.
|;
(
defun
_callback
(
dynpt
/
xline crvcrvint1 crvcrvint2 int1 int2
)
;|
drag callback function.
The intersection method of AcGe geometry library is completely used below.
|;
(
if
(
not
(
xdrx
-
points
-
iscolinear dynpt p1 p2
)
)
;;Mouse Drag Point( DYNPT ) and P1, P2 is not collinear
(
progn
(
setq
xline
(
xdge::constructor
"kLine3d"
dynpt
(
mapcar
'
+
dynpt p1
-
vecx
)
)
crvcrvint1
(
xdge::constructor
"kCurveCurveInt3d"
xline p1
-
xline '
(
0
0
1.0
)
)
int1
(
car
(
xdge::getpropertyvalue crvcrvint1
"intpoints"
)
)
crvcrvint2
(
xdge::constructor
"kCurveCurveInt3d"
xline p2
-
xline '
(
0
0
1.0
)
)
int2
(
car
(
xdge::getpropertyvalue crvcrvint2
"intpoints"
)
)
)
;|
if have two inter pnt,set the new Vertex
|;
(
if
(
and
int1 int2
)
(
xdrx
-
setproperty e
"pointat"
(
list
inx1 int1
)
"pointat"
(
list
inx2 int2
)
)
)
(
xdge::free crvcrvint1 crvcrvint2 xline
)
;;Release GE Object Memory
)
)
)
;|
Determine whether the two points P1 and P2 are within the same segment of the polyline
|;
(
defun
_isSameSeg
(
e p1 p2
)
(
and
(
setq
seg1
(
xdrx
-
getpropertyvalue e
"onsegat"
p1
)
)
(
setq
seg2
(
xdrx
-
getpropertyvalue e
"onsegat"
p2
)
)
(
=
(
car
seg1
)
(
car
seg2
)
)
)
(
car
seg1
)
)
;|
Pick point function, sort two points according to the polyline direction,
Make sure P1 is before P2
|;
(
defun
_pick
-
pnt
(
)
(
setq
p1
(
getpoint
"
\n
Point to get starting point <exit>:"
)
)
(
setq
p2
(
getpoint
"
\n
Click to get the end point <exit>:"
)
)
(
setq
pts
(
xdrx
-
points
-
sortoncurve e
(
list
p1 p2
)
)
)
(
mapcar
'
set
'
(
p1 p2
)
(
mapcar
'
cadr
pts
)
)
)
;|
Add two vertices P1 and P2
|;
(
defun
_add
-
vertex
(
)
(
xdrx
-
setpropertyvalue e
"addvertexat"
(
list
(
1+
inx
)
p1
)
)
(
setq
seg
(
xdrx
-
getpropertyvalue e
"onsegat"
p2
)
)
(
xdrx
-
setpropertyvalue e
"addvertexat"
(
list
(
1+
(
car
seg
)
)
p2
)
)
)
;|
Construct XLINE through point PT and direction vector vecy
|;
(
defun
_construct
-
xline
-
pnt
(
pt vecy
)
(
xdge::constructor
"kLine3d"
pt
(
mapcar
'
+
pt vecy
)
)
)
;|
Add two new vertices before and after the two picked points
P1 and P2 as the two vertices of the dragged segment.
|;
(
defun
_construct
-
drag
-
2pt
(
/
)
(
setq
inx1
(
xdrx
-
getpropertyvalue e
"nearindex"
p1
)
_short
-
len
(
/
(
distance
p1 p2
)
10.0
)
)
(
setq
temp
-
p1
(
mapcar
'
+
p1
(
xdrx
-
vector
-
product p1
-
vecx _short
-
len
)
)
)
(
setq
temp
-
p2
(
mapcar
'
+
p2
(
xdrx
-
vector
-
product
(
xdrx
-
vector
-
negate p1
-
vecx
)
_short
-
len
)
)
)
(
xdrx
-
setpropertyvalue e
"addvertexat"
(
list
(
1+
inx1
)
temp
-
p1
)
)
(
setq
inx1
(
1+
inx1
)
)
(
setq
inx2
(
xdrx
-
getpropertyvalue e
"nearindex"
p2
)
)
(
xdrx
-
setpropertyvalue e
"addvertexat"
(
list
inx2 temp
-
p2
)
)
)
(
defun
_drag
-
new
-
seg
(
)
(
xdrx
-
pointmonitor
"_callback"
)
(
getpoint
"
\n
Select the appropriate location:"
)
(
xdrx
-
pointmonitor
)
)
;; Main Program
(
xdrx
-
begin
)
;;Save the specified system variable and then set the new value
(
xdrx
-
sysvar
-
push '
(
(
"osmode"
544
)
(
"autosnap"
39
)
)
)
(
if
(
and
(
setq
e
(
car
(
xdrx
-
entsel
"
\n
Select Polyline <Exit>:"
'
(
(
0
.
"*polyline"
)
)
)
)
)
(
_pick
-
pnt
)
(
setq
inx
(
_isSameSeg e p1 p2
)
)
(
_add
-
vertex
)
(
setq
p1
-
vecx
(
xdrx
-
getpropertyvalue e
"firstderiv"
p1
)
p1
-
vecy
(
xdrx
-
vector
-
perpvector p1
-
vecx
)
)
(
setq
p1
-
xline
(
_construct
-
xline
-
pnt p1 p1
-
vecy
)
)
(
setq
p2
-
xline
(
_construct
-
xline
-
pnt p2 p1
-
vecy
)
)
)
(
progn
(
_construct
-
drag
-
2pt
)
(
_drag
-
new
-
seg
)
)
)
;;restore system variable
(
xdrx
-
sysvar
-
pop
)
(
xdrx
-
end
)
(
princ
)
)
«
Last Edit: November 28, 2023, 07:58:36 PM by xdcad
»
Logged
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net
Atook
Swamp Rat
Posts: 1031
AKA Tim
WWW
Re: [XDrX-PlugIn(19)] Select 2 points on POLYLINE and drag out a new segment
«
Reply #1 on:
November 28, 2023, 10:28:30 PM »
Very nice, that looks like it could be quite useful for some.
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
XDRX-API
»
Topic:
[XDrX-PlugIn(19)] Select 2 points on POLYLINE and drag out a new segment