Jump to content
dnovember99

adding text to existing text

Recommended Posts

dnovember99

ok so i found this lisp routine to be able to add text at the prefix or suffix of an existing text. it is also adding in a space between the new text and the old text.

 

(example of old text 3"GW - new text from this lisp (E) 3"GW)

 

is there a way to be able to remove that space that it is adding there?

 

(defun c:PST (/ PreSuf Str ent Cstr)
 (vl-load-com)
 (initget "PS")
 (setq PreSuf (getkword "\nChoose [Prefix/Suffix]  <Prefix>: "))
 (if (not PreSuf)
   (setq PreSuf "S")
 )
 (while (not str)
   (setq str (getstring T "\nEnter String: "))
   (cond ((and (eq str "")
 (princ "Null Input Try again")
 (setq str nil)
   )
  )
   )
 )
 (while (and (setq ent (car (nentsel "\nSelect Text/Attribute: ")))
      (member (cdr (assoc 0 (entget ent)))
       '("TEXT" "MTEXT" "ATTRIB")
      )
 )
   (setq ent  (vlax-ename->vla-object ent)
  Cstr (vla-get-textstring ent)
   )
   (vla-put-textstring
     ent
     (if (eq PreSuf "S")
(strcat Cstr " " str)
(strcat str " " Cstr)
     )
   )
 )(princ)
)

Share this post


Link to post
Share on other sites
ronjonp
(if (eq presuf "S")
 (strcat cstr [b][color="red"]" "[/color][/b] str)
 (strcat str [b][color="red"]" "[/color][/b] cstr)
)

Share this post


Link to post
Share on other sites
dnovember99

amazing! thank you for pointing this out!! this site is amazing

Share this post


Link to post
Share on other sites
Lee Mac

You may also find this post helpful.

Share this post


Link to post
Share on other sites
dnovember99
You may also find this post helpful.

 

Mr. Mac! thank you for this. i have to admit that your website is always the first place that i look for something that might be useful.

 

that is one of the first few that i read and in the beginning i was... well to be honest lost and overwhelmed. but going back thru this a few times this is for sure helping.

 

on a different note: do you happen to have or know if there is something to load into Autocad that will have a time start when ever you open a drawing? if you have something on your site just say that and i will look for it. (i have found a lot of cool tools there) but all in all THANK YOU!

Share this post


Link to post
Share on other sites
Lee Mac
Mr. Mac! thank you for this. i have to admit that your website is always the first place that i look for something that might be useful.

 

that is one of the first few that i read and in the beginning i was... well to be honest lost and overwhelmed. but going back thru this a few times this is for sure helping.

 

You're most welcome - I hope it'll be of some help.

 

on a different note: do you happen to have or know if there is something to load into Autocad that will have a time start when ever you open a drawing? if you have something on your site just say that and i will look for it. (i have found a lot of cool tools there) but all in all THANK YOU!

 

I'm not sure what you mean by:

 

...something to load into Autocad that will have a time start when ever you open a drawing?
Do you mean something equivalent to a Scheduled Task for programs in AutoCAD?

Share this post


Link to post
Share on other sites
dnovember99
You're most welcome - I hope it'll be of some help.

 

 

 

I'm not sure what you mean by:

 

Do you mean something equivalent to a Scheduled Task for programs in AutoCAD?

 

i am not sure what that really is to be honest. but i was thinking of something like a time counter. and the reason for this would be that my company harps on us so much over the time that is spent on each project.

 

to have when you open up an autocad file if there is a job number in the name of the file it would log it to a file just for that job number or for any cad file from the source folder so you can log your time a little more closely.being that each of out projects has a different job number, have it log time autocad was spent open with a drawing name, I.E. job number that is on the file.

 

this could be totally far fetched but i was thinking about this the other day. i have a logitec G13 keyboard. i attached a screen shot of the stopwatch that is on that. i can use it but it is hard to remember to hit stop and go each time. windows 10 also has one on there, just think it would be really cool to have one for autocad. that could log your time spent on a job.

20180208_122930.jpg

stopwatch from windows.png

Share this post


Link to post
Share on other sites
Grrr

As a generic pref/suff function I always liked this approach:

(defun pstxt ( p txt s )
 (strcat (cond (p)("")) txt (cond (s)("")))
)

Share this post


Link to post
Share on other sites
Lee Mac
As a generic pref/suff function I always liked this approach:

(defun pstxt ( p txt s )
 (strcat (cond (p)("")) txt (cond (s)("")))
)

 

IMO, calling pstxt with an empty string is more useful than supplying nil - consider that getstring returns an empty string on null input.

 

But a separate function definition for a single string concatenation seems unnecessary: (pstxt p txt s) is no different to (strcat p txt s)

 

@dnovember99, your posts regarding a drawing time-logging system are off-topic for this thread and ideally belong in a new thread - a Moderator can move them for you.

Share this post


Link to post
Share on other sites
BIGAL

dnovember99 did you look at what I posted it does lots more than just log time. I use a cut down version every day. It records every project individually from day 1.

 

cut down report
START TIME of report entry .... 2018.Jan.05  09:54:53
END TIME of report entry ...... 2018.Jan.05  10:05:45
Total period ............................... 00:10:52
FILENAME:           2012161-PF.dwg
DIRECTORY:          [url="file://\\XXXX.l\2012"]\\XXXX.l\2012[/url] Projects\2012161\Design\
LAST SAVE:          2018.Jan.05  10:05:40
TOTAL EDITING TIME: 397:56:44
LOGGED USER:        BIGAL
START TIME of report entry .... 2018.Jan.06  10:17:53
END TIME of report entry ...... 2018.Jan.06  10:30:34
Total period ............................... 00:12:41
FILENAME:           2012161-PF.dwg
DIRECTORY:          [url="file://\\XXXX.l\2012"]\\XXXX.l\2012[/url] Projects\2012161\Design\
LAST SAVE:          2018.Jan.05  10:30:29
TOTAL EDITING TIME: 398:09:42
LOGGED USER:        BIGAL
START TIME of report entry .... 2018.Jan.07  10:31:01
END TIME of report entry ...... 2018.Jan.07  10:56:51
Total period ............................... 00:25:50

Share this post


Link to post
Share on other sites
Grrr
IMO, calling pstxt with an empty string is more useful than supplying nil - consider that getstring returns an empty string on null input.

 

Well that pstxt its used, depending on the case(application) - but I agree that it doesn't suit well with getstring, hence OP's problem.

I was using it somewhere to look for a certain attrib values, then consider if they are valid to construct a main string.

Or say something like (I know this example could be written better) :

(defun picktext ( msg / e r )
 (and 
   (setq e (car (entsel msg))) ; user is allowed to miss-pick
   (setq r (cdr (assoc 1 (entget e))))
 )
 r
)

(pstxt 
 (picktext "\nPrefix: ")
 (picktext "\nMain Text: ")
 (picktext "\nSuffix: ")
)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×