Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Looks like CHATGP code as you have lots of not needed code. You use ssget with "Line" so no need to check is object a Line. Something else in code does not look right. The If distThreshold.
Not sure what your doing. Maybe post a dwg showing before and after.
@boyds86 wrote:
.... if distance <0.1 ........(if (or (not ss1) (not ss2))
(progn
()
(return)
)
)....
In your sample drawing, the distances are in scores or even hundreds of units, ridiculously far beyond 0.1. Either you need to use a very much bigger value for that comparison, or you need to be working with very much smaller pieces.
You don't say what happens when you run it, or doesn't happen, or whether you get any messages, or even whether it loads successfully. But if it loads but then just does nothing when you run it, the first suspect in my mind is that disconnect between the distance comparison and the actual distances involved.
I agree this looks like AI-generated code, and AI is [so far] notorious for not understanding AutoLisp very well. One part that suggests it is the code portion quoted above. The () is utterly pointless, and there is no AutoLisp (return) function. What are you expecting it to do if either selection set is empty?
Looking at the supplied dwg can understand what you want is to use the yellow line as a cut function to an underlying line. Need to have a full rewrite for task different approach. No need for the 0.1 as a ssget "F" should find the linework.
Will have a think about it maybe later today.
Dear @Sea-Haven @Kent1Cooper ,
My problem is that: Comparing lines, overlaping section (Common section) will turn to layer 15, and the remaining section will change to layer 44. I want to detect the different after comparing lines.
Thank you for your help!
@Kent1Cooper wrote:....
In your sample drawing, the distances are in scores or even hundreds of units, ridiculously far beyond 0.1. Either you need to use a very much bigger value for that comparison, or you need to be working with very much smaller pieces.
....
Looking at it more closely, it appears the intent of the 0.1 value is to find whether Lines overlap, or nearly do. But it looks at the distance between their midpoints, not the distance between them. That distance is far beyond 0.1 in all cases in your sample drawing. It needs to look at the distances from endpoints of one Line to nearest point on the other Line or its virtual extension.
It also appears to assume the overlapping Lines will always be drawn in the same direction. That is not the case in your sample drawing -- some are, and some are drawn in opposite directions.
Here's how I would go about this [lightly tested in your drawing]:
(defun C:AD
(/ ss ss11 ss12 n11 foundit line1 start1 end1
n12 line2 start2 end2 angdelta samedir)
(command "_.layer" "_unlock" "11,12" "")
(setq
ss (ssget '((0 . "LINE") (8 . "11,12"))); all in one selection
ss11 (ssget "_P" '((8 . "11")))
); ssget
(sssetfirst nil ss); select/grip/highlight again for:
(setq ss12 (ssget '((8 . "12"))))
(if (and ss11 ss12); there are some on each Layer
(progn ; then
(repeat (setq n11 (sslength ss11))
(setq
foundit nil ; reset for each Layer-11 Line
line1 (ssname ss11 (setq n11 (1- n11)))
start1 (cdr (assoc 10 (entget line1)))
end1 (cdr (assoc 11 (entget line1)))
n12 (sslength ss12); [what remains of it, if any]
); setq
(while (and (not foundit) (> n12 0))
; ends when Layer-12 Line overlap found, or if none found after looking at all
(setq
line2 (ssname ss12 (setq n12 (1- n12)))
start2 (cdr (assoc 10 (entget line2)))
end2 (cdr (assoc 11 (entget line2)))
); setq
(if
(and ; collinear within 0.1 unit:
(< (distance start1 (vlax-curve-getClosestPointTo line2 start1 T)) 0.1)
(< (distance end1 (vlax-curve-getClosestPointTo line2 end1 T)) 0.1)
(or ; and overlapping [either endpoint of either one on unextended other]:
(vlax-curve-getClosestPointTo line2 start1 nil)
(vlax-curve-getClosestPointTo line2 end1 nil)
(vlax-curve-getClosestPointTo line1 start2 nil)
(vlax-curve-getClosestPointTo line1 end2 nil)
); or
); and
(progn ; then
(setq
angdelta (abs (- (angle start1 end1) (angle start2 end2)))
samedir (or (equal angdelta 0 0.01) (equal angdelta (* pi 2) 0.01))
; second test for possible tiny difference at/near 0° direction
); setq
(command
"_.chprop" line1 line2 "" "_layer" "15" ""
"_.line" start1 (if samedir start2 end2) ""
"_.chprop" "_last" "" "_layer" "44" ""
"_.line" end1 (if samedir end2 start2) ""
"_.chprop" "_last" "" "_layer" "44" ""
); command
(ssdel line1 ss11) (ssdel line2 ss12); remove both from selection sets
(setq foundit T); end search relative to current Layer-11 Line
); progn
); if [no else -- do nothing if not overlapping/collinear
); while
); repeat
); progn [then]
); if [selection sets from both Layers]
(prin1)
)
You can select all the Lines on both Layers together, rather than the other code's requiring two separate selections.
Oddly, the Layer-44 Lines, though the most-recently-drawn, don't always all appear "on top." A DRAWORDER command could be incorporated to make them.
And it could use the usual stuff -- *error* handling, Undo begin/end wrapping, Osnap control if you might have running Osnap modes that do not include ENDpoint, etc. -- but first see whether it does what you want.
@Kent1Cooper
It is great! This is the lisp that I really need. It helped my current Problem & my company!
Thank you so much for your support!
Can't find what you're looking for? Ask the community or share your knowledge.