Combining strings / rtos / strcat

Combining strings / rtos / strcat

thomas.schive
Enthusiast Enthusiast
3,207 Views
4 Replies
Message 1 of 5

Combining strings / rtos / strcat

thomas.schive
Enthusiast
Enthusiast

Hello!

 

I'm trying to write a routine that does something like this. First of all the user puts in two values - one "constant" and one that's supposed to increase by one per click. As an example would this be useful for naming objects, if you have 10 boxes that should be named 60E1-1, 60E1-2, 60E1-3 and so on ...

 

I want the name to appear where the user clicks on a new created layer. Most of it is working, but I'm struggeling with combining the user inputs with strcat as I want to call it an integer, but then I'm not able to combine, and it won't write anything with my rtos now (I think).

 

Maybe you pros can find the problems here?

 

;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

;;Message to user
(princ "Write TBP to begin ... ")

;;Cleaning up
(defun LM:gpp ( / )
    (vl-load-com)
    (setq
        cmdech (getvar "CMDECHO")
        oldlay (getvar 'clayer)
    );_ setq
    (setvar "CMDECHO" 0)
);_ defun


;;Getting input
(defun LM:brukerinput ( / )
    (setq
        konstant (vl-string-translate " " " " (getstring T "\nWrite constant value "))
    )
    (setq
        variabelsv (getstring "\nWrite start value ") ;;I actually want this to be a getint, as it's supposed to be a number ...
    )
);_defun

;;Combining input
(defun LM:kombinering ( / )
    (setq
        kombinert (strcat konstant variabelsv) ;;This one fails when they're not both strings apparently
    )
);_defun

;;Write text
(defun LM:skrivtekst ( / )
    (command "_.Layer" "_Make" "Tellelag" "_Color" "7" "" "LType" "Continuous" "" "")
    (eval
        (append
            '(command "._text" punkta)
                (if
                    (zerop
                        (cdr
                            (assoc 40
                                (entget
                                    (tblobjname "style"
                                        (getvar 'textstyle)
                                    )
                                )
                            )
                        )
                    )
                    '(0.5);;Text size
                )
            '(0
                (rtos kombinert 2 0);; And here lies (I think) my next problem, rtos maybe isn't what I'm supposed to use?
            )
        )
    )
);_defun

;;mp
(defun c:tbp ( / )
    (LM:gpp)
    (LM:brukerinput)
    (LM:kombinering)
        (while
            (setq
                punkta (getpoint "\nChoose point ")
                variabelsv (+ variabelsv 1)
            )setq
            (LM:skrivtekst)
        )
        (setvar "CMDECHO" cmdech)
        (setvar "CLAYER" oldlay)
    (princ)
);_defun

 

;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> End of routine

 

Regards

ts

0 Likes
Accepted solutions (1)
3,208 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

If you use (getint) for the 'variabelsv' variable, then use (itoa) to make it into a string that you can concatenate with 'konstant':

 

(strcat konstant (itoa variabelsv))

Kent Cooper, AIA
Message 3 of 5

thomas.schive
Enthusiast
Enthusiast

Thanks, that solves that part!


Getting a "Choose point bad argument type: numberp: "60E21""

(now I wrote 60E2 as konstant and 1 as variabelsv)

 

I'm suspecting my rtos?

 

/ts

0 Likes
Message 4 of 5

rkmcswain
Mentor
Mentor
Accepted solution

Try this:

 

;;Message to user
(princ "Write TBP to begin ... ")

;;Cleaning up
(defun LM:gpp ( / )
    (vl-load-com)
    (setq
        cmdech (getvar "CMDECHO")
        oldlay (getvar 'clayer)
    );_ setq
    (setvar "CMDECHO" 0)
);_ defun


;;Getting input
(defun LM:brukerinput ( / )
    (setq
        konstant (vl-string-translate " " " " (getstring T "\nWrite constant value "))
    )
    (setq
        variabelsv (getint "\nWrite start value ") ;;I actually want this to be a getint, as it's supposed to be a number ...
    )
);_defun

;;Combining input
(defun LM:kombinering ( / )
    (setq
        kombinert (strcat konstant (itoa variabelsv)) 
    )
);_defun

;;Write text
(defun LM:skrivtekst ( / )
    (command "_.Layer" "_Make" "Tellelag" "_Color" "7" "" "LType" "Continuous" "" "")
    (eval
        (append
            '(command "._text" punkta)
                (if
                    (zerop
                        (cdr
                            (assoc 40
                                (entget
                                    (tblobjname "style"
                                        (getvar 'textstyle)
                                    )
                                )
                            )
                        )
                    )
                    '(0.5);;Text size
                )
            '(0
                kombinert
            )
        )
    )
);_defun

;;mp
(defun c:tbp ( / )
    (LM:gpp)
    (LM:brukerinput)
    (LM:kombinering)
        (while
            (setq
                punkta (getpoint "\nChoose point ")
                variabelsv (+ variabelsv 1)		
            )setq
	    (LM:skrivtekst)
	    (LM:kombinering)
        )
        (setvar "CMDECHO" cmdech)
        (setvar "CLAYER" oldlay)
    (princ)
);_defun

I didn't evaluate the code as a whole, just edited it enough to get it to work.

 

 

R.K. McSwain     | CADpanacea | on twitter
Message 5 of 5

thomas.schive
Enthusiast
Enthusiast

This worked great, thanks!

 

/ts

0 Likes