Author Topic: Help with lisp  (Read 4047 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Help with lisp
« on: February 11, 2005, 01:51:30 PM »
I am trying to make this lisp so that it will be all joined PLINES... no luck yet... any pointers?

thx you

Code: [Select]


(defun DTR (A) (* pi (/ A 180.0)))
(defun C:PI (/ PNT1 PNT2 D A ET HD L1 L2 L3 L4 OTM OSM)
   (setvar "CMDECHO" 0)
   (setq OTM (getvar "ORTHOMODE"))
   (setvar "ORTHOMODE" 0)
   (setq OSM (getvar "osmode"))
   (setvar "OSMODE" 0)
   (setq
      PNT1 (getpoint "\nPick Start of Pipe: ")
   )
   (setq PNT2 (getpoint PNT1 "\nPick End of Pipe: "))
   (setq
      D (getdist "\nEnter Pipe Width: ")
   ) ;In Engineering Units (ie. 2.5 etc.)
   (setq HD (/ D 2))
   (setq A (angle PNT1 PNT2))
   (command "Pline" PNT1 PNT2 "")
   (setq ET (entlast))
   (setq L1 (polar PNT1 (- A (DTR 90)) HD))
   (setq
      L2 (polar PNT2 (- A (DTR 90)) HD)
   )
   (setq L3 (polar PNT1 (+ A (DTR 90)) HD))
   (setq
      L4 (polar PNT2 (+ A (DTR 90)) HD)
   )
   (command "pline" L1 L2 "")
   (command "pline" L3 L4 "")
   (command
      "Change" ET "" "P" "LT" "hidden" "" ""
   ) ;change linetype to suit
   (command "Pedit" ET "W" D "" "")
   (setvar "ORTHOMODE" OTM)
   (setvar "OSMODE" OSM)
   (command "Redraw")
) ;end pipe.lsp

Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #1 on: February 11, 2005, 02:06:44 PM »
Can you explain what you are trying to do?
The routine draws 3 parallel plines then changes the
center line to hidden line type.
How did you want the lines joined? They don't share end points.
The 2 outer lines could be drawn as a rectangle but the
center line would still be a separate line.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Help with lisp
« Reply #2 on: February 11, 2005, 02:09:51 PM »
cab
I was trying to get them to fillet eachother together... the outside lines so it is similiar to having one CL PLINE with offsets.
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #3 on: February 11, 2005, 02:24:36 PM »
Try this.
Code: [Select]
(defun dtr (a) (* pi (/ a 180.0)))
(defun c:pi (/ pnt1 pnt2 d a et hd l1 l2 l3 l4 otm osm)
  (setvar "CMDECHO" 0)
  (setq otm (getvar "ORTHOMODE"))
  (setvar "ORTHOMODE" 0)
  (setq osm (getvar "osmode"))
  (setvar "OSMODE" 0)
  (setq pnt1 (getpoint "\nPick Start of Pipe: "))
  (setq pnt2 (getpoint pnt1 "\nPick End of Pipe: "))
  (setq d (getdist "\nEnter Pipe Width: ")) ;In Engineering Units (ie. 2.5 etc.)
  (setq hd (/ d 2))
  (setq a (angle pnt1 pnt2))
  (command "Pline" pnt1 pnt2 "")
  (setq et (entlast))
  (setq l1 (polar pnt1 (- a (dtr 90)) hd))
  (setq l2 (polar pnt2 (- a (dtr 90)) hd))
  (setq l3 (polar pnt1 (+ a (dtr 90)) hd))
  (setq l4 (polar pnt2 (+ a (dtr 90)) hd))
  (command "pline" l1 l3 l4 l2 "C" "")
  (command "Change" et "" "P" "LT" "hidden" "" "") ;change linetype to suit
  (command "Pedit" et "W" d "" "")
  (setvar "ORTHOMODE" otm)
  (setvar "OSMODE" osm)
  (command "Redraw")
) ;end pipe.lsp
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Help with lisp
« Reply #4 on: February 11, 2005, 02:37:01 PM »
not bad on the code:)

how about the user pics 3 or 5 points that are not connected... PLINE

ex. (not a line type)
/\/\/\/\/\/\/\/\/\/\/\/\/\ (as a pline)

then the pi.lsp would offset that  line

/\/\/\/\/\/\/\/\/\/\/\/\/\ (as a pline)
/\/\/\/\/\/\/\/\/\/\/\/\/\ (as a pline)
/\/\/\/\/\/\/\/\/\/\/\/\/\ (as a pline)

the middle PLINE would still have a thickness...

