Insert block at given offset from point

Matjaz Udovc

Usenet Archive
Joined
Feb 6, 2004
Messages
9
Reaction score
0
This will probably take less then a second to solve for someone who knows Lisp a bit...

How do I complete this simple routine that will prompt for a basepoint (X,Y,Z), prompt for offset distance (d) and then insert a block at a point X-d,Y,Z.

Here's how I've started it but I'm stuck at putting the insertion point into it:
(defun c:rout1

(setq bp (getpoint "Basepoint : ")
(setq of (getreal "Offset : "))
(command "-insert" "myblock" (- bp (of 0 0)) "1" "1" "0")

)
 
Err.. (polar bp (* pi 1.0) of) offsets the point along the X axis in negative direction. Is this waht you need?
 
Try this one:

(defun c:rout1
(setq bp (getpoint "Basepoint : ")
(setq of (getreal "Offset : "))
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
(command "-insert" "myblock" new_pt "1""1""0")
;;;(command "-insert" "myblock" (- bp (of 0 0)) "1" "1" "0")
)

Bob
 
ECCAD said:
(defun c:rout1
(setq bp (getpoint "Basepoint : ")
(setq of (getreal "Offset : "))
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
(command "-insert" "myblock" new_pt "1""1""0")
;;;(command "-insert" "myblock" (- bp (of 0 0)) "1" "1" "0")
)

Bob

Thanks for your help guys, but I still have problems.

I tried both Bob's and Rune's suggestion and they both show some strange behaviour: if you draw a horizontal line and a vertical line that crosses the first one, and then run the routine
1. if I pick the endpoint of each line the routine works just as planned
2. if I pick the intersection of those two lines the routine inserts "myblock" at the endpoint of the horizontal line (the one closer to the intersection)

both variants work this way
(setq new_pt (polar bp (* pi 1.0) of))
or
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))

how can this be mended?

TIA
 
Do you have running osnaps?

Matjaz Udovc said:
Thanks for your help guys, but I still have problems.

I tried both Bob's and Rune's suggestion and they both show some strange behaviour: if you draw a horizontal line and a vertical line that crosses the first one, and then run the routine
1. if I pick the endpoint of each line the routine works just as planned
2. if I pick the intersection of those two lines the routine inserts "myblock" at the endpoint of the horizontal line (the one closer to the intersection)

both variants work this way
(setq new_pt (polar bp (* pi 1.0) of))
or
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))

how can this be mended?

TIA
 
Rudy said:
Do you have running osnaps?

Not certain that I know what you mean. Osnap is on and that's how I want it for the basic idea is that I want to insert "myblock" at an offset from intersection of two lines thus I need Osnap on.
 
Matjaz,
I would be helpful to more clearly define 'exactly' what you wanted to do, we need to toggle off the running Osnap, so it does not 'override' the new_pt location.
Do:
(defun c:rout1
(setq bp (getpoint "Basepoint : ")
(setq OLD_SNAPMODE (getvar "OSMODE")); save settings
(setq of (getreal "Offset : "))
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
(command "-insert" "myblock" new_pt "1""1""0")
(setvar "OSMODE" OLD_SNAPMODE); restore
(princ)
)

Bob
 
Aha, now I get it. When new_pt fell exactly on a horizontal line ACAD picked endpoit of that line instead using osnap.

This routine is now working exactly like I wanted it to so I thank you all for two things:
1. getting this routine together that will save me some time and even more important 2. understanding a tiny bit more about how Lisp works

Thanks

Matjaz
 
(defun c:rout1
(setq bp (getpoint "Basepoint : "))
(setq OLD_SNAPMODE (getvar "OSMODE")); save settings
(setvar "OSMODE" 0); OSNAP off
(setq of (getreal "Offset : "))
(setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
(command "-insert" "myblock" new_pt "1""1""0")
(setvar "OSMODE" OLD_SNAPMODE); restore
(princ)
)

this is the routine that works like I planned (Had to add lne 4 to turn OSNAP off after saving the settings)

Matjaz
 
It's probably cleaner to avoid setting/resetting "Osmode" altogether since the user could *cancel* the function at the "Offset: " prompt. This can be done by overriding the current snap mode just before the point input in the command sequence. Also, things might be happier if the program didn't proceed on a null response... (defun c:rout1 ( / bp of new_pt) (and (setq bp (getpoint "Basepoint : ")) (setq of (getreal "Offset : ")) (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0))) (command "-insert" "myblock" "_NON" new_pt "1""1""0") ;; ---------- override here ----------^ ) (princ)
)
 
You'll need to turn OSNAP off somewhere int he routine to avoid the routine selecting the end of the existing lines. Another optionis have the routine place the block, then move it the specified distance.

I, personally, would just redefine the block so that it's insertion point remained at the selected point, but the graphics were offest.
 

Latest threads

Back
Top