Lisp for identifying ortho lines

Lisp for identifying ortho lines

Anonymous
Not applicable
3,291 Views
12 Replies
Message 1 of 13

Lisp for identifying ortho lines

Anonymous
Not applicable

I have to QC several drawings that should all be drawn 95% ortho, but are someitmes slightly off of ortho. I would like a lisp routine that will change the color of lines that are ortho. Red if there ortho on the X axis, and Green if there ortho on the Y. This will make all non ortho lines pop and I could determine very quikcly if the line was drawn wrong or should be as is. This is a visual display in other programs like Sketchup and I miss the functionality in Autocad. 

This should be a very simple rotuine for someone who knows what they are doing, and appreciate any help in this matter. 

 

-Chris

0 Likes
Accepted solutions (1)
3,292 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

Are you talking about specifically Line entities only [pretty simple], or might you need things like Polyline line segments included, and/or edges or segments of various other entity types [a lot more complicated]?

 

Wouldn't it be better to identify [whether by color, highlighting, moving to a different Layer, whatever] those that are not orthogonal, rather than those that are ?  If your 95% is correct, there would be a lot fewer things to "feature" that way, which I would think would make it easier for you to find them.

Kent Cooper, AIA
0 Likes
Message 3 of 13

ВeekeeCZ
Consultant
Consultant
You can use QSELECT command - select all the lines with Delta Y = 0 or Delta X = 0. Not that difficult. But lisp would be definitely faster 🙂
0 Likes
Message 4 of 13

Anonymous
Not applicable

A lisp of this would definately work better, but using Qselect and the Delta X, Y works great. Thanks for the help. Woud still be awesome to have a lisp that could do this as well as handle poly lines.

 

-Chris

0 Likes
Message 5 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

Are you talking about specifically Line entities only [pretty simple]...?  .... 

Wouldn't it be better to identify ... those that are not orthogonal, rather than those that are ?....


Here's something pretty basic that does that for all non-orthogonal Line entities [lightly tested]:

 

(defun C:LOFFO (/ liness offss line ldata); = Lines that are OFF-Ortho
  (setq
    liness (ssget "_X" (list '(0 . "LINE") (cons 410 (getvar 'ctab))))
    offss (ssadd); selection set of Lines off-ortho [initially empty]
  ); setq
  (repeat (setq n (sslength liness))
    (setq
      line (ssname liness (setq n (1- n)))
      ldata (entget line)
    ); setq
    (if
      (not
        (or
          (equal (cadr (assoc 10 ldata)) (cadr (assoc 11 ldata)) 1e-6); X's equal
          (equal (caddr (assoc 10 ldata)) (caddr (assoc 11 ldata)) 1e-6); Y's equal
        ); or
      ); not
      (ssadd line offss)
    ); if
  ); repeat
  (if (> (sslength offss) 0) (command "_.chprop" offss "" "_color" 2 "")); <--color as you prefer
); defun

It could, instead of changing their color, select/highlight/grip them, or turn them to Polylines and give them width to make them obvious, or change them to a distinct Layer, or probably some other possibilities.

 

Polylines are a lot more complicated.  Presumably it would step along and check the orthogonality [is that a word?] of every segment [which isn't so hard], but then what should it do if it finds one that's off?  Draw a Line along it and change that for noticeability?  Change the width of that segment to make it stand out?  Something else?  Presumably you wouldn't want the entire Polyline "featured," because that wouldn't tell you which segment(s) in it is/are off.

 

Another thing to consider:  It could be made to ignore Lines that are far enough away from orthogonal [such as 45 degree angles] that obviously they don't need to be "fixed," but you would need to suggest a criterion for that -- more than 1 degree off, or more than 5 degrees off, or something.  On the other hand, it wouldn't be too hard to also find things that are close to but not exactly on, say, any 15-degree multiple, not just those that are slightly off of orthogonal.

 

There are routines on these Forums to do the fixing for you, some that force everything to orthogonal or multiple-of-some-increment directions [as I recall, Rotating Lines about their start points or maybe midpoints], and some that force all endpoints to fall on snap-grid positions of whatever precision you want [which would often fix things that are slightly off, though depending on the details could take some a little further off, but at least they'd be more noticeable that way] -- do a Search.

Kent Cooper, AIA
Message 6 of 13

Anonymous
Not applicable

Lisp routine returns "nil"

 

"Command: LOFFO
_.chprop
Select objects: 840 found
Select objects:
Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]: _color
New color [Truecolor/COlorbook] <2 (yellow)>: 2
Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]:
Command: nil"

 

I appreciate the effort, I should be able to just make a macro using the Qselect. For now I'm making a sperate drawing, and exploding all my polylines so they too can be checked. 

 

Thanks for your help.

0 Likes
Message 7 of 13

