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.
Solved! Go to Solution.
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.
(setq edata (subst (cons 40 txth) (assoc 40 edata) edata))
(setq edata (subst (cons 41 txtw) (assoc 41 edata) edata))
that it buddy, hope this will help you
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register