- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Looking for assistance in creating a code to split all lines in my "Scribe" Layer and then set all of their lengths to 1" from the outer profile of the DXF "0" layer.
Found a method to cut the scribe lines in half here:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-break-multiple-lines-at-midpoin...
Then messed around with the code some but I cant get the lines on the left to change length. 😞
(defun C:LBH ; = Lines Break in Half
(/ ss lin)
(vl-load-com)
(prompt "\nTo Break Lines in Half and Adjust Length,")
; Select all lines on the "Scribe" layer
(setq ss (ssget "_X" '((8 . "Scribe") (0 . "LINE"))))
; Check if lines are selected
(if ss
(progn
(setq n (sslength ss))
; Loop through each selected line
(repeat n
(setq lin (ssname ss (setq n (1- n))))
; Break the line in half
(command "_.break" lin "_non"
(mapcar '/ (mapcar '+ (vlax-curve-getStartPoint lin) (vlax-curve-getEndPoint lin)) '(2 2 2))
"@")
; Calculate the new length (1 inch)
(setq newLength 1.0)
; Get the start and end points of the new line segments
(setq startPt (vlax-curve-getStartPoint lin))
(setq endPt (vlax-curve-getEndPoint lin))
; Calculate the current length of the line
(setq currentLength (distance startPt endPt))
; Calculate the scale factor to adjust the line to the new length
(setq scaleFactor (/ newLength currentLength))
; Scale the line segment to the new length
(command "_.scale" lin "" startPt scaleFactor)
)
)
; If no lines are selected
(prompt "\nNo lines found on the \"Scribe\" layer.")
)
(princ)
)
This is how I want the code to work in picture form.
Example part:
Splits all lines at midpoint.
Then lengthen to 1" from the outer side.
Cant see in the photo but every scribe line is set to 1".
The purpose of this is so that the sheet metal brake operators can line up their laser to the scribe on both sides and work quicker.
Solved! Go to Solution.