Jonathan3891
Advisor
Advisor
The routine that @Kent1Cooper posted works perfectly on my end. I'm not sure why you are getting "nil"

Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Lisp routine returns "nil"

 

....
New color [Truecolor/COlorbook] <2 (yellow)>: 2
Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]:
Command: nil"

....


I assume from your Command:-line quoted series that it is changing such Lines to yellow, as intended.  As Help will confirm for you, the (command) function always returns nil when done -- it is not an error, nor does it mean it didn't work.  And a routine like this always returns whatever is returned by the last thing in it.  If you want the routine to "exit quietly" as they describe it, without that nil showing up, add this line:

....
(if (> (sslength offss) 0) (command "_.chprop" offss "" "_color" 2 "")); <--color as you prefer
(princ) ); defun

A (princ) function [or (print) or (prin1) -- you'll see those used for this, too] with no arguments returns nothingness, and thereby suppresses the nil returned by the otherwise-last thing in the function.  Read all about it in Help for [I forget which -- maybe more than one of] those functions.

Kent Cooper, AIA
0 Likes
Message 9 of 13

Anonymous
Not applicable

I'm an idiot, works great.

Should of looked at the results instead of just staring at the command line and assuming "nil" = failure

 

0 Likes
Message 10 of 13

cool.stuff
Collaborator
Collaborator

Hello @Kent1Cooper 🙂

 

Could you please change your lisp code above in order to allow user selection and not to change lines' color but to move them to a layer name "temp_offo"?

 

Could it be done to delta z as well?

 

Sorry to bother again.

 

Many thanks 🙂

0 Likes
Message 11 of 13

cool.stuff
Collaborator
Collaborator

@Kent1Cooper, sorry to bother you.

 

By searching in other lisps from forum, I found a way to do it

 

(defun C:LOFFOLay (/ liness offss line ldata); = Lines that are OFF-Ortho
(setq
liness (ssget "_X" (list '(0 . "*LINE") (cons 410 (getvar 'ctab))))
offss (ssadd); selection set of Lines off-ortho [initially empty]
); setq
(repeat (setq n (sslength liness))
(setq
line (ssname liness (setq n (1- n)))
ldata (entget line)
); setq
(if
(not
(or
(equal (cadr (assoc 10 ldata)) (cadr (assoc 11 ldata)) 1e-6); X's equal
(equal (caddr (assoc 10 ldata)) (caddr (assoc 11 ldata)) 1e-6); Y's equal
); or
); not
(ssadd line offss)
); if
); repeat
(command "_.Layer" "_Make" "off_ortho" "_Color" "1" "" "LType" "Continuous" "" "")
;(if (> (sslength offss) 0) (command "_.chprop" offss "" "_color" 2 "")); <--color as you prefer
(if (> (sslength offss) 0) (command "_.chprop" offss "" "_lay" "off_ortho" "")); <--layer and color
(princ)
); defun

 

But I could not find a way to identify the delta-z.. Could this be changed to identify delta z as well?

 

Many thanks!! 🙂

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@cool.stuff wrote:

... allow user selection and not to change lines' color but to move them to a layer name "temp_offo"?

Could it be done to delta z as well?


[In Reply to Message 10, before I saw Message 11]

For User selection, remove the "_X" from the 3rd line [of the code in Message 5].

Then further down:

,,,,
(if
(or <--ADDED
(not (equal (cadddr (assoc 10 ldata)) (cadddr (assoc 11 ldata)) 1e-6)); Z's unequal <--ADDED (not (or (equal (cadr (assoc 10 ldata)) (cadr (assoc 11 ldata)) 1e-6); X's equal (equal (caddr (assoc 10 ldata)) (caddr (assoc 11 ldata)) 1e-6); Y's equal
); or ); not
); or <--ADDED (ssadd line offss) ); if ....

That assumes that you want to catch something that is not "flat" in Z, even if it is orthogonal in XY.  But if it's not orthogonal in XY, you want to catch it even if its ends are at the same Z coordinate.  If I have misunderstood, give a more detailed description.  EDIT:  Specific question:  What should it think of a Line that is purely vertical?  It would have different Z coordinates at its ends, so it would be flagged by the above, but surely it would technically qualify as "orthogonal."

 

For the Layer change instead of color change, you could figure it out by looking into the CHPROP command:

(if (> (sslength offss) 0) (command "_.chprop" offss "" "_layer" "temp_offo" "")); <--layer as you prefer

Kent Cooper, AIA
Message 13 of 13

cool.stuff
Collaborator
Collaborator
Many many thanks @Kent1Cooper 🙂

Yes, I have understood what you meant, it is not so easy to qualify a line that is not straight in Z axis.
With this, I can save a lot of time 🙂

Works perfectly for its purposes 🙂

Best regards
0 Likes