Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pipe with bends

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
718 Views, 3 Replies

pipe with bends

My goal is to draw a line with polar tracking on set to various bend angles.
as each angle is formed it will insert the appropriate bend. for some
reason this way sporadiacally inserts the bends and often a ways down the
run it quits putting in bends altogether. I suspect there is a better way
but can anyone point out a fixable problem with this code? the RANG will be
the rotation angle calculation which i will attemp when all else works ok.

Thanks alex



(defun c:pwb ()
(SETQ BPS (GETVAR "BPARAMETERSIZE"))

(SETVAR "POLARANG" (/ PI 2))
(SETVAR "POLARADDANG"
"11d15'0\";22d30'0\";45d0'0\";315d0'0\";337d30'0\";348d45'0\"")
(SETVAR "POLARMODE" 5)

(command "line" pause)(setq pt1 (getvar "lastpoint"))
(command pause)(setq pt2 (getvar "lastpoint"))

(while (= nil nothing)
(command pause)
(setq pt3 (getvar "lastpoint"))
(setq myang (r2d (dotp pt1 pt2 pt2 pt3)) RANG 0.0)
(PRINT myang)
(if (eq myang 90.0) (progn (command "" "insert" "90 BEND" PT2 BPS BPS RANG
"line" pt3 )))
(if (eq myang 45.0) (progn (command "" "insert" "45 BEND" PT2 BPS BPS RANG
"line" pt3 )))
(if (eq myang 22.5) (progn (command "" "insert" "22-5 BEND" PT2 BPS BPS RANG
"line" pt3 )))
(if (eq myang 11.25) (progn (command "" "insert" "11-25 BEND" PT2 BPS BPS
RANG "line" pt3 )))


(setq pt1 pt2 pt2 pt3)
)

(princ))


;dotp.lsp pass 4 points containing the x y z vals of the 2 vectors.
(defun dotp (tpt1 tpt2 tpt3 tpt4)
(IF (= 2 (LENGTH TPT1)) (PROGN (SETQ TPT1 (LIST (CAR TPT1) (CADR TPT1)
0 ) ) ))
(IF (= 2 (LENGTH TPT2)) (PROGN (SETQ TPT2 (LIST (CAR TPT2) (CADR TPT2)
0 ) ) ))
(IF (= 2 (LENGTH TPT3)) (PROGN (SETQ TPT3 (LIST (CAR TPT3) (CADR TPT3)
0 ) ) ))
(IF (= 2 (LENGTH TPT4)) (PROGN (SETQ TPT4 (LIST (CAR TPT4) (CADR TPT4)
0 ) ) ))

(setq vx1 (- (car tpt2) (car tpt1)) vx2 (- (car tpt4) (car tpt3)) )
(setq vy1 (- (cadr tpt2) (cadr tpt1)) vy2 (- (cadr tpt4) (cadr tpt3)) )
(setq vz1 (- (caddr tpt2) (caddr tpt1)) vz2 (- (caddr tpt4) (caddr tpt3)) )
(setq uv (+ (* vx1 vx2) (* vy1 vy2) (* vz1 vz2)) u (sqrt (+ (sq vy1) (sq
vx1) (sq vz1))) v (sqrt (+ (sq vy2) (sq vx2) (sq vz2))))
(ACOS (/ uv u v))
)



;sq = square function
(defun sq (tpt) (* tpt tpt))

(defun acos (val /) (atan (sqrt (- 1.0 (* val val))) val) )
3 REPLIES 3
Message 2 of 4
devitg
in reply to: Anonymous

Hi.
Ccould you upload a dwg with all the BLOCKS , and better an before and after DWG .???
It will help to help you.
Message 3 of 4
mlouis
in reply to: devitg

Using ACAD 2010 I created this Block. Very useful if you ask me!

Message 4 of 4
Kent1Cooper
in reply to: Anonymous


*Alex wrote:
My goal is to draw a line with polar tracking on set to various bend angles.
as each angle is formed it will insert the appropriate bend. for some
reason this way sporadiacally inserts the bends and often a ways down the
run it quits putting in bends altogether....

 

....

(command "line" pause)(setq pt1 (getvar "lastpoint"))
(command pause)(setq pt2 (getvar "lastpoint"))

(while (= nil nothing)
....

(setq myang (r2d (dotp pt1 pt2 pt2 pt3)) RANG 0.0)
....

(if (eq myang 90.0) (progn (command "" "insert" "90 BEND" PT2 BPS BPS RANG "line" pt3 )))
....
;dotp.lsp pass 4 points containing the x y z vals of the 2 vectors.
(defun dotp (tpt1 tpt2 tpt3 tpt4)
(IF (= 2 (LENGTH TPT1)) (PROGN (SETQ TPT1 (LIST (CAR TPT1) (CADR TPT1)
0 ) ) ))
....


I'm guessing that maybe you need a fuzz factor in your check on the value of 'myang', something like:

 

(if (equal myang 90.0 1e-6)....

 

A couple of other things I noticed:

 

You have a lot of (progn) functions that you don't need.  They're only needed where a 'then' or 'else' argument to an (if) function requires running more than one function, but yours all seem to call for only single (command) or (setq) functions, so they don't need the (progn) wrappers.

 

A simpler way to get something to run repeatedly until the User hits Escape is:

 

(while T

  ....

 

I don't think you need that (if (= 2 (length tpt1))... part about adding a Z component to two-component point lists.  That may be appropriate in other applications, but it looks like in this one all your arguments are coming from (getvar "lastpoint") functions, which return 3-component point lists.

 

And I expect the determination of the bend angles could be a lot simpler with an approach something like:

 

(setq bend

  (rem

    (- (angle pt2 pt3) (angle pt1 pt2))

    (/ pi 2)
  )

)

 

That should give you a radian value from which you can get the bend angle [0 for 90 degrees], for determination of which Block to insert.  And depending on the way your Blocks are constructed, one of those (angle) functions should give you the rotation angle directly [in radians].  Even adding some compensation for the possibility of crossing the zero-degree direction and something to determine whether the bend was to the left or right, I expect it could still be simpler than the (dotp)/(sq)/(acos) family of functions.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost