Jump to content

Placing block at dead end Lines


Recommended Posts

lucky9

I have this block which needs to be placed at the end of  each dead end line.  Can it be automated , like selecting the block then selecting all the lines and blocks will be placed. thanks 

 

 

 

71148d119874f2c020d3243d1bf641dc.png

Link to post
Share on other sites
mhupp

If they are lines they would have to be drawn the same way.  The first point picked when drawing a line is always 10 the other endpoint will be 11.

Attached the red line is drawn from the center point of the white to the end of the blue line. that is why the block is backwards.

the rest of the lines were draw by picking the point not touching the white line first.

 

image.thumb.png.545c87e8213a2b48f44d74144e113ff3.png

 

 

This is just a basic lisp to get you what you need. The block 0 degree needs to be like the one in the rectangle.

 

(defun C:BLKPlace (/ ss blk blkname pt1 pt2 ang)
  (prompt "\nSelect Lines")
  (setq SS (ssget))
  (setq blk (car (entsel "\nSelect Block")))
  (setq blkname (cdr (assoc 2 (entget blk))))  
  (setvar 'cmdecho 0)
  (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq pt1 (cdr (assoc 10 (entget x)))
          pt2 (cdr (assoc 11 (entget x)))
          ang (* 180.0 (/ (angle pt1 pt2) pi))
    )
    (vl-cmdf "-Insert" blkname pt1 "" "" ang)
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

Link to post
Share on other sites
lucky9

Thank you guys, I'm attaching a sample drawing. Is it possible to automate placing bends also. BTW the end plug block is attached with the drawing which and all the bends blocks too. 

 

2 hours ago, mhupp said:

If they are lines they would have to be drawn the same way.  The first point picked when drawing a line is always 10 the other endpoint will be 11.

Attached the red line is drawn from the center point of the white to the end of the blue line. that is why the block is backwards.

the rest of the lines were draw by picking the point not touching the white line first.

 

image.thumb.png.545c87e8213a2b48f44d74144e113ff3.png

 

 

This is just a basic lisp to get you what you need. The block 0 degree needs to be like the one in the rectangle.

 




(defun C:BLKPlace (/ ss blk blkname pt1 pt2 ang)
  (prompt "\nSelect Lines")
  (setq SS (ssget))
  (setq blk (car (entsel "\nSelect Block")))
  (setq blkname (cdr (assoc 2 (entget blk))))  
  (setvar 'cmdecho 0)
  (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq pt1 (cdr (assoc 10 (entget x)))
          pt2 (cdr (assoc 11 (entget x)))
          ang (* 180.0 (/ (angle pt1 pt2) pi))
    )
    (vl-cmdf "-Insert" blkname pt1 "" "" ang)
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

 

I have tried your code but I am getting a error message  "Select Block; error: bad argument type: 2D/3D point: nil" I need to work with the block I have in the sample drawing attached herewith. Some bends blocks are also attached please have a look. 

 

Best Wishes 

Sample_to_automate.dwg

Edited by lucky9
Attachment
Link to post
Share on other sites
lucky9
2 hours ago, ronjonp said:

THIS too.

Your code is not working with my block, Even after changing  my block name to "End Cap"

 

 

Edited by lucky9
Link to post
Share on other sites
mhupp
41 minutes ago, lucky9 said:

I have tried your code but I am getting a error message  "Select Block; error: bad argument type: 2D/3D point: nil

 

Its giving an error because my code uses lines to generate points. the blue "lines" in your drawing are polylines so points are not generated.  Error "2D/3D point: nil"

 

@ronjonp's code works but block needs to be rotated 180, scaled up by 8. then exploded and made a block again with new orientation and scale. see attached.

test.dxf

Link to post
Share on other sites
BIGAL

Mhupp look at check does end pt touch any other object if so then its not the "Dead end" put block on other end.

 

Re add other type of blocks, I can see problems as the linework is not drawn in true pipe directions eg "T", bends 22.5, 45, 90 etc I can see its diagramatic. The only thing I can see say for T is pick line 1 line 2 and it will add 90 deg to 2nd line.

Link to post
Share on other sites
Jonathan Handojo

Pretty ugly, but I guess better than nothing:

 

(defun foo:settings nil
    (list
        "END POINT"     ; Name of block to insert
        0               ; Additional rotation of block in radians
        8               ; Scale of the block to insert
        1e-6            ; Tolerance to consider an end point touching a curve
    )
)

(defun c:foo ( / *error* activeundo acadobj adoc ep msp nm rot scl sp ss ss_lst sx)
    (defun *error* ( msg )
        (vla-EndUndoMark adoc)
        (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*exit*"))
            (princ (strcat "Error: " msg))
        )
    )
    (defun ss_lst (ss / rtn i) 
        (if ss 
            (repeat (setq i (sslength ss)) 
                (setq rtn (cons (ssname ss (setq i (1- i))) rtn))
            )
        )
    )
    (setq
        acadobj (vlax-get-acad-object)
        adoc (vla-get-ActiveDocument acadobj)
        msp (vla-get-ModelSpace adoc)
        activeundo nil
    )
    (if (= 0 (logand 8 (getvar "UNDOCTL"))) (vla-StartUndoMark adoc) (setq activeundo T))
    (mapcar 'set '(nm rot scl fz) (foo:settings))
    (if 
        (setq ss (ss_lst (ssget (list '(0 . "LINE,LWPOLYLINE,ARC,ELLIPSE,SPLINE")))))
        (foreach x ss
            (setq sp (vlax-curve-getstartpoint x) ep (vlax-curve-getendpoint x) sx (vl-remove x ss))
            (if (not (vl-some '(lambda (a) (equal sp (vlax-curve-getclosestpointto a sp) fz)) sx))
                (vla-insertblock msp (vlax-3d-point sp) nm scl scl scl 
                    (+ 
                        (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv x (vlax-curve-getstartparam x)))
                        rot pi
                    )
                )
            )
            (if (not (vl-some '(lambda (a) (equal ep (vlax-curve-getclosestpointto a ep) fz)) sx))
                (vla-insertblock msp (vlax-3d-point ep) nm scl scl scl 
                    (+ 
                        (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv x (vlax-curve-getendparam x)))
                        rot
                    )
                )
            )
        )
    )
    (if activeundo nil (vla-EndUndoMark adoc))
    (princ)
)
(vl-load-com)

 

Edited by Jonathan Handojo
Link to post
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
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...