Jump to content

Recommended Posts

Posted

hallo masters.

I need one help. let me explain that 

need to insert one block between 3 lines (pipe) Intersection point and automatically rotate the block suitable for routing after inserting trim remaining area (same as lee mac auto block break) if can measure the distance 3 line and scale the block 

 

1. I will create a block suitable for 100 mm pipe

2. for pipe will use multiline. and after I will explode. because multiline will not vary the pipe size, pipe size will be okay.

3. I need to insert that block on the Intersection point with scale so I can use different pipe sizes with the same block. 

4. I will use only this tool 0° 90° 180° 270° pipe angle (so I can use the same block) check the 2 angle of pipe routing and rotate the block as that need(i will make all block the same angle  )

5. after the Intersection, trim the remaining area.

 

* if I can set the block on the first time from the drawings that will be good

* same as window selection that will be great 

 

please check the drawing that will help full for what am thinking

PIPE.dwg

Posted (edited)

For me I think do it all in one go, just draw the centre line as a pline, ask for size 100, 150, 225, 300 etc and visibilty A B C D, then offset, insert and scale to suit dia. 

 

image.png.87a117e6ef2e22cb3b11f7f1d2473a42.png

 

(defun c:testdia ( / )
(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:but nil)(setq ah:but 1))
(if (= ah:but2 nil)(setq ah:but2 1))
(setq lst1 (list "Select Dia " "100" "150" "225" "300" "Other"))
(setq lst2 (list "Select Visibilty " "A" "B" "C" "D"))
(ah:buttscol ah:but ah:but2 "Please select " lst1 lst2)
)
(C:testdia)

I have the code also to insert a dynamic block and set to a visibility state.

 

If happy with this idea let me know. And will add to my, To do list.

Multi radio buttons 2col.lsp

Edited by BIGAL
Posted

my issue not with visibility, no need to check visibility. visibility I will change manually. I need to insert block on the centerline 

Posted

That is what I said do it all in one go, draw centrelines, select the pipe size and visibility all done. No need to do 3 or 4 draw objects and trim etc. Draw it once to match block, that is what automation is about. Maybe 2-3 seconds to do. 

 

What are pipe sizes ?

 

Posted

I have to add some trimming to this, but before I do try it out, let me know what it needs. 

 

