Jump to content

adding text to existing text


dnovember99

Recommended Posts

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)
)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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: ")
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...