Jump to content

Recommended Posts

Posted (edited)

I'm trying to grab a hundred pieces of MText (polyline contour labels) that are simply a number, and add 2 to them, or increment them by a given number.

I'm allowing the user to select them any way they choose first, then use "P" previous in my ssget function.


This is very rudimentary, quick and dirty programming. Please excuse my aged style, I learned lisp back in R10.

 

I seem to be stuck on the SUBST, ENTMOD and ENTUPD section.

What am I missing?

(defun C:IncConTxt ()
(setq SS1 (ssget  "_P"))
(setq HTFAC (atoi (getstring "\nHeight Factor: ")))
 (setq NUM (sslength SS1))
 (setq CNT 0)



 (while (< CNT NUM)
   (setq ENT (ssname SS1 CNT))
   (setq OLDHT (cdr (assoc 1 (entget ENT))))
   (setq NEWHT (+ (atoi OLDHT) HTFAC))
   (setq NEWHT (itoa NEWHT))

   (setq OLDHT (itoa OLDHT))



     (setq STUFF (entget ENT))
     (setq STUFF (subst (cons 1 NEWHT) (assoc 1 STUFF) STUFF))
     (entmod STUFF)
     (entupd ENT)
   (setq CNT (+ 1 CNT))
 );close while


);close defun

IncConTxt.lsp

Edited by fuccaro
adding CODE tags
Posted

@Arizona

Take out this line and it should work: (setq oldht (itoa oldht))

 

Also .. don't forget to localize your variables:

(/ cnt ent htfac newht num oldht ss1 stuff)

 

Posted

@ronjonp

That worked!! Thank you!

As far as local variables, yes. I'm going to clean the thing up, put some notes as to what it does and how it works, and credit myself to get the Glory!

 

Thanks so much Ron.

Posted
1 hour ago, Arizona said:

@ronjonp

That worked!! Thank you!

As far as local variables, yes. I'm going to clean the thing up, put some notes as to what it does and how it works, and credit myself to get the Glory!

 

Thanks so much Ron.

:beer:

Posted

 

 

You might look into using VL lisp as it uses words like (vlax-put obj 'Textstring newht) bit easier than remembering dxf codes and is also very fast.

 

I plus many others do a selection set loops like this.

 

(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1-x))))
....
)
(defun C:IncConTxt ( / ss1 x ent oldht newht)
(setq SS1 (ssget  "_P"))
(setq HTFAC  (getint "\nHeight Factor: "))
 (repeat (setq x (sslength ss1)
   (setq ent (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
   (setq OLDHT (atoi (vlax-get ent 'Textstring)))
   (setq NEWHT (+ OLDHT HTFAC))
)
);close defun

 

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