Jump to content

Help with Flange lisp


tmelancon

Recommended Posts

Hey guys I have a lisp routine to draw "flanges" for isometric piping. Basically drawings two lines that are a specific length and distance apart. The lisp prompts user for initial point(P1) then direction of flanges(P2).

 

The problem I am having is for some reason I cant figure out why the flanges are centered around Point 1 instead of the first flange (line) being at P1 and the second flange (line) being at the specified distance in the direction of P2. check it out, run a test and report back if you can. I would love to learn the way to tweak this for future encounters with the same issue. See photos also.

 

Thank you in advance. Please let me know if I can assist in any way.

 

 

 

(defun c:FLANGES_DCP (/ *ERROR* test oldsnap oldorth oldlayr oldos p1 p2 xp1 xp2 yp1 yp2 PZ)
(setvar "cmdecho" 0) (command "undo" "m")
(defun *error* (msg)
    (if oldlayr (setvar "clayer" oldlayr))
    (if oldos (setvar "osmode" oldos))
    (if oldorth (setvar "orthomode" oldorth))
    (if oldsnap (setvar "snapstyl" oldsnap))
    (if msg (prompt msg))
    (princ)
  )

(defun drawflng (/ OLDPWID e1 e2)
(setq oldpwid (getvar "plinewid")) (command "._plinewid" "0")
(command "._pline" p3 p6 "") (setq e1 (entlast)) (setq flnggrp (ssget "l"))
(command "._pline" p4 p5 "") (setq e2 (entlast)) (ssadd e2 flnggrp)
(command "._plinewid" oldpwid)
(prin1))

(defun one () (drawflng) (prin1))

(defun two () (drawflng)
(command "._rotate" flnggrp "" p1 "180.0") (prin1))

(defun three (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y")
(command "._rotate" flnggrp "" p1 "180.0") (prin1))

(defun four (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y") (prin1))

(defun five (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y")
(command "._rotate" flnggrp "" p1 "60.0") (prin1))

(defun six () (drawflng)
(command "._rotate" flnggrp "" p1 "300.0") (prin1))

(defun seven () (drawflng)
(command "._rotate" flnggrp "" p1 "120.0") (prin1))

(defun eight (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y")
(command "._rotate" flnggrp "" p1 "240.0") (prin1))

(defun nine (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y")
(command "._rotate" flnggrp "" p1 "120.0") (prin1))

(defun ten (/ px) (drawflng)
(setq px (make_pt p1 (dtr 90.0) 0.1))
(command "._mirror" flnggrp "" p1 px "y")
(command "._rotate" flnggrp "" p1 "300.0") (prin1))

(defun eleven () (drawflng)
(command "._rotate" flnggrp "" p1 "240.0") (prin1))

(defun twelve () (drawflng)
(command "._rotate" flnggrp "" p1 "60.0") (prin1))

(defun right ()
(if (and (< xp1 xp2) (< yp1 yp2)) (three))
(if (and (> xp1 xp2) (> yp1 yp2)) (four))
(if (and (= xp1 xp2) (> yp1 yp2)) (six))
(if (and (= xp1 xp2) (< yp1 yp2)) (seven))
(prin1))

(defun top ()
(if (and (< xp1 xp2) (> yp1 yp2)) (nine))
(if (and (> xp1 xp2) (< yp1 yp2)) (ten))
(if (and (> xp1 xp2) (> yp1 yp2)) (eleven))
(if (and (< xp1 xp2) (< yp1 yp2)) (twelve))
(prin1))

(defun left ()
(if (and (< xp1 xp2) (> yp1 yp2)) (one))
(if (and (> xp1 xp2) (< yp1 yp2)) (two))
(if (and (= xp1 xp2) (> yp1 yp2)) (five))
(if (and (= xp1 xp2) (< yp1 yp2)) (eight))
(prin1))

(defun setpnts (/ p3 p4 p5 p6)
(setq p3 (make_pt p1 (dtr 70.89339442) 0.0533))
(setq p4 (make_pt p3 (dtr 150.0) 0.0420))
(setq p5 (make_pt p4 (dtr 270.0) 0.12))
(setq p6 (make_pt p3 (dtr 270.0) 0.12))
(if (= test 0) (left)) (if (= test 1) (top)) (if (= test 2) (right))
(prin1))


(setq oldsnap (getvar "snapstyl")) 
(setvar "snapstyl" 1)
(setq oldorth (getvar "orthomode")) 
(setvar "orthomode" 1)
(setq oldos (getvar "osmode"))
(setq oldlayr (getvar "clayer"))
(setq p1 (getpoint "\nStart point: "))
(setvar "osmode" 0)
(initget 32) (setq p2 (getpoint p1 "\nDirection of line: "))
(setq test (getvar "snapisopair")) 
;(setq headtype 3)
(setq xp1 (car p1)) (setq xp2 (car p2))
(setq yp1 (cadr p1)) (setq yp2 (cadr p2))
(setpnts)
(setvar "snapstyl" oldsnap) 
(setvar "orthomode" oldorth) 
(command "._layer" "s" oldlayr "")
(*error* nil)
(prin1))

 

 

flanges1.png

 

 

Flanges2.png

 

 

Flanges3.JPG

 

Edited by tmelancon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...