Code Red > AutoLISP (Vanilla / Visual)

Trying to simplify or clean up

(1/4) > >>

Biscuits:
This routine is used in mapping underground fiber optics.
Working with an existing polyline, the user indicates the length of the bore required,
selects a point on the existing polyline, and a circle is created based on that information.
The user then selects the two intersections created by the circle and the polyline.
Two smaller circles are then created at those intersections and the original polyline.
A new polyline is drawn between the two smaller circles and offset to both sides.
The larger and the new polyline are then deleted.
This routine works great. I'm just looking for advice on how to improve, simplify and/or clean it up a bit.
Any help would be much appreciated.
Thanks and have a great holiday season!


--- Code: ---;Bore by length

(defun C:TN2 (/ na nab lastent1 lastent2 pt1 pt2 o s)

(vl-load-com)

     (command "-layer" "s" "LAND_BORE" "")

(setq na (getint "\nTotal Bore Length : "))

(setq nab (/ na 2.0))

(prompt "\nSelect Circle Centerpoint")

(command "circle" "nea" pause nab)
(setq lastEnt1 (entlast))

(SETQ PT1 (GETPOINT "\nSelect 1st Point:"))
    (COMMAND "Circle" PT1 "D" "3.6")
(COMMAND "CHPROP" "L" "" "C" "RED" "")

(SETQ PT2 (GETPOINT "\nSelect 2nd Point:"))
   (COMMAND "Circle" PT2 "d" "3.6")
(COMMAND "CHPROP" "L" "" "C" "RED" "")

(command "pline" PT1 PT2 "")
(setq lastEnt2 (entlast))

 (setq o 1.7999999)

 (setq s (ssget "L" '((0 . "*LINE,CIRCLE,ARC,ELLIPSE"))))
   (foreach v (list o (- o))
     (vla-Offset (vlax-EName->vla-Object (ssname s 0)) v)
     )

(COMMAND "ERASE" LASTENT1 "")
(COMMAND "ERASE" LASTENT2 "")
 (princ)
)

--- End code ---

JohnK:
Are you looking for more error checking and or "safer operations" as well? The program is pretty clean as it is (you cannot get much more bare-bones) unless you are wanting to use less "command".

Biscuits:
Thank you for your opinion. Wouldn't mind fewer steps for the user maybe better automation.
Mostly curious if it could use any improvements. Thanks

JohnK:
What do you consider improvement? I would have built the lisp differently but if its working fine...

JohnK:
I spent a minute adding some comments/questions for you to answer/think about.


--- Code - Auto/Visual Lisp: ---(defun C:TN2 (/ na nab lastent1 lastent2 pt1 pt2 o s)  (vl-load-com)  (command "-layer" "s" "LAND_BORE" "") ;; if the layer doesn't exist: ;;  - I would add in a check to build layer if it doesnt exist. ;; if the layer exists: ;;  - I would add a check to ensure that the layer isnt frozen or off.  (setq na (getint "\nTotal Bore Length : ")) ;; I would add a default bore lenght.  (setq nab (/ na 2.0)) ;; I would check you can divide the number by 2 -i.e. >= 0  (prompt "\nSelect Circle Centerpoint") (command "circle" "nea" pause nab) ;; What if point selected is NOT on circle?  (setq lastEnt1 (entlast))  (SETQ PT1 (GETPOINT "\nSelect 1st Point:")) (COMMAND "Circle" PT1 "D" "3.6") (COMMAND "CHPROP" "L" "" "C" "RED" "") ;; What if point selected isnt on circle?  (SETQ PT2 (GETPOINT "\nSelect 2nd Point:")) (COMMAND "Circle" PT2 "d" "3.6") (COMMAND "CHPROP" "L" "" "C" "RED" "") ;; What if point selected isnt on circle?  ;; -The last two clode blocks are essentially the same; couldn't we "simplify" ;;  this by making a special function to call (twice)?  (command "pline" PT1 PT2 "") (setq lastEnt2 (entlast))  (setq o 1.7999999)  (setq s (ssget "L" '((0 . "*LINE,CIRCLE,ARC,ELLIPSE")))) (foreach v (list o (- o))  (vla-Offset (vlax-EName->vla-Object (ssname s 0)) v) )  (COMMAND "ERASE" LASTENT1 "") (COMMAND "ERASE" LASTENT2 "") (princ))

Navigation

[0] Message Index

[#] Next page

Go to full version