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

Substr

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
andreas7ZYXQ
809 Views, 4 Replies

Substr

I have a issue id like to solve.

In my substr i want to replace 16 with with pos..
i dont know how to get around it and make it work..

thanks.

 

 

(defun c:001 ()
 (setq plan "1");
 (setq pos "2")
 (setq name (getvar "dwgname"))
 (setq pos2 (substr name 16 1))
;(setq pos2 (substr name pos 1)) <---- someone that could give me some help and explain why it wint work? (if (= plan pos2) (princ "This is true") (princ "This is false") );end of if statement );defun

 

4 REPLIES 4
Message 2 of 5
ВeekeeCZ
in reply to: andreas7ZYXQ

your pos variable must be an INTEGER not a STRING 

 

(setq pos 2)

 

then for your father comparison must be plan an integer as well 

 

(defun c:001 ()
 (setq plan 1);
 (setq pos 2)
 (setq name (getvar "dwgname"))
 (setq pos2 (substr name 16 1))
 ;(setq pos2 (substr name pos 1)) <---- someone that could give me some help and explain why it wint work? 
 (if (= plan pos2)
   (princ "This is true")
   (princ "This is false")
  );end of if statement
 );defun

 

Read HERE about integers, real, strings... and conversions between them...

Message 3 of 5
john.uhden
in reply to: ВeekeeCZ

How can (= plan pos2) ever be true?

 

plan is an integer, but pos2 is a string.

John F. Uhden

Message 4 of 5
ВeekeeCZ
in reply to: john.uhden


@john.uhden wrote:

How can (= plan pos2) ever be true?

 

plan is an integer, but pos2 is a string.


Good point. Thx 

 

@andreas7ZYXQ Then keep your plan a string.

Message 5 of 5
andreas7ZYXQ
in reply to: ВeekeeCZ

I changed to this. Thanks alot for the advice @ВeekeeCZ

 

(defun c:001 ()
 (setq plan "1");
 (setq pos "2")
 (setq name (getvar "dwgname"))
(setq pos2 (substr name (atoi pos) 1))
 (if (= plan pos2)
   (princ "This is true")
   (princ "This is false")
  );end of if statement
 );defun

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report