Jump to content

Drawing 2D Pipe with centerline and O.D. and I.D.


cadmando2

Recommended Posts

Having Issue with this lisp routine, co-worker left behind!

It work, but layers and not giving length of center line of pipe?

can anyone help!

 

 

 

(defun c:DP-2 (/ olayer lay_name A B C D E N1 N2 pnt11 pnt12 mssg dist dist2 entity count total)

; load the vla command set
  (vl-load-com)

; accessing the graphic screen as opposed to the text screen
  (graphscr)

; remember the current layer
  (setq olayer (getvar "clayer"))

; define the layers addressed in the program
   (command "layer" "m" "3" "c" "2" "" "lt" "Center" "" "")
   (command "layer" "m" "2" "c" "red" "" "lt" "Hidden" "" "")
   (command "layer" "m" "15" "c" "30" "" "lt" "Continuous" "" "")
   (setvar "clayer" olayer)

; let user specify OD & ID
(setq P-OD (getreal "\n Enter O.D. of Pipe: "))
(setq P-ID (getreal "\n Enter I.D. of Pipe: "))
(setq P-OD_2 (/ P-OD 2))
(setq P-ID_2 (/ P-ID 2))

;|  SECTION BLOCKED
; this portion filters only lines on layer PC
   (setq lay_name "PC")

; note: ssget "X" even selects objects on layers turned off, locked or frozen!
   (setq A (ssget "X"
           (list (cons 0 "LINE") (cons 8 lay_name))
           )
   );setq A

; END SECTION BLOCKED
|;
  (princ "\n Warning! Arc/Splines CL's Return Incorrect Length.\nSelect Centerlines to Construct Pipe: ")
   (setq A (ssget))

;variable B knows how many objects were found in variable A
   (setq B (sslength A))

   (setq C 0); counter

; the loop ends when C = B
   (while (< C B)

;  command line animation to prove computer is working:
   (defun spinbar (sbar)
     (cond
          ((= sbar "\\") "|")
          ((= sbar "|") "/")
          ((= sbar "/") "-")
          (t "\\")
      );cond
   );defun

   (princ (strcat "\rOffsetting Pipe Entities " (setq sbar (spinbar sbar))))

; D is assigned the next entity found in the subset
      (setq D (ssname A C))

      (initget (+ 1 2 4 64))
      (setq odist P-OD_2); distance for offsets
      (setq idist P-ID_2); distance for offsets

; D is the entity but must be considered an object to be offset
      (setq D (vlax-ename->vla-object D))

; D is offset in both directions everything to be on Pipe layer
      (vla-offset D idist)
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "Boiler-Pipe-ID")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D (* idist -1))
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "2")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D odist)
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "15")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D (* odist -1))
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "15")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
    (setq C (1+ C));add one to counter before testing while loop again
 ) ;while 

; Now to calculate the same selection sets total length in Feet & Inches.
   (setq E (ssget "P"))
  (setq total 0)
  (setq count (sslength E))
    (while (/= count 0)
    (setq N1 (ssname E 0))
    (setq N2 (entget N1)
              N2 (subst (cons 8 "Center")
             (assoc 8 N2) N2)
        );setq 
    (setq pnt10 (cdr (assoc 10 N2)))
    (setq pnt11 (cdr (assoc 11 N2)))
    (setq dist2 (distance pnt10 pnt11))
    (setq total (+ dist2 total))
    (ssdel N1 E)
        (entmod N2)
    (setq count (1- count))
    );end while
        (setq mssg (strcat " Finished!  " "\n Lengthe  of Pipe = " (rtos total 4 2)))
        (prompt mssg)
  (princ)
);defun DP-2

Link to comment
Share on other sites

(princ "\n Warning! Arc/Splines CL's Return Incorrect Length.\nSelect Centerlines to Construct Pipe: ")

 

Replace the pnt10 pnt11 with a vla-get-length this way it handles plines with curves.

 

