Jump to content

Recommended Posts

Posted

Hey all,

 

I need some help, I have written the lisp routine below and decided to update it with some new features except that the complexity is a bit further than I can comprehend right now.

 

My old version just prompted for insertion point and rotation of the valve and the scale is based off of the current dimscale. I decided, however, that I wanted the block to rotate it's self according to the line it was bieng inserted on, then break to that line and eventually join itself with the line. The code is below so please point me in the right direction.

 

;;``````````````````````````````````````````````````````````````````````````````;;
;;--------------------------THERMOSTATIC MIXING VALVE---------------------------;;  (10)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;
;start of command
(defun c:tmv ( / ss es ro a1 a2 os scale osm oldvar oldvar2 a po b)
 (if (= (getvar "dimanno") 1)
   (progn (command "-dimstyle" "r" "standard")
     (setq b (initget 128))
     (setq a (getreal "\nDefine your drawing scale: "))
     (command "dimscale" a)
     )
   )
 (if (= (getvar "dimscale") 0)
   (PROGN (setq B (getreal "\nDefine your drawing scale: "))
     (COMMAND "dimscale" B)
     )
   )
 (sssetfirst nil nil)
 (valve_print_settings10)
 (setq os (getvar "osmode"))
 (setq oldvar (getvar "lunits"))
 (setq oldvar2 (getvar "luprec"))
 (setvar "lunits" 2)
 (setvar "luprec" 0)
 (princ)
 (setq scale (rtos (getvar "dimscale")))
 (princ)
 (setvar "lunits" oldvar)
 (setvar "luprec" oldvar)
 (command "-osnap" "near")
 (setq es (entsel "\nSpecify the host pipe: "))
 (command "select" es "")
 (if (setq es (ssget "_p" '((0 . "*POLYLINE"))))
     (setq es1 (entlast))
     (command "_.explode" es1))
 (setq ro (ssget "L")
a1 (cdr (assoc 10 (entget ro)))
a2 (cdr (assoc 11 (entget ro)))
ro (angle a1 a2)
)
 (setq po (getpoint (strcat "\nSpecify insertion point of valve: ")))
 (command "_.insert" (block_name10) "s" scale po ro)
 (setvar "osmode" os)
 (setq  ss (get_blk_info)
 x1 (cadr ss)
 x2 (caddr ss)
 ss (car ss))  
 (command "break" es "f" x1 x2)
)
;end of command
;;``````````````````````````````````````````````````````````````````````````````;;
;;        valve_print_settings10 ;;
;;  Controls the initial command line print of     ;;
;;  Valve type = Valve Name, Dimscale = x     ;;
;;______________________________________________________________________________;;
(defun valve_print_settings10 ( / )
 (setq oldvar (getvar "lunits"))
 (setq oldvar2 (getvar "luprec"))
 (setvar "lunits" 2)
 (setvar "luprec" 0)
 (princ)
 (setq dimscale (rtos (getvar "dimscale")))
 (princ)
 (setvar "lunits" oldvar)
 (setvar "luprec" oldvar)
 (prompt (strcat "\nValve type = " (block_name10) ", Dimscale = " dimscale))
 )
;;``````````````````````````````````````````````````````````````````````````````;;
;;             block_name10 ;;
;;  Controls what block to insert       ;;
;;  and defines the Valve in the valve_print_settings    ;;
;;______________________________________________________________________________;;
(defun block_name10 (/ )
 (setq blk_nm "Thermostatic Mixing Valve")
 blk_nm
 )
;;``````````````````````````````````````````````````````````````````````````````;;
;;           get_blk_info10 ;;
;;  Collects the defpoints within the block and creates a list   ;;
;;            ;;
;;______________________________________________________________________________;;
(defun get_blk_info10 ( po / na scale na2 ss ss2 ss3 p1 p2 lst)
 (setq na (entlast));setq
 (setq scale (rtos (getvar "dimscale")))
 (command "_.insert" (BLOCK_NAME10) "s" scale po 0)
 (if (not (equal na (entlast)))
   (progn
     (command "_.explode" (entlast))
     (while (wcmatch (getvar "cmdnames") "*EXPLODE*")
(command ""))
     (setq ss (acet-ss-new na))
     )
   )
 (if ss
   (progn
     (setq ss3 (ssget "_p" '((0 . "*POLYLINE"))))
     (setq na (entlast))
     (command "_.explode" ss3)
     (while (wcmatch (getvar "cmdnames") "*EXPLODE*")
(command "")
)
     (if (and (setq ss3 (acet-ss-new na))
       (> (sslength ss3) 0)
       )
(progn
  (command "_.select" ss ss3 "")
  (setq ss (ssget "_p"))
  )
(command "_.select" ss "")
)
     )
   )
 (if ss
   (progn
     (setq ss2 (ssget "_p" '((0 . "POINT") (8 . "DEFPOINTS"))))
     )
   )
 (if (and ss2
   (= (sslength ss2) 2))
   (progn
     (setq  na (ssname ss2 0)
     ss (ssdel na ss)
     p1 (cdr (assoc 10 (entget na)))
     p1 (trans p1 0 1)
     )
     (entdel na)
     (setq  na (ssname ss2 1)
     ss (ssdel na ss)
     p2 (cdr (assoc 10 (entget na)))
     p2 (trans p2 0 1)
     )
     (entdel na)
     )
   (setq ss2 nil)
   )
 (cond (T (setq lst (list ss p1 p2))))
 lst
 )

;;``````````````````````````````````````````````````````````````````````````````;;
;;////////////////////////[END THERMOSTATIC MIXING VALVE]\\\\\\\\\\\\\\\\\\\\\\\;;
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;

 

Alright now heres the problem: I can't seem to understand how to get autocad to accept both the coordinates from the angle of the line for rotating the block, as well as, the defpoints listed in the get_block_info for breaking the line. So if any of you brilliant forum dieties could lend me a hand I would be greatful. I would also love to get some tips too!

 

Thank you,

 

Matt

Posted

This same thing has been asked and solved on this forum several times. Search around for insert and trim block or something of the like.

Posted
Hey all,

 

I need some help, I have written the lisp routine below and decided to update it with some new features except that the complexity is a bit further than I can comprehend right now.

 

My old version just prompted for insertion point and rotation of the valve and the scale is based off of the current dimscale. I decided, however, that I wanted the block to rotate it's self according to the line it was bieng inserted on, then break to that line and eventually join itself with the line. The code is below so please point me in the right direction.

 

;;``````````````````````````````````````````````````````````````````````````````;;
;;--------------------------THERMOSTATIC MIXING VALVE---------------------------;;  (10)
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;
;start of command
(defun c:tmv ( / ss es ro a1 a2 os scale osm oldvar oldvar2 a po b)
 (if (= (getvar "dimanno") 1)
   (progn (command "-dimstyle" "r" "standard")
     (setq b (initget 128))
     (setq a (getreal "\nDefine your drawing scale: "))
     (command "dimscale" a)
     )
   )
 (if (= (getvar "dimscale") 0)
   (PROGN (setq B (getreal "\nDefine your drawing scale: "))
     (COMMAND "dimscale" B)
     )
   )
 (sssetfirst nil nil)
 (valve_print_settings10)
 (setq os (getvar "osmode"))
 (setq oldvar (getvar "lunits"))
 (setq oldvar2 (getvar "luprec"))
 (setvar "lunits" 2)
 (setvar "luprec" 0)
 (princ)
 (setq scale (rtos (getvar "dimscale")))
 (princ)
 (setvar "lunits" oldvar)
 (setvar "luprec" oldvar)
 (command "-osnap" "near")
 (setq es (entsel "\nSpecify the host pipe: "))
 (command "select" es "")
 (if (setq es (ssget "_p" '((0 . "*POLYLINE"))))
     (setq es1 (entlast))
     (command "_.explode" es1))
 (setq ro (ssget "L")
a1 (cdr (assoc 10 (entget ro)))
a2 (cdr (assoc 11 (entget ro)))
ro (angle a1 a2)
)
 (setq po (getpoint (strcat "\nSpecify insertion point of valve: ")))
 (command "_.insert" (block_name10) "s" scale po ro)
 (setvar "osmode" os)
 (setq  ss (get_blk_info)
 x1 (cadr ss)
 x2 (caddr ss)
 ss (car ss))  
 (command "break" es "f" x1 x2)
)
;end of command
;;``````````````````````````````````````````````````````````````````````````````;;
;;        valve_print_settings10 ;;
;;  Controls the initial command line print of     ;;
;;  Valve type = Valve Name, Dimscale = x     ;;
;;______________________________________________________________________________;;
(defun valve_print_settings10 ( / )
 (setq oldvar (getvar "lunits"))
 (setq oldvar2 (getvar "luprec"))
 (setvar "lunits" 2)
 (setvar "luprec" 0)
 (princ)
 (setq dimscale (rtos (getvar "dimscale")))
 (princ)
 (setvar "lunits" oldvar)
 (setvar "luprec" oldvar)
 (prompt (strcat "\nValve type = " (block_name10) ", Dimscale = " dimscale))
 )
;;``````````````````````````````````````````````````````````````````````````````;;
;;             block_name10 ;;
;;  Controls what block to insert       ;;
;;  and defines the Valve in the valve_print_settings    ;;
;;______________________________________________________________________________;;
(defun block_name10 (/ )
 (setq blk_nm "Thermostatic Mixing Valve")
 blk_nm
 )
;;``````````````````````````````````````````````````````````````````````````````;;
;;           get_blk_info10 ;;
;;  Collects the defpoints within the block and creates a list   ;;
;;            ;;
;;______________________________________________________________________________;;
(defun get_blk_info10 ( po / na scale na2 ss ss2 ss3 p1 p2 lst)
 (setq na (entlast));setq
 (setq scale (rtos (getvar "dimscale")))
 (command "_.insert" (BLOCK_NAME10) "s" scale po 0)
 (if (not (equal na (entlast)))
   (progn
     (command "_.explode" (entlast))
     (while (wcmatch (getvar "cmdnames") "*EXPLODE*")
(command ""))
     (setq ss (acet-ss-new na))
     )
   )
 (if ss
   (progn
     (setq ss3 (ssget "_p" '((0 . "*POLYLINE"))))
     (setq na (entlast))
     (command "_.explode" ss3)
     (while (wcmatch (getvar "cmdnames") "*EXPLODE*")
(command "")
)
     (if (and (setq ss3 (acet-ss-new na))
       (> (sslength ss3) 0)
       )
(progn
  (command "_.select" ss ss3 "")
  (setq ss (ssget "_p"))
  )
(command "_.select" ss "")
)
     )
   )
 (if ss
   (progn
     (setq ss2 (ssget "_p" '((0 . "POINT") (8 . "DEFPOINTS"))))
     )
   )
 (if (and ss2
   (= (sslength ss2) 2))
   (progn
     (setq  na (ssname ss2 0)
     ss (ssdel na ss)
     p1 (cdr (assoc 10 (entget na)))
     p1 (trans p1 0 1)
     )
     (entdel na)
     (setq  na (ssname ss2 1)
     ss (ssdel na ss)
     p2 (cdr (assoc 10 (entget na)))
     p2 (trans p2 0 1)
     )
     (entdel na)
     )
   (setq ss2 nil)
   )
 (cond (T (setq lst (list ss p1 p2))))
 lst
 )

;;``````````````````````````````````````````````````````````````````````````````;;
;;////////////////////////[END THERMOSTATIC MIXING VALVE]\\\\\\\\\\\\\\\\\\\\\\\;;
;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;

 

Alright now heres the problem: I can't seem to understand how to get autocad to accept both the coordinates from the angle of the line for rotating the block, as well as, the defpoints listed in the get_block_info for breaking the line. So if any of you brilliant forum dieties could lend me a hand I would be greatful. I would also love to get some tips too!

 

Thank you,

 

Matt

 

 

See this thread:

 

http://www.cadtutor.net/forum/showthread.php?t=38340&highlight=INSERT+BLOCK+WITH+TRIM

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...