(defun c:testdia ( / )
(setvar 'orthomode 1)
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 3)
(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:but nil)(setq ah:but 1))
(if (= ah:but2 nil)(setq ah:but2 1))
(setq lst1 (list "Select Dia " "25" "32" "50" "82" "110"))
(setq lst2 (list "Select Visibilty " "A" "B" "C" "D"))
(ah:buttscol ah:but ah:but2 "Please select " lst1 lst2)
(setq dia (/ (atof (nth ah:2col lst1)) 2.0))
(setq ans (nth ah:2col2 lst2))
(setq pt1 (getpoint "\nStarting point of Pline : "))
(setq pt2 (getpoint pt1 "\npick second point "))
(setq pt3 (getpoint pt2 "\npick 3rd point "))
(command "_pline" pt1 pt2 pt3 "")
(setq ang1 (angle pt2 pt1) ang2 (angle pt2 pt3))
(setq obj (vlax-ename->vla-object  (entlast)))
(vla-offset obj dia)
(setq off1 (vlax-ename->vla-object  (entlast)))
(vla-offset obj (- 0.0 dia))
(setq off2 (vlax-ename->vla-object  (entlast)))
(command "line" (vlax-curve-getstartPoint off1) (vlax-curve-getstartPoint off2) "")
(command "line" (vlax-curve-getendPoint off1) (vlax-curve-getendPoint off2) "")
(setvar 'clayer "01-FITTINGS")
(command "-insert" "CHWP ELBOW 40 mm  90° ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2)
(setq obj (vlax-ename->vla-object (entlast)))
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(LM:SetVisibilityState obj ans)
; do trim
(setvar 'aunits oldaunits)
(princ)
)
(C:testdia)

 

Lee-mac Dynamic block get-put.lsp

Posted (edited)

This is what I need but here are some suggestions. the block is not rotating properly. the same angle if I draw reverse the block is not rotating properly. and if I can draw continuously that will be good. same like pipe draw in Revit. 

 

Edited by Ajmal
Posted (edited)

I was a bit worried about direction will have  a think about it and add the correct trim. 

 

Not sure what you mean the direction is based on the way the center line pline is drawn, this is left -> right, then right -> left. Can you clarify please. Could add a question "FLIP" ?

 

image.png.651093df3e52fc3e3badf496ec3184d5.png

Edited by BIGAL
Posted (edited)

Try this I added things to @BIGAL code, no trimming but scaling instead. And angles should work fine. Tested it and it seems working, but only problem is it breaks on error after first time you run the function in drawing. Don't know why, I made all variables local I think. Maybe someone can debug and figure out why is that?


 

(defun c:testdia ( / oldosmode oldaunits lst1 lst2 dia ans pt1 start pt2 pt3 fact fact2 d12 dif_scl fact12 lin1 ang1 obj offset1L off1 offset1R off2 pt2old lin2 ang2 d23 fact23 offset2L offset2R)
(setvar 'orthomode 1)
(setq oldosmode (getvar 'osmode));snap
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 0);degrees
(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:but nil)(setq ah:but 1))
(if (= ah:but2 nil)(setq ah:but2 1))
(setq lst1 (list "Select Dia " "25" "32" "50" "82" "110"))
(setq lst2 (list "Select Visibilty " "A" "B" "C" "D"))
(ah:buttscol ah:but ah:but2 "Please select " lst1 lst2)
(setq dia (/ (atof (nth ah:2col lst1)) 2.0))
(setq ans (nth ah:2col2 lst2))
(setq fact (/ dia 50.0))
(setq fact2 (* fact 102))
(setq start 0)
(if (and
      (setq pt1 (getpoint "\nStarting point of pipe: "))
      (setq pt2 (getpoint pt1 "\nPick second point: ")))
(progn
(while
(setq pt3 (getpoint pt2 "\nPick next point: "))
(setvar 'osmode 0)
(cond
  ((= start 0)
(setq d12 (distance pt1 pt2))
(setq dif_scl (- d12 fact2))
(setq fact12 (/ dif_scl d12))
(setvar 'clayer "0")
(command "_line" pt1 pt2 "")
(setq lin1 (entlast))
(command "_scale" lin1 "" pt1 fact12)
(setq ang1 (angtos (angle pt1 pt2)))
(setq obj (vlax-ename->vla-object lin1))
(vla-offset obj dia)
(setq offset1L (entlast))
(setq off1 (vlax-ename->vla-object lin1))
(vla-offset obj (- 0.0 dia))
(setq offset1R (entlast))
(setq off2 (vlax-ename->vla-object lin1))
(vla-put-linetype (vlax-ename->vla-object lin1) "Center")
(vla-put-linetypescale (vlax-ename->vla-object lin1) 10)
)
  ((= start 1)
(setq pt1 pt2old)
(setq lin1 lin2)
(setq d12 (distance (vlax-curve-getstartPoint lin1) (vlax-curve-getendPoint lin1)))
(setq dif_scl (- d12 fact2))
(setq fact12 (/ dif_scl d12))
(command "_scale" lin1 "" (vlax-curve-getstartPoint lin1) fact12)
(setq offset1L offset2L)
(command "_scale" offset1L "" (vlax-curve-getstartPoint offset1L) fact12)
(setq offset1R offset2R)
(command "_scale" offset1R "" (vlax-curve-getstartPoint offset1R) fact12)
(setq ang1 (angtos (angle pt1 pt2)))
)
);cond
(setq d23 (distance pt2 pt3))
(setq dif_scl (- d23 fact2))
(setq fact23 (/ dif_scl d23))
(setvar 'clayer "0")
(command "_line" pt2 pt3 "")
(setq lin2 (entlast))
(command "_scale" lin2 "" pt3 fact23)
(setq obj (vlax-ename->vla-object lin2))
(vla-offset obj dia)
(setq offset2L (entlast))
(setq off1 (vlax-ename->vla-object lin2))
(vla-offset obj (- 0.0 dia))
(setq offset2R (entlast))
(setq off2 (vlax-ename->vla-object lin2))
(vla-put-linetype (vlax-ename->vla-object lin2) "Center")
(vla-put-linetypescale (vlax-ename->vla-object lin2) 10)
(cond ((= ang1 "0")
       (cond ((< (cadr pt2) (cadr pt3))
	      (setq ang2 "90")
	      )
	     ((> (cadr pt2) (cadr pt3))
	      (setq ang2 "180")
	      )
	     );cond
       )
      ((= ang1 "180")
       (cond ((< (cadr pt2) (cadr pt3))
	      (setq ang2 "0")
	      )
	     ((> (cadr pt2) (cadr pt3))
	      (setq ang2 "270")
	      )
	     );cond
       )
      ((= ang1 "90")
       (cond ((< (car pt2) (car pt3))
	      (setq ang2 "270")
	      )
	     ((> (car pt2) (car pt3))
	      (setq ang2 "180")
	      )
	     );cond
       )
      ((= ang1 "270")
       (cond ((< (car pt2) (car pt3))
	      (setq ang2 "0")
	      )
	     ((> (car pt2) (car pt3))
	      (setq ang2 "90")
	      )
	     );cond
       )
      );cond
(setvar 'clayer "01-FITTINGS")
(command "-insert" "CHWP ELBOW 40 mm  90° ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2)
(setq obj (vlax-ename->vla-object (entlast)))
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(LM:SetVisibilityState obj ans)
(setq pt2old pt2)
(setq pt2 pt3)
(setq start 1)
(setvar 'aunits oldaunits)
(setvar 'osmode oldosmode)
);while
);progn
);if
)

 

Edited by lastknownuser
  • Thanks 1
Posted (edited)

Where is the load Lee-mac functions.

 

(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(LM:SetVisibilityState obj ans)

 Just a comment change the name of the defun to something that suits you.

Edited by BIGAL
Posted

Probably deleted it by accident, I edited the post. 

Posted
23 hours ago, lastknownuser said:

Try this I added things to @BIGAL code, no trimming but scaling instead. And angles should work fine. Tested it and it seems working, but only problem is it breaks on error after first time you run the function in drawing. Don't know why, I made all variables local I think. Maybe someone can debug and figure out why is that?


 

(defun c:testdia ( / oldosmode oldaunits lst1 lst2 dia ans pt1 start pt2 pt3 fact fact2 d12 dif_scl fact12 lin1 ang1 obj offset1L off1 offset1R off2 pt2old lin2 ang2 d23 fact23 offset2L offset2R)
(setvar 'orthomode 1)
(setq oldosmode (getvar 'osmode));snap
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 0);degrees
(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:but nil)(setq ah:but 1))
(if (= ah:but2 nil)(setq ah:but2 1))
(setq lst1 (list "Select Dia " "25" "32" "50" "82" "110"))
(setq lst2 (list "Select Visibilty " "A" "B" "C" "D"))
(ah:buttscol ah:but ah:but2 "Please select " lst1 lst2)
(setq dia (/ (atof (nth ah:2col lst1)) 2.0))
(setq ans (nth ah:2col2 lst2))
(setq fact (/ dia 50.0))
(setq fact2 (* fact 102))
(setq start 0)
(if (and
      (setq pt1 (getpoint "\nStarting point of pipe: "))
      (setq pt2 (getpoint pt1 "\nPick second point: ")))
(progn
(while
(setq pt3 (getpoint pt2 "\nPick next point: "))
(setvar 'osmode 0)
(cond
  ((= start 0)
(setq d12 (distance pt1 pt2))
(setq dif_scl (- d12 fact2))
(setq fact12 (/ dif_scl d12))
(setvar 'clayer "0")
(command "_line" pt1 pt2 "")
(setq lin1 (entlast))
(command "_scale" lin1 "" pt1 fact12)
(setq ang1 (angtos (angle pt1 pt2)))
(setq obj (vlax-ename->vla-object lin1))
(vla-offset obj dia)
(setq offset1L (entlast))
(setq off1 (vlax-ename->vla-object lin1))
(vla-offset obj (- 0.0 dia))
(setq offset1R (entlast))
(setq off2 (vlax-ename->vla-object lin1))
(vla-put-linetype (vlax-ename->vla-object lin1) "Center")
(vla-put-linetypescale (vlax-ename->vla-object lin1) 10)
)
  ((= start 1)
(setq pt1 pt2old)
(setq lin1 lin2)
(setq d12 (distance (vlax-curve-getstartPoint lin1) (vlax-curve-getendPoint lin1)))
(setq dif_scl (- d12 fact2))
(setq fact12 (/ dif_scl d12))
(command "_scale" lin1 "" (vlax-curve-getstartPoint lin1) fact12)
(setq offset1L offset2L)
(command "_scale" offset1L "" (vlax-curve-getstartPoint offset1L) fact12)
(setq offset1R offset2R)
(command "_scale" offset1R "" (vlax-curve-getstartPoint offset1R) fact12)
(setq ang1 (angtos (angle pt1 pt2)))
)
);cond
(setq d23 (distance pt2 pt3))
(setq dif_scl (- d23 fact2))
(setq fact23 (/ dif_scl d23))
(setvar 'clayer "0")
(command "_line" pt2 pt3 "")
(setq lin2 (entlast))
(command "_scale" lin2 "" pt3 fact23)
(setq obj (vlax-ename->vla-object lin2))
(vla-offset obj dia)
(setq offset2L (entlast))
(setq off1 (vlax-ename->vla-object lin2))
(vla-offset obj (- 0.0 dia))
(setq offset2R (entlast))
(setq off2 (vlax-ename->vla-object lin2))
(vla-put-linetype (vlax-ename->vla-object lin2) "Center")
(vla-put-linetypescale (vlax-ename->vla-object lin2) 10)
(cond ((= ang1 "0")
       (cond ((< (cadr pt2) (cadr pt3))
	      (setq ang2 "90")
	      )
	     ((> (cadr pt2) (cadr pt3))
	      (setq ang2 "180")
	      )
	     );cond
       )
      ((= ang1 "180")
       (cond ((< (cadr pt2) (cadr pt3))
	      (setq ang2 "0")
	      )
	     ((> (cadr pt2) (cadr pt3))
	      (setq ang2 "270")
	      )
	     );cond
       )
      ((= ang1 "90")
       (cond ((< (car pt2) (car pt3))
	      (setq ang2 "270")
	      )
	     ((> (car pt2) (car pt3))
	      (setq ang2 "180")
	      )
	     );cond
       )
      ((= ang1 "270")
       (cond ((< (car pt2) (car pt3))
	      (setq ang2 "0")
	      )
	     ((> (car pt2) (car pt3))
	      (setq ang2 "90")
	      )
	     );cond
       )
      );cond
(setvar 'clayer "01-FITTINGS")
(command "-insert" "CHWP ELBOW 40 mm  90° ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2)
(setq obj (vlax-ename->vla-object (entlast)))
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(LM:SetVisibilityState obj ans)
(setq pt2old pt2)
(setq pt2 pt3)
(setq start 1)
(setvar 'aunits oldaunits)
(setvar 'osmode oldosmode)
);while
);progn
);if
)

 

 

This is what i expect 🥰🥰🥰🥰, thanks. great tool.

I have one more suggestion. let me explain. this 
1. for pipe size type "d" I need to change it so I can put whatever pipe size
2. for visibility only multi-Radio buttons. 
3. (optional) If I can change the visibility while drawing pipe by typing "s" that will be great (if too much am asking no need for this 😉)

Posted

In the radio buttons bit can add "Other" then it will ask for size. Also a bit hidden if you run again can set the buttons to last selected so just hit OK. Will show how.

 

(setq lst1 (list "Select Dia " "25" "32" "50" "82" "110" "Other"))

(if (= (nth ah:2col lst1) "Other")
(setq dia (getreal "\nEnter dia size ")
(setq dia (/ (atof (nth ah:2col lst1)) 2.0))
)
(setq ah:but ah:2col ah:but2 ah:2col2)

 

  • 3 weeks later...
Posted (edited)

 

(defun c:PIPE ( / osm oldaunits pipesize dia pt1 pt2 pt3 start ang1 ang2 lin1 lin2 offset1L offset1R offset2L offset2R)
  (defun *error* ( msg )
    (if (= 'int (type osm)) (setvar 'osmode osm))
    (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )

  ;; Save original settings
  (setvar 'orthomode 1)
  (setq osm (getvar 'osmode)
        olr (getvar 'clayer)
        oldaunits (getvar 'aunits))

  ;; Set the angle units to degrees
  (setvar 'aunits 0)

  ;; Get the pipe size from the user
  (if (or (not (setq tmp (getenv "GPIPESIZE")))
            (not (setq tmp (distof tmp 2)))
        )
        (setenv "GPIPESIZE" (rtos (setq tmp 25) 2 2))
    )
    (initget 4)
    (if (setq pipesize (getreal (strcat "\nSpecify the pipe size <" (rtos tmp 2 2) ">: ")))
        (setenv "GPIPESIZE" (rtos pipesize 2 2))
        (setq pipesize tmp)
    )
  (setq dia (/ pipesize 2.0)start 0)


  ;; Main loop to draw the pipe segments
  (if (and
        (setq pt1 (reverse (cdr (reverse (getpoint "\nStarting point of pipe: ")))))
        (setq pt2 (reverse (cdr (reverse (getpoint pt1 "\nPick second point: "))))))
    (progn
      (while
        (setq pt3 (reverse (cdr (reverse (getpoint pt2 "\nPick next point: ")))))
        (setvar 'osmode 0)
        (setvar "CMDECHO" 0)
        (cond
          ((= start 0)
           ;; Draw the first segment of the pipe
           (command "_line" pt1 pt2 "")
           (setq lin1 (entlast))
           (setq ang1 (angtos (angle pt1 pt2)))
           (setq offset1L (vla-offset (vlax-ename->vla-object lin1) dia))
           (setq offset1R (vla-offset (vlax-ename->vla-object lin1) (- 0.0 dia)))
           (vla-put-linetype (vlax-ename->vla-object lin1) "Center")
           (vla-put-linetypescale (vlax-ename->vla-object lin1) 10)
           )
          ((= start 1)
           ;; Draw subsequent segments of the pipe
           (setq pt1 pt2old
                 lin1 lin2
                 offset1L offset2L
                 offset1R offset2R)
           (setq ang1 (angtos (angle pt1 pt2)))
           )
        )

        ;; Draw the next segment of the pipe
        (command "_line" pt2 pt3 "")
        (setq lin2 (entlast))
        (setq obj (vlax-ename->vla-object lin2))
        (setq offset2L (vla-offset obj dia))
        (setq offset2R (vla-offset obj (- 0.0 dia)))
        (vla-put-linetype obj "Center")
        (vla-put-linetypescale obj 10)

        ;; Determine the angle of the current segment
        (setq ang2
               (cond
                 ((= ang1 "0")    (if (< (cadr pt2) (cadr pt3)) "90" "180"))
                 ((= ang1 "180")  (if (< (cadr pt2) (cadr pt3)) "0"  "270"))
                 ((= ang1 "90")   (if (< (car pt2)  (car pt3))  "270" "180"))
                 ((= ang1 "270")  (if (< (car pt2)  (car pt3))  "0"  "90"))))
        ;; Set the current layer to "01-FITTINGS" and insert fitting based on pipe size
        (setvar 'clayer "01-FITTINGS")
        (cond ((< pipesize 50)
               (command "-insert" "CHWP+ELBOW-40mm-90°-ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2))
              ((>= pipesize 50)
               (command "-insert" "CHWP-ELBOW-50mm- 90°-ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2)))

        (setq obj (entlast))
        (LM:AutoBlockBreak obj nil)
        (setq pt2old pt2)
        (setq pt2 pt3)
        (setq start 1)
        (setvar 'aunits oldaunits)
        (setvar 'osmode osm)
        (setvar 'clayer olr)
      )
    )
  )
)
(princ "\n Draw 2D CHWP Pipe Type \"Pipe\" to start")
(princ)
;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

 

pipe.dwg

Edited by Ajmal
add more drawings

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