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:
how to call function and store output in variable ?
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: how to call function and store output in variable ? (Read 1519 times)
0 Members and 1 Guest are viewing this topic.
vincent.r
Newt
Posts: 101
how to call function and store output in variable ?
«
on:
December 09, 2019, 05:41:14 AM »
I made a function to get list of electrical connection data to block. List consist of sub lists of tag, attribute value & insertion point.
Final output stored in variable "masterconnectiondata". Function performs fine.
I am trying to call this function from another program
Code - Auto/Visual Lisp:
[Select]
(
setq
masterconnectiondata1
(
vr:checkconnectionpoints sortedlist2
)
)
but not able to store data in variable masterconnectiondata1.
Am I made mistake somewhere ?
code -
Code - Auto/Visual Lisp:
[Select]
(
defun
vr:checkconnectionpoints
(
sortedlist1
/
dataextractfi1 dataextractatt1 dataextractattval1 dataextracttagval1 dataextractinsval1 connectionpointlist connectionlist
)
(
while
(
/=
(
length
sortedlist1
)
0
)
(
setq
dataextractfi1
(
car
sortedlist1
)
)
(
setq
dataextractatt1
(
entnext
dataextractfi1
)
)
(
while
(
/=
(
cdr
(
assoc
0
(
entget
dataextractatt1
)
)
)
"SEQEND"
)
(
setq
dataextractattval1
(
cdr
(
assoc
1
(
entget
dataextractatt1
)
)
)
)
(
setq
dataextracttagval1
(
cdr
(
assoc
2
(
entget
dataextractatt1
)
)
)
)
(
setq
dataextractinsval1
(
cdr
(
assoc
10
(
entget
dataextractatt1
)
)
)
)
;(SETQ dataextracttagval1 "X4TERMDESC01")
(
if
(
and
(
setq
x4testpoint
(
vl-string-search
"X4TERM"
dataextracttagval1
0
)
)
(
=
(
vl-string-search
"DESC"
dataextracttagval1
)
nil
)
)
(
progn
(
setq
connectionpointlist
(
cons
dataextracttagval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
cons
dataextractattval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
cons
dataextractinsval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
reverse
connectionpointlist
)
)
(
setq
connectionlist
(
cons
connectionpointlist connectionlist
)
)
;(setq connectionlist nil)
(
setq
connectionpointlist
nil
)
)
)
(
setq
dataextractatt1
(
entnext
dataextractatt1
)
)
)
(
setq
masterconnectiondata
(
cons
connectionlist masterconnectiondata
)
)
(
setq
connectionlist
nil
)
(
setq
sortedlist1
(
cdr
sortedlist1
)
)
)
)
EDIT (John): Added code tags.
«
Last Edit: December 09, 2019, 11:55:15 AM by John Kaul (Se7en)
»
Logged
ribarm
Gator
Posts: 3274
Marko Ribar, architect
WWW
Re: how to call function and store output in variable ?
«
Reply #1 on:
December 09, 2019, 05:57:34 AM »
masterconnectiondata variable must be last statement before ending closing bracked of zour sub function... It should also be localized among other localized variables...
Logged
Marko Ribar, d.i.a.
(graduated engineer of architecture)
M.R. on Youtube
vincent.r
Newt
Posts: 101
Re: how to call function and store output in variable ?
«
Reply #2 on:
December 09, 2019, 06:38:15 AM »
Thanks for efforts ribarm !
Tried your suggestion. But it doesn't work. It gives nil output.
Modifies code is -
Code - Auto/Visual Lisp:
[Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(
defun
vr:checkconnectionpoints
(
sortedlist1
/
dataextractfi1 dataextractatt1 dataextractattval1 dataextracttagval1 dataextractinsval1 connectionpointlist connectionlist masterconnectiondata masterconnectiondataresult
)
(
while
(
/=
(
length
sortedlist1
)
0
)
(
setq
dataextractfi1
(
car
sortedlist1
)
)
(
setq
dataextractatt1
(
entnext
dataextractfi1
)
)
(
while
(
/=
(
cdr
(
assoc
0
(
entget
dataextractatt1
)
)
)
"SEQEND"
)
(
setq
dataextractattval1
(
cdr
(
assoc
1
(
entget
dataextractatt1
)
)
)
)
(
setq
dataextracttagval1
(
cdr
(
assoc
2
(
entget
dataextractatt1
)
)
)
)
(
setq
dataextractinsval1
(
cdr
(
assoc
10
(
entget
dataextractatt1
)
)
)
)
;(SETQ dataextracttagval1 "X4TERMDESC01")
(
if
(
and
(
setq
x4testpoint
(
vl-string-search
"X4TERM"
dataextracttagval1
0
)
)
(
=
(
vl-string-search
"DESC"
dataextracttagval1
)
nil
)
)
(
progn
(
setq
connectionpointlist
(
cons
dataextracttagval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
cons
dataextractattval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
cons
dataextractinsval1 connectionpointlist
)
)
(
setq
connectionpointlist
(
reverse
connectionpointlist
)
)
(
setq
connectionlist
(
cons
connectionpointlist connectionlist
)
)
;(setq connectionlist nil)
(
setq
connectionpointlist
nil
)
)
)
(
setq
dataextractatt1
(
entnext
dataextractatt1
)
)
)
(
setq
connectionlist
nil
)
(
setq
sortedlist1
(
cdr
sortedlist1
)
)
(
setq
masterconnectiondata
(
cons
connectionlist masterconnectiondata
)
)
)
(
setq
masterconnectiondataresult masterconnectiondata
)
)
EDIT (John): Added code tags.
«
Last Edit: December 09, 2019, 11:55:42 AM by John Kaul (Se7en)
»
Logged
Lee Mac
Seagull
Posts: 12914
London, England
WWW
Re: how to call function and store output in variable ?
«
Reply #3 on:
December 09, 2019, 06:56:22 AM »
Amongst other issues, you are setting the data you have collected to nil before constructing the output list -
Code - Auto/Visual Lisp:
[Select]
(
setq
connectionlist
nil
)
;; <----- connectionlist is now nil
(
setq
sortedlist1
(
cdr
sortedlist1
)
)
(
setq
masterconnectiondata
(
cons
connectionlist masterconnectiondata
)
)
;; <----- masterconnectiondata will be a list of nils
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
vincent.r
Newt
Posts: 101
Re: how to call function and store output in variable ?
«
Reply #4 on:
December 09, 2019, 07:12:38 AM »
Oh! my mistake. Thank you Lisp Master.
Thanks for efforts.
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
how to call function and store output in variable ?