Jump to content

Recommended Posts

Posted

I have a lisp to insert blocks, 90% of them work fine, the block being inserted is the same size a few of them break the line they are being inserted on too much, the first one below inserts fine, the second one leaves a gap between the edge of the block (a circle) and the pipe (just a regular line in acad) Ive attached the blocks, i know it has to do with pt 1 and pt 2 but I dont know how to change them to the right points.

 

(defun c:gv (/ *error* scl dis ov vl
               lne pnt ang pt1 pt2)

 ;; Always localise your variables!
 
 (or (not (zerop (setq scl (getvar "DIMSCALE"))))
     (setq scl 1.))

 ;; Dimscale may be zero - need to check for this
 
 (setq dis (* scl 0.0703))

 ;; Use an Error Handler as we are tampering with Sys Vars
 
 (defun *error* (msg)
   (if ov (mapcar 'setvar vl ov)) ; Reset Sys Vars    
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n<< Error: " msg " >>")))
   (princ))

 (setq vl '("CMDECHO" "OSMODE" "CLAYER") ; Sys Var list
       ov (mapcar 'getvar vl)) ; Get Old Sys Var Values
 
 (if (or (tblsearch "BLOCK" "gv") ; Check for Block in Dwg...
         (findfile "gv.dwg"))   ;... And in Search path
   (progn
     
     (while ; While the following returns T
       
       (progn ; Wrap the following expressions
         
         (setq lne (entsel "\nSelect a Line: ")) ; Select a Line
         
         (cond ((null lne) t) ; Stay in Loop
               ((eq "LINE"
                  (cdr (assoc 0 (setq elst (entget (car lne)))))) nil) ; Exit Loop
               (t (princ "\n** Incorrect Selection **"))))) ; Stay in Loop
     
     (if (setq pt (getpoint "\nPick Insertion Point: ")) ; Prompt for Point
       (progn
         (setq ang (angle (cdr (assoc 10 elst)) (cdr (assoc 11 elst)))) ; Get Line Angle
         
         (mapcar 'setvar vl (list 0 0 (cdr (assoc 8 (entget (car lne))))))

         ; Set Sys Vars to how we want them - CMDECHO=0, OSMODE=0, CLAYER= <line layer>
         
         (command "-insert" "gv" pt scl scl (* 180. (/ ang pi))) ; insert Block

         ;; Prefix commands with "_." to make them language compatible
         
         (setq pt1 (polar pt ang dis)
               pt2 (polar pt (- ang pi) dis))
         
         (command "_.break" lne "_F" pt1 pt2))))
   
   (princ "\n<< Block Not Found >>")) ; Else the Block was not found
 
 (mapcar 'setvar vl ov) ; Reset Sys Vars
 
 (princ)) ; Exit Cleanly

 

(defun c:priser (/ *error* scl dis ov vl
               lne pnt ang pt1 pt2)

 ;; Always localise your variables!
 
 (or (not (zerop (setq scl (getvar "DIMSCALE"))))
     (setq scl 1.))

 ;; Dimscale may be zero - need to check for this
 
 (setq dis (* scl 0.0703))

 ;; Use an Error Handler as we are tampering with Sys Vars
 
 (defun *error* (msg)
   (if ov (mapcar 'setvar vl ov)) ; Reset Sys Vars    
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n<< Error: " msg " >>")))
   (princ))

 (setq vl '("CMDECHO" "OSMODE" "CLAYER") ; Sys Var list
       ov (mapcar 'getvar vl)) ; Get Old Sys Var Values
 
 (if (or (tblsearch "BLOCK" "priser") ; Check for Block in Dwg...
         (findfile "priser.dwg"))   ;... And in Search path
   (progn
     
     (while ; While the following returns T
       
       (progn ; Wrap the following expressions
         
         (setq lne (entsel "\nSelect a Line: ")) ; Select a Line
         
         (cond ((null lne) t) ; Stay in Loop
               ((eq "LINE"
                  (cdr (assoc 0 (setq elst (entget (car lne)))))) nil) ; Exit Loop
               (t (princ "\n** Incorrect Selection **"))))) ; Stay in Loop
     
     (if (setq pt (getpoint "\nPick Insertion Point: ")) ; Prompt for Point
       (progn
         (setq ang (angle (cdr (assoc 10 elst)) (cdr (assoc 11 elst)))) ; Get Line Angle
         
         (mapcar 'setvar vl (list 0 0 (cdr (assoc 8 (entget (car lne))))))

         ; Set Sys Vars to how we want them - CMDECHO=0, OSMODE=0, CLAYER= <line layer>
         
         (command "-insert" "priser" pt scl scl (* 180. (/ ang pi))) ; insert Block

         ;; Prefix commands with "_." to make them language compatible
         
         (setq pt1 (polar pt ang dis)
               pt2 (polar pt (- ang pi) dis))
         
         (command "_.break" lne "_F" pt1 pt2))))
   
   (princ "\n<< Block Not Found >>")) ; Else the Block was not found
 
 (mapcar 'setvar vl ov) ; Reset Sys Vars
 
 (princ)) ; Exit Cleanly

GV.DWG

PRISER.dwg

Posted

the image below shows GV (the first block on the line) with the line broken at the edge lines of GV, then it shows the circle priser and the lines the do not meet with the edge of the circle. i want them to meet with the edge like it does with GV

break.jpg

Posted

The "priser" block is smaller than the GV.

 

In the line that reads:

(setq dis (* scl 0.0703)

 

change it to:

(setq dis (* scl 0.0469)

 

since that is the value of priser's radius

Posted

sorry for the late reply was gone for a long weekend. That works perfect... Thanks

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