Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
sean.keohane
Posts: 170
Registered: ‎02-10-2004
Message 1 of 3 (175 Views)
Accepted Solution

Editing distorted text...

175 Views, 2 Replies
09-18-2012 08:13 AM

Hi,

I have attached a lsp in progress. It is designed to

a. make a block of a selection. that part works.

b. insert the new block with a "Y" scale distortion and explode. that part works

c. make a selection of text with 5x width factor. that part kinda works??

d. make a selection of text with 0.2x width factor. that part kinda works??

e. apply new text height and width factor to the 2 selections. that part is kinda working on the first selection and not working on the second.

Can someone take a look at it and show where this code is wrong.

I'm struggling to teach myself lisp and would be no where without the help I get in this forum.

So thanks in advance.

Regards

Sean

Distinguished Mentor
Moshe-A
Posts: 745
Registered: ‎09-14-2003
Message 2 of 3 (166 Views)

Re: Editing distorted text...

09-18-2012 09:54 AM in reply to: sean.keohane

Sean,

 

take a look at the fix code i made for you (did not test it though)

 

(defun c:datablk (/ ss)
 (if (setq ss (ssget))
  (progn
   (command "block" "data" "0,620" ss "")
   (command "insert" "data" "0,620" "1" "5" "0")
   (command "explode" "last")

   (modify_text 12.5 1.0)
   (modify_text nil  1.0)
    
  ); progn
 ); if
  
); defun


(defun modify_text (txth txtw / txtSS i edata)
 (if (setq txtSS (ssget "X" '((0 . "TEXT") (41 . 5))))
  (progn
   (setq i -1)
   (repeat (sslength txtSS)
    (setq i (1+ i))
    (setq edata (entget (ssname txtSS i)))
     
    (if txth
      (setq edata (subst (cons 40 txth) (assoc 40 edata) edata))
    )
     
    (if txtw
      (setq edata (subst (cons 41 txtw) (assoc 41 edata) edata))
    )
     
    (entmod edata)
   ); repeat
  ); progn
 ); if
)

 

basicly what you are doing after creating and inserting the block is selecting two groups of text

and modify them (height and width) i took that group text handling and put it in sub-routine with two

arguments (txth txtw) and then call it from the main command.

 

pay attention to defining a meaningful variables (it is very importent for later debuging the code)

and declaring them a local variables

 

(setq data (ssget "_W" '(-100 450) '(13600 630)))

 

when calling (ssget) with "w" argument you are actually do not give the user the option to select what he wants

it better to call it this way (setq data (ssget))

 

also if the user fail to select any object? your program will continue and right after crash with an error

it is better to start it with an if function to make sure that (ssget) contains objects.

 

generally invoking a standard autocad command from the (command) function (or script file) does not require you

to prefix the command with dash sign...it's design to run from command line automaticlly.

 

see how did i call (modify_text) the first time with your new height & width values but the second time

i put a nil for the height argument (cause in your 2nd group text handling) you only modified the width field.

 

(modify_text 12.5 1.0)
(modify_text nil    1.0)

 

and in the sub-routine i checked to see if txth has a value? and only if it is? i'm taking the change.

 

(if txth
  (setq edata (subst (cons 40 txth) (assoc 40 edata) edata))
)
     
(if txtw
 (setq edata (subst (cons 41 txtw) (assoc 41 edata) edata))
)

 

that it buddy, hope this will help you

Moshe

 

 

 

 

Distinguished Contributor
sean.keohane
Posts: 170
Registered: ‎02-10-2004
Message 3 of 3 (145 Views)

Re: Editing distorted text...

09-18-2012 11:48 PM in reply to: Moshe-A

Hi Moshe,

Thanks for helping me out. That looks a whole lot neater than my attempt and the plus is -  it works.

The step by step  is a big help in understanding my mistakes thanks for that also.

Regards

Sean

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.