does that help?
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #5 on: February 11, 2005, 03:11:16 PM »
Try this:
Code: [Select]
(defun c:pi (/ pnt1 pnt2 d a et hd l1 l2 l3 l4 otm osm)
  (setvar "CMDECHO" 0)
  (setq otm (getvar "ORTHOMODE"))
  (setvar "ORTHOMODE" 0)
  (setq osm (getvar "osmode"))
  (setvar "OSMODE" 0)
  (setq d (getdist "\nEnter Pipe Width: ")) ;In Engineering Units (ie. 2.5 etc.)
  (setq hd (/ d 2))
  (prompt "\n***  Draw the pipe.")

  ;;   repeat a point input until Enter
  (command "PLINE")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )

  (setq et (entlast))

  (if (= (cdr (assoc 0 (entget et))) "LWPOLYLINE")
    (progn
      (offsetdouble et hd)
      (command "Change" et "" "P" "LT" "hidden" "" "") ;change linetype to suit
      (command "Pedit" et "W" d "" "")
    )
  )
  (setvar "ORTHOMODE" otm)
  (setvar "OSMODE" osm)
  (command "Redraw")
) ;end pipe.lsp


;;  Double Offset Method - CAB  10/26/2004
;;  offset to both sides a given distance
;;  Arguments
;;    ename is an entity name
;;    dist is the offset distance
;;  Returns
;;   nil if failed or
;;   list of the two new entities
;;
(defun OffsetDouble (ename dist / vobj enew)
  (setq vobj (vlax-ename->vla-object ename)
        enew '())
  (if (vlax-method-applicable-p vobj 'Offset)
    (progn
      (if (vl-catch-all-error-p
            (vl-catch-all-apply 'vlax-invoke
              (list vobj 'Offset dist)))
        (prompt "\nPositive distance failed.")
        (setq enew (list (entlast)))
      )
      (if (vl-catch-all-error-p
            (vl-catch-all-apply 'vlax-invoke
              (list vobj 'Offset (- dist))))
        (prompt "\nNegative distance failed.")
        (setq enew (cons (entlast) enew))
      )
    )
    (prompt "\nCannot offset selected object type.")
  )
); defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #6 on: February 14, 2005, 08:44:43 AM »
You will need the end points of the pline drawn by the user so
Code: [Select]
;;after this line
(setq et (entlast))
;;  add this
(setq vlist   (cdrs 10 (entget et))
         pst    (car vlist)
         pend (car (reverse vlist))
)



Then add this code to the end of your main routine
Code: [Select]
;;************************************************************************
;;;(cdrs 10 (entget (car (entsel "\nSelect a polyline"))))
;;;returns something like this:
;;;((259.943 -252.219) (214.182 -140.305) (254.223 -92.925) (215.0 -21.0386)
;;;   (253.406 41.8621) (215.817 112.115))
;;;Micheal Puckett
(defun cdrs (key lst / pair rtn)
   (while (setq pair (assoc key lst))
      (setq rtn (cons (cdr pair) rtn)
            lst (cdr (member pair lst))
      )
   )
   (reverse rtn)
)


Now add the other code I gave you to insert the blocks.
One for start of line & one for end of line, or better yet create a sub routine to repeat the block insert process.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Help with lisp
« Reply #7 on: February 14, 2005, 08:55:56 AM »
Code: [Select]

(defun DTR (A) (* pi (/ A 180.0)))
(defun C:PI (/ PNT1 PNT2 D A ET HD L1 L2 L3 L4 OTM OSM)
   (setvar "CMDECHO" 0)
   (setq OTM (getvar "ORTHOMODE"))
   (setvar "ORTHOMODE" 0)
   (setq OSM (getvar "osmode"))
   (setvar "OSMODE" 0)
   (setq
      PNT1 (getpoint "\nPick Start of Pipe: ")
   )
   (setq PNT2 (getpoint PNT1 "\nPick End of Pipe: "))
   (setq
      D (getdist "\nEnter Pipe Width: ")
   ) ;In Engineering Units (ie. 2.5 etc.)

(initget "Manhole Endsection Inlet None")
(setq choice (getkword "\nAdd to start of line, [Manhole Endsection Inlet]

<None> "))
(cond
  ((or (null choice) (= choice "None"))
   ;;  do nothing
  )
  (T ; insert a block
   (command "-insert"
            choice ; block name
            p1     ; insert point
            ""     ; x scale
            ""     ; y scale
            ""     ; rotation angle
   )
  )
)
 
   (setq HD (/ D 2))
   (setq A (angle PNT1 PNT2))
   (command "Pline" PNT1 PNT2 "")
   (setq ET (entlast))
   (setq L1 (polar PNT1 (- A (DTR 90)) HD))
   (setq
      L2 (polar PNT2 (- A (DTR 90)) HD)
   )
   (setq L3 (polar PNT1 (+ A (DTR 90)) HD))
   (setq
      L4 (polar PNT2 (+ A (DTR 90)) HD)
   )


;;after this line
(setq et (entlast))
;;  add this
(setq vlist   (cdrs 10 (entget et))
         pst    (car vlist)
         pend (car (reverse vlist))
)

;;************************************************************************
;;;(cdrs 10 (entget (car (entsel "\nSelect a polyline"))))
;;;returns something like this:
;;;((259.943 -252.219) (214.182 -140.305) (254.223 -92.925) (215.0 -21.0386)
;;;   (253.406 41.8621) (215.817 112.115))
;;;Micheal Puckett
(defun cdrs (key lst / pair rtn)
   (while (setq pair (assoc key lst))
      (setq rtn (cons (cdr pair) rtn)
            lst (cdr (member pair lst))
      )
   )
   (reverse rtn)
)
   (command "pline" L1 L2 "")
   (command "pline" L3 L4 "")
   (command
      "Change" ET "" "P" "LT" "hidden" "" ""
   ) ;change linetype to suit
   (command "Pedit" ET "W" D "" "")
   (setvar "ORTHOMODE" OTM)
   (setvar "OSMODE" OSM)
   (command "Redraw")

) ;end pipe.lsp


so far i have the code somewhat compiled... now i get a

C:PI

Command: pi
Pick Start of Pipe:
Pick End of Pipe:
Enter Pipe Width: 1

Add to start of line, [Manhole Endsection Inlet] <None>  ; error: no function
definition: CDRS

still plugin with it though
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #8 on: February 14, 2005, 09:17:53 AM »
Well, more like this: :wink:
Code: [Select]
(defun c:pi (/ pnt1 pnt2 d a et hd l1 l2 l3 l4 otm osm)
  (setvar "CMDECHO" 0)
  (setq otm (getvar "ORTHOMODE"))
  (setvar "ORTHOMODE" 0)
  (setq osm (getvar "osmode"))
  (setvar "OSMODE" 0)
  (setq d (getdist "\nEnter Pipe Width: ")) ;In Engineering Units (ie. 2.5 etc.)
  (setq hd (/ d 2))
  (prompt "\n***  Draw the pipe.")

  ;;   repeat a point input until Enter
  (command "PLINE")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )

  (setq et (entlast))
  (setq vlist (cdrs 10 (entget et)) ; vertex list
        pst   (car vlist)           ; start point
        pend  (car (reverse vlist)) ; end point
  )
 
  (if (= (cdr (assoc 0 (entget et))) "LWPOLYLINE")
    (progn
      (offsetdouble et hd)
      (command "Change" et "" "P" "LT" "hidden" "" "") ;change linetype to suit
      (command "Pedit" et "W" d "" "")
    )
  )

  (initget "Manhole Endsection Inlet None")
  (setq choice (getkword "\nAdd to start of line, [Manhole Endsection Inlet] <None> "))
  (cond
    ((or (null choice) (= choice "None"))
     ;;  do nothing
    )
    (t ; insert a block
     (command "-insert" choice ; block name
              pst   ; insert point
              ""    ; x scale
              ""    ; y scale
              ""    ; rotation angle
      )
    )
  )
  (initget "Manhole Endsection Inlet None")
  (setq choice (getkword "\nAdd to end of line, [Manhole Endsection Inlet] <None> "))
  (cond
    ((or (null choice) (= choice "None"))
     ;;  do nothing
    )
    (t ; insert a block
     (command "-insert" choice ; block name
              pend  ; insert point
              ""    ; x scale
              ""    ; y scale
              ""    ; rotation angle
      )
    )
  )


  (setvar "ORTHOMODE" otm)
  (setvar "OSMODE" osm)
  (command "Redraw")
) ;end pipe.lsp



;;  Double Offset Method - CAB  10/26/2004
;;  offset to both sides a given distance
;;  Arguments
;;    ename is an entity name
;;    dist is the offset distance
;;  Returns
;;   nil if failed or
;;   list of the two new entities
;;
(defun OffsetDouble (ename dist / vobj enew)
  (setq vobj (vlax-ename->vla-object ename)
        enew '())
  (if (vlax-method-applicable-p vobj 'Offset)
    (progn
      (if (vl-catch-all-error-p
            (vl-catch-all-apply 'vlax-invoke
              (list vobj 'Offset dist)))
        (prompt "\nPositive distance failed.")
        (setq enew (list (entlast)))
      )
      (if (vl-catch-all-error-p
            (vl-catch-all-apply 'vlax-invoke
              (list vobj 'Offset (- dist))))
        (prompt "\nNegative distance failed.")
        (setq enew (cons (entlast) enew))
      )
    )
    (prompt "\nCannot offset selected object type.")
  )
); defun

;;************************************************************************
;;;(cdrs 10 (entget (car (entsel "\nSelect a polyline"))))
;;;returns something like this:
;;;((259.943 -252.219) (214.182 -140.305) (254.223 -92.925) (215.0 -21.0386)
;;;   (253.406 41.8621) (215.817 112.115))
;;;Micheal Puckett
(defun cdrs (key lst / pair rtn)
   (while (setq pair (assoc key lst))
      (setq rtn (cons (cdr pair) rtn)
            lst (cdr (member pair lst))
      )
   )
   (reverse rtn)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Help with lisp
« Reply #9 on: February 14, 2005, 09:31:18 AM »
hey the only way to make mistakes is to learn.... :)

Thanks CAB... im learning!
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with lisp
« Reply #10 on: February 14, 2005, 09:56:07 AM »
Keep it up, it take's awhile. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.