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)
»
Topic:
Help: Export coordinates from block attribute
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Help: Export coordinates from block attribute (Read 617 times)
0 Members and 1 Guest are viewing this topic.
mhy3sx
Newt
Posts: 120
Help: Export coordinates from block attribute
«
on:
April 06, 2023, 03:19:07 AM »
Hi, I use this code to export coordinates from my attibute blocks. Is it possible to change the code to work only for one block with name STATION.dwg (ignore all the other blocks)?
Code - Auto/Visual Lisp:
[Select]
(
defun
c:PXYZD
(
/
*error*
del des ent idx lst obj ord out rtn sel
)
(
defun
*error*
(
msg
)
(
if
(
=
'file
(
type
des
)
)
(
close
des
)
)
(
if
(
not
(
wcmatch
(
strcase
msg t
)
"*break,*cancel*,*exit*"
)
)
(
princ
(
strcat
"
\n
Error: "
msg
)
)
)
(
princ
)
)
(
setq
ord '
(
"POINT"
POINT
-
X POINT
-
Y
"ELEV"
"DESC"
)
out
(
LM:uniquefilename
(
strcat
(
getvar
'dwgprefix
)
(
vl-filename-base
(
getvar
'dwgname
)
)
)
".crd"
)
del
","
)
(
if
(
setq
sel
(
ssget
'
(
(
0
.
"INSERT"
)
(
66
.
1
)
)
)
)
(
if
(
setq
des
(
open
out
"w"
)
)
(
progn
(
repeat
(
setq
idx
(
sslength
sel
)
)
(
setq
ent
(
ssname
sel
(
setq
idx
(
1-
idx
)
)
)
obj
(
vlax
-
ename
->
vla-object
ent
)
)
(
setq
lst
(
append
(
mapcar
'
(
lambda
(
a b
)
(
cons
a
(
rtos
b
)
)
)
'
(
point
-
x point
-
y point
-
z
)
(
trans
(
cdr
(
assoc
10
(
entget
ent
)
)
)
ent
0
)
)
(
mapcar
'
(
lambda
(
x
)
(
cons
(
strcase
(
vla-get-tagstring
x
)
)
(
vla-get-textstring
x
)
)
)
(
append
(
vlax-invoke
obj 'getattributes
)
(
vlax-invoke
obj 'getconstantattributes
)
)
)
)
)
;(setq rtn (cons (vl-remove 'nil (mapcar '(lambda ( x ) (cdr (assoc x lst))) ord)) rtn))
(
if
(
and
(
setq
pnt
(
assoc
"POINT"
lst
)
)
(
/=
""
(
cdr
pnt
)
)
)
(
setq
rtn
(
cons
(
mapcar
'
(
lambda
(
x
/
v
)
(
if
(
and
(
setq
v
(
cdr
(
assoc
x lst
)
)
)
(
/=
""
v
)
)
v
"0.00"
)
)
ord
)
rtn
)
)
)
)
(
foreach
idx
(
LM:alphanumsort
-
i
(
mapcar
'
car
rtn
)
)
(
write-line
(
LM:lst
->
str
(
nth
idx rtn
)
del
)
des
)
)
(
setq
des
(
close
des
)
)
)
(
princ
(
strcat
"
\n
Unable to open file:
\"
"
out
"
\"
for writing."
)
)
)
)
(
princ
)
)
;; List to String - Lee Mac
;; Concatenates each string in a list, separated by a given delimiter
(
defun
LM:lst
->
str
(
lst del
)
(
if
(
cdr
lst
)
(
strcat
(
car
lst
)
del
(
LM:lst
->
str
(
cdr
lst
)
del
)
)
(
car
lst
)
)
)
;; Unique Filename - Lee Mac
;; Returns a unique filename for a given path & file extension
(
defun
LM:uniquefilename
(
pth ext
/
fnm tmp
)
(
if
(
findfile
(
setq
fnm
(
strcat
pth ext
)
)
)
(
progn
(
setq
tmp
1
)
(
while
(
findfile
(
setq
fnm
(
strcat
pth
"("
(
itoa
(
setq
tmp
(
1+
tmp
)
)
)
")"
ext
)
)
)
)
)
)
fnm
)
;; Alphanumerical Sort-i - Lee Mac
;; Sorts a list of strings containing a combination of alphabetical & numerical characters and returns the indices.
(
defun
LM:alphanumsort
-
i
(
lst
)
(
vl-sort-i
(
mapcar
'LM:splitstring lst
)
(
function
(
lambda
(
a b
/
x y
)
(
while
(
and
(
setq
x
(
car
a
)
)
(
setq
y
(
car
b
)
)
(
=
x y
)
)
(
setq
a
(
cdr
a
)
b
(
cdr
b
)
)
)
(
cond
(
(
null
x
)
b
)
(
(
null
y
)
nil
)
(
(
and
(
numberp
x
)
(
numberp
y
)
)
(
<
x y
)
)
(
(
numberp
x
)
)
(
(
numberp
y
)
nil
)
(
(
<
x y
)
)
)
)
)
)
)
;; Split String - Lee Mac
;; Splits a string into a list of text and numbers
(
defun
LM:splitstring
(
str
)
(
(
lambda
(
l
)
(
read
(
strcat
"("
(
vl
-
list
->
string
(
apply
'
append
(
mapcar
(
function
(
lambda
(
a b c
)
(
cond
(
(
or
(
=
34
b
)
(
=
92
b
)
)
(
list
32
34
92
b
34
32
)
)
(
(
or
(
<
47
b
58
)
;(and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
(
and
(
=
46
b
)
(
<
47
a
58
)
(
<
47
c
58
)
)
)
(
list
b
)
)
(
(
list
32
34
b
34
32
)
)
)
)
)
(
cons
nil
l
)
l
(
append
(
cdr
l
)
'
(
(
)
)
)
)
)
)
")"
)
)
)
(
vl
-
string
->
list
str
)
)
)
(
vl-load-com
)
(
princ
)
Thanks
Logged
kozmos
Newt
Posts: 114
Re: Help: Export coordinates from block attribute
«
Reply #1 on:
April 06, 2023, 03:30:13 AM »
simply change
(setq sel (ssget '((0 . "INSERT") (66 . 1))))
into
(setq sel (ssget '((0 . "INSERT")(2 . "STATION") (66 . 1))))
Logged
KozMos Inc.
Lee Mac
Seagull
Posts: 12912
London, England
WWW
Re: Help: Export coordinates from block attribute
«
Reply #2 on:
April 17, 2023, 07:18:37 PM »
Original source
You may also wish to include anonymous references in the selection (using the filter
"`*U*"
) and then check the ActiveX
effectivename
property within the
repeat
loop if your blocks are dynamic, otherwise they won't be selected if their dynamic parameters have been altered following insertion.
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Help: Export coordinates from block attribute