Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

if statement help

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
787 Views, 14 Replies

if statement help

I have so far put together this. The first part works where it does the tablesearch and if it returns a nil value for the wanted dimstyle it then creates it. I'm having trouble with the else part. Where if the style already exists, it simply switches to it. AutoCAD has either returned with an error or tries to recreate the layer and that is not wanted.


(defun QQ ()
(setq D1 (tblsearch "dimstyle" "VAAFULL"))
(if
(/= D1 "VAAFULL") ;must be false
(progn ;then
lots of stuff here for setting up the dimstyles
);progn
(command "-dimstyle" "r" "DIMFULL")
);if
(princ)
)
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: Anonymous

You should do it like

(if (setq D1 (tblsearch "dimstyle" "VAAFULL"))
..... style exists .....
.... style does not exist ....
)

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5692008@discussion.autodesk.com...
I have so far put together this. The first part works where it does the
tablesearch and if it returns a nil value for the wanted dimstyle it then
creates it. I'm having trouble with the else part. Where if the style
already exists, it simply switches to it. AutoCAD has either returned with
an error or tries to recreate the layer and that is not wanted.


(defun QQ ()
(setq D1 (tblsearch "dimstyle" "VAAFULL"))
(if
(/= D1 "VAAFULL") ;must be false
(progn ;then
lots of stuff here for setting up the dimstyles
);progn
(command "-dimstyle" "r" "DIMFULL")
);if
(princ)
)
Message 3 of 15
Anonymous
in reply to: Anonymous

I've changed the coding around a bit and I still recieve and error when I try to switch to it if it already exists.

New coding:

(setq D1 (tblsearch "dimstyle" "DIMFULL"))
(if
(= D1 "DIMFULL")
(command "-dimstyle" "r" "DIMFULL");then
(progn;else
junk
);else
);if

If i had it set as

(if (setq D1 (tblsearch "dimstyle" "DIMFULL"))

it would create an error before even creating the dimension. Message was edited by: silomethis
Message 4 of 15
Anonymous
in reply to: Anonymous

Did you not see how I told you you should do it?

It will not work the way you are doing it because you are not understand
what is being returned by 'tblsearch'. tblsearch returns a short list of
lists (dxf code lists), so your check will never be true.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5692046@discussion.autodesk.com...
I've changed the coding around a bit and I still recieve and error when I
try to switch to it if it already exists.

New coding:

(setq D1 (tblsearch "dimstyle" "DIMFULL"))
(if
(= D1 "DIMFULL")
(command "-dimstyle" "r" "DIMFULL");then
(progn;else
junk
);else
);if
Message 5 of 15
Anonymous
in reply to: Anonymous

In line with Tim's sugestion you can test thins at the command line if you're not sure what you're going to get.

Example:

Command: (tblsearch "dimstyle" "RJCL-M")
((0 . "DIMSTYLE") (2 . "RJCL-M") (70 . 0) (3 . "") (4 . "") (5 . "OPEN30") (6 .
"") (7 . "") (40 . 1.0) (41 . 2.0) (42 . 2.25) (43 . 0.0) (44 . 1.5) (45 . 0.0)
(46 . 1.5) (47 . 0.0) (48 . 0.0) (140 . 2.0) (141 . 3.0) (142 . 0.0) (143 .
25.4) (144 . 1.0) (145 . 0.0) (146 . 1.0) (147 . 1.0) (71 . 0) (72 . 0) (73 .
0) (74 . 0) (75 . 0) (76 . 0) (77 . 1) (78 . 3) (170 . 0) (171 . 2) (172 . 1)
(173 . 0) (174 . 1) (175 . 0) (176 . 0) (177 . 0) (178 . 0) (270 . 2) (271 . 0)
(272 . 4) (273 . 2) (274 . 2) (340 . ) (275 . 0) (280 .
0) (281 . 0) (282 . 0) (283 . 1) (284 . 0) (285 . 0) (286 . 0) (287 . 4) (288 .
0))
Message 6 of 15
Anonymous
in reply to: Anonymous

It appears i'm at a loss as to how to get a positive out of this. Anyway, I dumped together a little code to try and test out how to get it to notice that the style did exist. I'm going to go read through that section again.

(defun c:haha ()
(if (setq dim1 (assoc 2 (tblsearch "dimstyle" "DIMFULL")))
(= dim1 DIMFULL)
(print "you win")
(print "you lose")
)
(princ)
)

I lost.
Message 7 of 15
Anonymous
in reply to: Anonymous

like this...

[code]
(defun c:haha ()
(if (tblsearch "dimstyle" "DIMFULL")
(princ "the dimstyle exists")
(princ "the dimstyle was not found")
)
(princ)
)
[/code]

Regards
Phil
Message 8 of 15
Anonymous
in reply to: Anonymous

or

[code]
(defun c:haha ( / DIM1)
(if (setq DIM1 (tblsearch "dimstyle" "DIMFULL"))
(princ "the dimstyle exists")
(princ "the dimstyle was not found")
)
(princ)
)
[/code]
Message 9 of 15
Anonymous
in reply to: Anonymous

And now I see what Tim was trying to tell me. Thanks for the help from everyone. I'm going to go burn that book now.
Message 10 of 15
Anonymous
in reply to: Anonymous

or

[code]
(defun c:haha ( / DIM1)
(if (setq DIM1 (tblsearch "dimstyle" "DIMFULL"))
(progn
(princ (strcat "the dimstyle " (cdr (assoc 2 DIM1)) " exists"))
; and more stuff
)
(progn
;whatever you want
(princ "the dimstyle was not found")
)
)
(princ)
)
[/code]
Message 11 of 15
Anonymous
in reply to: Anonymous

Thanks for the super examples Phil.

Glad you got what you wanted silomethis.

The 'if' will return 'true' for any arguement that isn't nil. So since
'tblsearch' returns something if the name exists, it will be true, and false
if it doesn't exist because it will return nil (which means nothing in
lisp). Hope that clears up somethings.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5692286@discussion.autodesk.com...
And now I see what Tim was trying to tell me. Thanks for the help from
everyone. I'm going to go burn that book now.
Message 12 of 15
Anonymous
in reply to: Anonymous

That makes it much clearer than everything I have read about if/then/else statements and how tblsearch/entget works with them.

Thanks again for your help. Message was edited by: silomethis
Message 13 of 15
Anonymous
in reply to: Anonymous

You're welcome. Didn't mean to stomp on your post.

Cheers
Phil
Message 14 of 15
Anonymous
in reply to: Anonymous

Not at all. If someone is around, and can answer the questions that be
asked, I have no problem sharing. As long as the OP gets something they can
use, or information on what needs to happen (in a helpful way) then it's all
good with me.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5692392@discussion.autodesk.com...
You're welcome. Didn't mean to stomp on your post.

Cheers
Phil
Message 15 of 15
Anonymous
in reply to: Anonymous

Glad to hear it helped. You're welcome.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5692347@discussion.autodesk.com...
That makes it much clearer than everything I have read about if/then/else
statements and how tblsearch/entget works with them.

Thanks again for your help.

Message was edited by: silomethis

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost