Getting the measurements for stretching

Getting the measurements for stretching

Anonymous
Not applicable
856 Views
5 Replies
Message 1 of 6

Getting the measurements for stretching

Anonymous
Not applicable

Hello, 

I am creating an algorithm to help me expand boxes to the correct size, as such:
originaloriginalexpected resultexpected result

I made a code that asks two points that should be the new depth and measures them. Then subtracts to the original depth of the block (0.51) and then asks the side to stretch. 

(defun mystretchh ( dis / pt1 pt2 sel )
    (while
        (and
            (setq pt1 (getpoint "\nFirst point of selection window: "))
            (setq pt2 (getcorner pt1 "\nSecond point of selection window: "))
            (not (setq sel (ssget "_C" pt1 pt2)))
        )
        (princ "\nNo objects where found in the selection window.")
    )
    (if sel
        (progn
            (command "_.stretch" sel "" "_non" '(0 0) "_non" (list dis 0))
            t
        )
    )
)
(defun c:test (/ a x c p)
;ungroup
(command "pickstyle" 0)
;variables
(initget (+ 1 2 4))
(setq p (getpoint "\nSelect first point: "))
(setq c (getpoint "\nSelect second point: "))
(command "_.dist" p c)
(setq x (rtos (getvar 'distance) 2 3))


	;calculate distance to stretch
	(setq a (- x 0.51))


	;stretch
	(mystretchh a)
		
	;regroup
	(command "pickstyle" 1)
	(print "Module modified.")
	(princ)
	)

I am having two problems. One, the stretch is working backwards, i tried using negative values to no avail. Second it accuses a syntax error but I cannot find it. 

 

I haven't touched Autolisp for half a year, maybe some of you can find the problems in a eye blink.
PS: i send the file in the annex

0 Likes
857 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

The STRETCH command can't be given just a selection set, i.e. a collection of entities -- it needs a Crossing-type selection [see the prompt], because it needs to know which things are fully inside and will be moved, and which things are partially inside and will have their inside aspects repositioned but the outside aspects left where they are.  Try replacing this:

 

(command "_.stretch" sel "" "_non" '(0 0) "_non" (list dis 0))

 

with this:

 

(command "_.stretch" "_C" pt1 pt2 "" "_non" '(0 0) "_non" (list dis 0))

 

Also, this is incorrect, because x is a text string, not a number:

(setq a (- x 0.51))

 

Kent Cooper, AIA
0 Likes
Message 3 of 6

CodeDing
Advisor
Advisor

@Anonymous ,

 

If the example image that you posted is similar to how your scenario will be every time, then I am going to Highly recommend that you try creating a dynamic block to get your solution.

 

Best,

~DD

0 Likes
Message 4 of 6

Anonymous
Not applicable

how would you make X into a number?

I tried strcat but it did not work.
I am a bit new to all this, any help is appreciated 🙂

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

how would you make X into a number?

....


It was made into a text string from a number -- you can use the same number:

 

(setq a (- (getvar 'distance) 0.51))

[EDIT:  ... which it would seem means you don't need the 'x' variable at all, unless there's more to all this and you need it later for something else.]

 

Kent Cooper, AIA
0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

keep x a number

 

(setq x (distance p c))
0 Likes