Keep your ssgets as individuals then no need to reselect all the time.

 (setq ASS (ssget "X"  (list (cons 0 "LINE") (cons 8 lay_name)) )   ) ;setq ASS

 

As you make the offsets just add the new offset to a selection set SSADD then at end do 1 change Properties. (command "CHPROP" SSNEW1 "" "LAYER" "2" "") repeat for ssnew2 "15"

  • Agree 1
Link to comment
Share on other sites

here are some more tips.

 

cut down on command line spam when making layers turn cmdecho off before and back on after the layers are made.

(setvar 'cmdecho 0)  
(command "layer" "m" ...
(command "layer" "m" ...
(command "layer" "m" ...
(setvar 'cmdecho 1)  

 

getdist for OD and ID. you can pick points with mouse or type, also makes sure OD is bigger then ID. and divides them by 2 in one go.

(if (and (setq P-OD (/ (getdist "\n Enter O.D. of Pipe: ") 2)) (setq P-ID (/ (getdist "\n Enter I.D. of Pipe: ") 2)) (> P-OD P-ID))
  (progn)
  (Progn
    (prompt "\nI.D. Needs to be smaller then O.D.")
    (quit)
  )
)

 

If center line for pipe is Multiple lines, arc's that are all connected i would join into one polyline.

(vl-cmdf "_.Join" A "") ;join everything selected with ssget into one polyline if they are connected

 

can replace the 24 lines of entmod with 4 vla lines

(setq off (vla-offset D idist)) ;sets vla-objname of new offset entity
(vla-put-layer off "Boiler-Pipe-ID") ;moves offset entity to layer

 

 

Edited by mhupp
Link to comment
Share on other sites

Thanks for everyone's help and I am very appreciated . The Project I was going to use this on just got canceled, but would like to keep working on this DP-2.lsp for future projects. 

I was going to take AutoLisp class at local Community College , but they canceled the class and now trying to learn on my own! any suggestions!

I am still learning basics of lisp! I use note pad, scents AutoDesk removed "Visual Lisp Editor"! 

Is there a bester lisp editor and why to test lisp besides running in Autocad?

 

 

Edited by cadmando2
Link to comment
Share on other sites

4 hours ago, cadmando2 said:

I am still learning basics of lisp! I use note pad, scents AutoDesk removed "Visual Lisp Editor"! 

The vlide is still in AutoCAD. You'll need to change LISPSYS to 0 though.

Link to comment
Share on other sites

  • 1 month later...

I updated pipe routine, but still getting error at end  and not getting the Pline  or polyline to change to center line layer.

 

here is the Code:

(defun c:DP-3 (/ olayer lay_name A B C D E N1 N2 pnt11 pnt12 mssg dist dist2 entity count total)

; load the vla command set
  (vl-load-com)

; accessing the graphic screen as opposed to the text screen
  (graphscr)

; remember the current layer
  (setq olayer (getvar "clayer"))

; define the layers addressed in the program
(command "-LAYER"

  "N" "JR-Boiler-Pipe-ID,JR-Boiler-Pipe-OD,JR-Pipe-Center-line"
 
  "C" "30" "JR-Boiler-Pipe-OD"
 
  "C" "red" "JR-Boiler-Pipe-ID"
 
  "C" "yellow" "JR-Pipe-Center-line"
 
  "L" "Continuous" "JR-Boiler-Pipe-OD"

  "L" "Hidden" "JR-Boiler-Pipe-ID"

  "L" "Center" "JR-Pipe-Center-line"

  "D" "Boiler : Pipe-Inside Diameter" "JR-Boiler-Pipe-ID"
  "D" "Boiler : Pipe-Outside Diameter" "JR-Boiler-Pipe-OD"
  "D" "Boiler : Pipe-Center-line" "JR-Pipe-Center-line"
 
  "S" "0"

    "" ; end Layer
  (setvar "clayer" olayer)
); command

; let user specify OD & ID
(setq P-OD (getreal "\n Enter O.D. of Pipe: "))
(setq P-ID (getreal "\n Enter I.D. of Pipe: "))
(setq P-OD_2 (/ P-OD 2))
(setq P-ID_2 (/ P-ID 2))

;|  SECTION BLOCKED
; this portion filters only lines on layer PC
   (setq lay_name "PC")

; note: ssget "X" even selects objects on layers turned off, locked or frozen!
   (setq A (ssget "X"
           (list (cons 0 "LINE") (cons 8 lay_name))
           )
   );setq A

; END SECTION BLOCKED
|;
  (princ "\n Warning! Arc/Splines CL's Return Incorrect Length.\nSelect Centerlines to Construct Pipe: ")
   (setq A (ssget))

;variable B knows how many objects were found in variable A
   (setq B (sslength A))

   (setq C 0); counter

; the loop ends when C = B
   (while (< C B)

;  command line animation to prove computer is working:
   (defun spinbar (sbar)
     (cond
          ((= sbar "\\") "|")
          ((= sbar "|") "/")
          ((= sbar "/") "-")
          (t "\\")
      );cond
   );defun

   (princ (strcat "\rOffsetting Pipe Entities " (setq sbar (spinbar sbar))))

; D is assigned the next entity found in the subset
      (setq D (ssname A C))

      (initget (+ 1 2 4 64))
      (setq odist P-OD_2); distance for offsets
      (setq idist P-ID_2); distance for offsets

; D is the entity but must be considered an object to be offset
      (setq D (vlax-ename->vla-object D))

; D is offset in both directions everything to be on Pipe layer
      (vla-offset D idist)
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "JR-Boiler-Pipe-ID")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D (* idist -1))
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "JR-Boiler-Pipe-ID")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D odist)
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "JR-Boiler-Pipe-OD")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
      (vla-offset D (* odist -1))
        (setq entity (entlast)
              entity (entget entity)
              entity (subst (cons 8 "JR-Boiler-Pipe-OD")
             (assoc 8 entity) entity)
         );setq
         (entmod entity)
    (setq C (1+ C));add one to counter before testing while loop again
 ) ;while 

; Now to calculate the same selection sets total length in Feet & Inches.
   (setq E (ssget "P"))
  (setq total 0)
  (setq count (sslength E))
    (while (/= count 0)
    (setq N1 (ssname E 0))
    (setq N2 (entget N1)
              N2 (subst (cons 8 "JR-Pipe-Center-line")
             (assoc 8 N2) N2)
        );setq 
    (setq pnt10 (cdr (assoc 10 N2)))
    (setq pnt11 (cdr (assoc 11 N2)))
    (setq dist2 (distance pnt10 pnt11))
    (setq total (+ dist2 total))
    (ssdel N1 E)
        (entmod N2)
    (setq count (1- count))
    );end while
        (setq mssg (strcat " Finished!  " "\n Lengthe  of Pipe = " (rtos total 4 2)))
        (prompt mssg)
  (princ)
);defun DP-3

 

 

and here is the error at the end.

Enter name list of layer(s) to apply description or <select objects>:  <*>: JR-Pipe-Center-line Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile/Xref]: S
Enter layer name to make current or <select object>: 0 Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile/Xref]:
Command: 0 Unknown command "0".  Press F1 for help.
Command:
 Enter O.D. of Pipe: 2.5
 Enter I.D. of Pipe: 1.94
 Warning! Arc/Splines CL's Return Incorrect Length.
Select Centerlines to Construct Pipe:
Select objects: 1 found
Select objects:
Offsetting Pipe Entities \; error: bad argument type: 2D/3D point: nil

 

Link to comment
Share on other sites

Maybe 2nd line ??

 

; END SECTION BLOCKED
|;
  (princ "\n Warning! Arc/Splines CL's Return Incorrect Length.\nSelect Centerlines to Construct Pipe: ")

 

Edited by BIGAL
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...